Skip to main content

A python library implementing the git http transfer protocol.

Project description

repligit

repligit is a Python library that implements the Git transfer protocol. It enables users to query remote repositories, mirror repositories between two locations without storing state locally, and incrementally archive repositories to disk. repligit is used by Hubcast to mirror repositories from GitHub to GitLab for secure CI/CD on local hardware.

Installation

You can install repligit from PyPI using pip:

pip install repligit

Features

  • Query remote Git repositories.
  • Mirror repositories between different Git hosting services.
  • Incrementally archive repositories to disk.
  • Implements Git transfer protocol in pure Python.

Example Usage

from repligit import fetch_pack, ls_remote, send_pack


def main():
    src_remote_url = "https://github.com/spack/spack.git"
    dest_remote_url = "https://gitlab.com/test-org/test-repo.git"

    branch_name = "main"

    target_ref = f"refs/heads/{branch_name}"

    # Authentication credentials
    # Note: Only provide credentials when authentication is required
    # src_username = "<username>"  # Uncomment if source repo requires auth
    # src_password = "<token>"     # Uncomment if source repo requires auth
    dest_username = "<username>"   # For destination repo write access
    dest_password = "<token>"      # For destination repo write access

    # List references from source repository (without authentication)
    gh_refs = ls_remote(src_remote_url)

    # List references from destination repository (with authentication)
    gl_refs = ls_remote(
        dest_remote_url,
        username=dest_username,
        password=dest_password
    )

    want_sha = gh_refs[target_ref]
    have_shas = gl_refs.values()

    from_sha = gl_refs.get(target_ref) or ("0" * 40)

    if want_sha in have_shas:
        print("Everything is up to date")
        return

    # Fetch the packfile from source repository
    packfile = fetch_pack(
        src_remote_url,
        want_sha,
        have_shas,
        # username=src_username,  # Uncomment if source repo requires auth
        # password=src_password,  # Uncomment if source repo requires auth
    )

    # Upload packfile to destination repository
    send_pack(
        dest_remote_url,
        target_ref,
        from_sha,
        want_sha,
        packfile,
        username=dest_username,
        password=dest_password,
    )


if __name__ == "__main__":
    main()

License

Licensed under the Apache License, Version 2.0 w/LLVM Exception (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

LLNL-CODE-2003682

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repligit-0.0.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repligit-0.0.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file repligit-0.0.1.tar.gz.

File metadata

  • Download URL: repligit-0.0.1.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for repligit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3acf31370050a189aaf9c7eed186ffb62961372156c261335fe97f51d1ea65e8
MD5 9f47dc213a2c2a896910c072adb4f90e
BLAKE2b-256 d500360738242d07fd5a6b303f05542e210a91a1b900895ff25248e788bc772f

See more details on using hashes here.

File details

Details for the file repligit-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: repligit-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for repligit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d02cbde563ae6438fa13517434db7e9aa48cd43ff1e470cd8d65e7866f70ce92
MD5 df0caf67e37411fb2d480857efb9c775
BLAKE2b-256 0df64dccaeaf1beabdec2b1548adf397e52b18a842bb2c17ed31ebbbc50144fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page