pygitmirror 0.0.2__tar.gz → 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. {pygitmirror-0.0.2 → pygitmirror-0.1.0}/.gitignore +9 -2
  2. pygitmirror-0.1.0/PKG-INFO +163 -0
  3. pygitmirror-0.1.0/README.md +132 -0
  4. pygitmirror-0.1.0/pyproject.toml +127 -0
  5. pygitmirror-0.1.0/src/pygitmirror/__init__.py +74 -0
  6. pygitmirror-0.1.0/src/pygitmirror/__main__.py +8 -0
  7. pygitmirror-0.1.0/src/pygitmirror/_compat.py +20 -0
  8. pygitmirror-0.1.0/src/pygitmirror/cli/__init__.py +5 -0
  9. pygitmirror-0.1.0/src/pygitmirror/cli/_main.py +76 -0
  10. pygitmirror-0.1.0/src/pygitmirror/cli/_parser.py +116 -0
  11. pygitmirror-0.1.0/src/pygitmirror/config/__init__.py +7 -0
  12. pygitmirror-0.1.0/src/pygitmirror/config/_json.py +33 -0
  13. pygitmirror-0.1.0/src/pygitmirror/config/_load.py +120 -0
  14. pygitmirror-0.1.0/src/pygitmirror/config/host_settings.py +54 -0
  15. pygitmirror-0.1.0/src/pygitmirror/config/settings.py +36 -0
  16. pygitmirror-0.1.0/src/pygitmirror/errors.py +75 -0
  17. pygitmirror-0.1.0/src/pygitmirror/git/__init__.py +7 -0
  18. pygitmirror-0.1.0/src/pygitmirror/git/_redact.py +17 -0
  19. pygitmirror-0.1.0/src/pygitmirror/git/_remote.py +55 -0
  20. pygitmirror-0.1.0/src/pygitmirror/git/git.py +111 -0
  21. pygitmirror-0.1.0/src/pygitmirror/git/local_mirror.py +93 -0
  22. pygitmirror-0.1.0/src/pygitmirror/hosts/__init__.py +28 -0
  23. pygitmirror-0.1.0/src/pygitmirror/hosts/_factory.py +33 -0
  24. pygitmirror-0.1.0/src/pygitmirror/hosts/_transport.py +91 -0
  25. pygitmirror-0.1.0/src/pygitmirror/hosts/api_client.py +123 -0
  26. pygitmirror-0.1.0/src/pygitmirror/hosts/api_response.py +40 -0
  27. pygitmirror-0.1.0/src/pygitmirror/hosts/bitbucket_host.py +89 -0
  28. pygitmirror-0.1.0/src/pygitmirror/hosts/gitea_host.py +30 -0
  29. pygitmirror-0.1.0/src/pygitmirror/hosts/github_host.py +38 -0
  30. pygitmirror-0.1.0/src/pygitmirror/hosts/github_style_host.py +95 -0
  31. pygitmirror-0.1.0/src/pygitmirror/hosts/gitlab_host.py +98 -0
  32. pygitmirror-0.1.0/src/pygitmirror/hosts/host.py +181 -0
  33. pygitmirror-0.1.0/src/pygitmirror/hosts/plain_host.py +54 -0
  34. pygitmirror-0.1.0/src/pygitmirror/hosts/repository_info.py +26 -0
  35. pygitmirror-0.1.0/src/pygitmirror/mirror/__init__.py +8 -0
  36. pygitmirror-0.1.0/src/pygitmirror/mirror/_transfer.py +185 -0
  37. pygitmirror-0.1.0/src/pygitmirror/mirror/mirror.py +228 -0
  38. pygitmirror-0.1.0/src/pygitmirror/mirror/mirror_plan.py +50 -0
  39. pygitmirror-0.1.0/src/pygitmirror/mirror/mirror_result.py +72 -0
  40. pygitmirror-0.1.0/src/pygitmirror/mirror/operation.py +22 -0
  41. pygitmirror-0.1.0/src/pygitmirror/repository_ref.py +58 -0
  42. pygitmirror-0.1.0/tests/cli/test_main.py +110 -0
  43. pygitmirror-0.1.0/tests/config/test_load_settings.py +140 -0
  44. pygitmirror-0.1.0/tests/git/__init__.py +0 -0
  45. pygitmirror-0.1.0/tests/git/test_git.py +68 -0
  46. pygitmirror-0.1.0/tests/git/test_local_mirror.py +67 -0
  47. pygitmirror-0.1.0/tests/helpers.py +117 -0
  48. pygitmirror-0.1.0/tests/hosts/__init__.py +0 -0
  49. pygitmirror-0.1.0/tests/hosts/test_api_client.py +137 -0
  50. pygitmirror-0.1.0/tests/hosts/test_bitbucket_host.py +74 -0
  51. pygitmirror-0.1.0/tests/hosts/test_github_style_hosts.py +120 -0
  52. pygitmirror-0.1.0/tests/hosts/test_gitlab_host.py +73 -0
  53. pygitmirror-0.1.0/tests/hosts/test_host.py +79 -0
  54. pygitmirror-0.1.0/tests/mirror/__init__.py +0 -0
  55. pygitmirror-0.1.0/tests/mirror/conftest.py +46 -0
  56. pygitmirror-0.1.0/tests/mirror/test_clone.py +104 -0
  57. pygitmirror-0.1.0/tests/mirror/test_migrate.py +69 -0
  58. pygitmirror-0.1.0/tests/mirror/test_mirror_plan.py +35 -0
  59. pygitmirror-0.1.0/tests/mirror/test_sync.py +115 -0
  60. pygitmirror-0.1.0/tests/test_import.py +44 -0
  61. pygitmirror-0.1.0/tests/test_repository_ref.py +25 -0
  62. pygitmirror-0.0.2/.github/workflows/python-publish.yml +0 -34
  63. pygitmirror-0.0.2/.github/workflows/python-test.yml +0 -43
  64. pygitmirror-0.0.2/.pylintrc +0 -637
  65. pygitmirror-0.0.2/.vscode/settings.json +0 -4
  66. pygitmirror-0.0.2/PKG-INFO +0 -128
  67. pygitmirror-0.0.2/README.md +0 -94
  68. pygitmirror-0.0.2/pyproject.toml +0 -112
  69. pygitmirror-0.0.2/setup.cfg +0 -4
  70. pygitmirror-0.0.2/src/pygitmirror/__main__.py +0 -50
  71. pygitmirror-0.0.2/src/pygitmirror/arguments/__init__.py +0 -7
  72. pygitmirror-0.0.2/src/pygitmirror/arguments/arguments.py +0 -65
  73. pygitmirror-0.0.2/src/pygitmirror/arguments/check_repos.py +0 -34
  74. pygitmirror-0.0.2/src/pygitmirror/arguments/check_url.py +0 -4
  75. pygitmirror-0.0.2/src/pygitmirror/arguments/process_arguments.py +0 -56
  76. pygitmirror-0.0.2/src/pygitmirror/arguments/read_json.py +0 -21
  77. pygitmirror-0.0.2/src/pygitmirror/sync/__init__.py +0 -5
  78. pygitmirror-0.0.2/src/pygitmirror/sync/add_destination_remote.py +0 -27
  79. pygitmirror-0.0.2/src/pygitmirror/sync/clone_repo.py +0 -17
  80. pygitmirror-0.0.2/src/pygitmirror/sync/constants.py +0 -2
  81. pygitmirror-0.0.2/src/pygitmirror/sync/fetch_repo.py +0 -25
  82. pygitmirror-0.0.2/src/pygitmirror/sync/get_reference_by_name.py +0 -15
  83. pygitmirror-0.0.2/src/pygitmirror/sync/push_origin_destination.py +0 -58
  84. pygitmirror-0.0.2/src/pygitmirror/sync/sync_repo.py +0 -38
  85. pygitmirror-0.0.2/src/pygitmirror.egg-info/PKG-INFO +0 -128
  86. pygitmirror-0.0.2/src/pygitmirror.egg-info/SOURCES.txt +0 -34
  87. pygitmirror-0.0.2/src/pygitmirror.egg-info/dependency_links.txt +0 -1
  88. pygitmirror-0.0.2/src/pygitmirror.egg-info/entry_points.txt +0 -2
  89. pygitmirror-0.0.2/src/pygitmirror.egg-info/requires.txt +0 -9
  90. pygitmirror-0.0.2/src/pygitmirror.egg-info/top_level.txt +0 -1
  91. pygitmirror-0.0.2/tests/test_import.py +0 -41
  92. {pygitmirror-0.0.2 → pygitmirror-0.1.0}/LICENSE +0 -0
  93. {pygitmirror-0.0.2/src/pygitmirror/arguments → pygitmirror-0.1.0/src/pygitmirror}/py.typed +0 -0
  94. {pygitmirror-0.0.2/src/pygitmirror → pygitmirror-0.1.0/tests}/__init__.py +0 -0
  95. /pygitmirror-0.0.2/src/pygitmirror/py.typed → /pygitmirror-0.1.0/tests/cli/__init__.py +0 -0
  96. /pygitmirror-0.0.2/src/pygitmirror/sync/py.typed → /pygitmirror-0.1.0/tests/config/__init__.py +0 -0
@@ -161,5 +161,12 @@ cython_debug/
161
161
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
162
  #.idea/
163
163
 
164
- **/*temp*
165
- **/*Temp*
164
+ # Scratch files and folders at the root
165
+ /*temp*
166
+ /*Temp*
167
+
168
+ # Generated API reference
169
+ docs/reference/api/
170
+
171
+ # Local mirrors made while trying the tool
172
+ /mirrors/
@@ -0,0 +1,163 @@
1
+ Metadata-Version: 2.5
2
+ Name: pygitmirror
3
+ Version: 0.1.0
4
+ Summary: Clone, sync and migrate git repositories between GitHub, GitLab, Gitea and Bitbucket
5
+ Project-URL: Homepage, https://github.com/pygitmirror/pygitmirror
6
+ Project-URL: Documentation, https://pygitmirror.readthedocs.io/
7
+ Project-URL: Repository, https://github.com/pygitmirror/pygitmirror
8
+ Project-URL: Issues, https://github.com/pygitmirror/pygitmirror/issues
9
+ Project-URL: Author, https://girgis.me
10
+ Author-email: Bassem Girgis <brgirgis@gmail.com>
11
+ Maintainer-email: Bassem Girgis <brgirgis@gmail.com>
12
+ License-Expression: MIT
13
+ License-File: LICENSE
14
+ Keywords: bitbucket,clone,git,gitea,github,gitlab,migrate,mirror,sync
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: System Administrators
19
+ Classifier: Natural Language :: English
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: 3.14
26
+ Classifier: Topic :: Software Development :: Version Control :: Git
27
+ Classifier: Topic :: System :: Archiving :: Mirroring
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.11
30
+ Description-Content-Type: text/markdown
31
+
32
+ # pygitmirror
33
+
34
+ [![Tests](https://github.com/pygitmirror/pygitmirror/actions/workflows/tests.yml/badge.svg)](https://github.com/pygitmirror/pygitmirror/actions/workflows/tests.yml)
35
+ [![Documentation](https://readthedocs.org/projects/pygitmirror/badge/?version=latest)](https://pygitmirror.readthedocs.io/)
36
+ [![PyPI version](https://img.shields.io/pypi/v/pygitmirror)](https://pypi.org/project/pygitmirror/)
37
+ [![Python versions](https://img.shields.io/pypi/pyversions/pygitmirror)](https://pypi.org/project/pygitmirror/)
38
+ [![License](https://img.shields.io/pypi/l/pygitmirror)](https://github.com/pygitmirror/pygitmirror/blob/master/LICENSE)
39
+
40
+ Clone, sync and migrate git repositories between GitHub, GitLab, Gitea, Bitbucket and any other git server. A command, `git-mirror`, and a Python library.
41
+
42
+ ```shell
43
+ export GIT_MIRROR_SOURCE_TOKEN=... # a GitHub token
44
+ export GIT_MIRROR_DESTINATION_TOKEN=... # a Gitea token
45
+
46
+ git-mirror sync --source github \
47
+ --destination gitea --destination-url https://git.example.com \
48
+ --org my-org --all
49
+ ```
50
+
51
+ - **Three operations**: `clone` only adds, `sync` makes the destination equal to the source, `migrate` clones, verifies and can archive the source
52
+ - **Creates what is missing**: destination repositories are created with the description and visibility of the source
53
+ - **All branches and tags**, for one repository or every repository of an organization
54
+ - **Cheap to repeat**: a repository which did not change costs two short requests and no download
55
+ - **Careful with tokens**: read from the environment, never written to a file, a URL or a command line
56
+ - **No dependencies**: needs Python 3.11 and git 2.31, nothing else
57
+ - **Typed**: type hints throughout, checked with mypy in strict mode
58
+
59
+ Full documentation: **https://pygitmirror.readthedocs.io/**
60
+
61
+ ## Installation
62
+
63
+ ```shell
64
+ pip install pygitmirror
65
+ ```
66
+
67
+ ## Operations
68
+
69
+ | | `clone` | `sync` | `migrate` |
70
+ | --- | --- | --- | --- |
71
+ | adds missing branches and tags | yes | yes | yes |
72
+ | moves a branch forward | yes | yes | yes |
73
+ | overwrites a branch or tag which differs | no, fails | yes | no, fails |
74
+ | deletes what the source does not have | no | yes | no, fails |
75
+ | checks the destination afterwards | no | no | yes |
76
+ | can archive the source | no | no | yes |
77
+
78
+ Add `--dry-run` to any of them to see what would be done.
79
+
80
+ ```shell
81
+ # A first copy which cannot overwrite anything
82
+ git-mirror clone --source github --destination gitlab --org my-org --repo api web
83
+
84
+ # Keep a copy up to date, for example from cron
85
+ git-mirror sync --source github --destination gitlab --org my-org --all
86
+
87
+ # Move to a new home and make the old one read-only
88
+ git-mirror migrate --source bitbucket --destination github \
89
+ --org my-workspace --destination-org my-org --all
90
+ ```
91
+
92
+ Only branches and tags are copied: not issues, pull requests, wikis, releases or Git LFS files.
93
+
94
+ ## Hosts
95
+
96
+ | Provider | Servers | Creates repositories |
97
+ | --- | --- | --- |
98
+ | `github` | github.com, GitHub Enterprise Server | yes |
99
+ | `gitlab` | gitlab.com, self-managed GitLab | yes |
100
+ | `gitea` | Gitea, Forgejo | yes |
101
+ | `bitbucket` | bitbucket.org | yes |
102
+ | `plain` | any git server or local folder | no, the destination must exist |
103
+
104
+ Without `--source` or `--destination` a host is plain, and the URL of a repository is the address followed by the owner and the name:
105
+
106
+ ```shell
107
+ git-mirror clone --source-url ssh://git@old.example.com:7999 \
108
+ --destination-url https://git.example.com --org my-project --repo api
109
+ ```
110
+
111
+ ## Settings file
112
+
113
+ To name many repositories at once, use a JSON file, in which lines starting with `//` are comments:
114
+
115
+ ```
116
+ {
117
+ "sync_path": "/var/lib/git-mirror",
118
+ "source": { "provider": "github" },
119
+ "destination": { "provider": "gitea", "url": "https://git.example.com" },
120
+ "repos": {
121
+ // These two only.
122
+ "organization-1": ["repo-1", "repo-2"],
123
+ // Every repository of the organization.
124
+ "organization-2": "*"
125
+ }
126
+ }
127
+ ```
128
+
129
+ ```shell
130
+ git-mirror sync --config settings.json
131
+ ```
132
+
133
+ ## Python
134
+
135
+ ```python
136
+ from pygitmirror import Mirror, make_host
137
+
138
+ source = make_host("github", token=github_token)
139
+ destination = make_host("gitea", url="https://git.example.com", token=gitea_token)
140
+
141
+ mirror = Mirror(source, destination, workdir="/var/lib/git-mirror")
142
+ result = mirror.sync("my-org/api")
143
+ print(result.summary())
144
+ ```
145
+
146
+ ## Upgrading from 0.0
147
+
148
+ Calls such as `git-mirror --source_url ... --destination_url ... --org ... --repo ...` and the settings files of the first versions still work; they run `clone`. The [changelog](https://pygitmirror.readthedocs.io/en/latest/project/changelog.html) lists what changed.
149
+
150
+ ## Development
151
+
152
+ ```shell
153
+ git clone https://github.com/pygitmirror/pygitmirror.git
154
+ cd pygitmirror
155
+ make install # create the environment with uv
156
+ make check # lint, type check, test and build the docs
157
+ ```
158
+
159
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
160
+
161
+ ## License
162
+
163
+ MIT. Maintained by [Bassem Girgis](https://girgis.me).
@@ -0,0 +1,132 @@
1
+ # pygitmirror
2
+
3
+ [![Tests](https://github.com/pygitmirror/pygitmirror/actions/workflows/tests.yml/badge.svg)](https://github.com/pygitmirror/pygitmirror/actions/workflows/tests.yml)
4
+ [![Documentation](https://readthedocs.org/projects/pygitmirror/badge/?version=latest)](https://pygitmirror.readthedocs.io/)
5
+ [![PyPI version](https://img.shields.io/pypi/v/pygitmirror)](https://pypi.org/project/pygitmirror/)
6
+ [![Python versions](https://img.shields.io/pypi/pyversions/pygitmirror)](https://pypi.org/project/pygitmirror/)
7
+ [![License](https://img.shields.io/pypi/l/pygitmirror)](https://github.com/pygitmirror/pygitmirror/blob/master/LICENSE)
8
+
9
+ Clone, sync and migrate git repositories between GitHub, GitLab, Gitea, Bitbucket and any other git server. A command, `git-mirror`, and a Python library.
10
+
11
+ ```shell
12
+ export GIT_MIRROR_SOURCE_TOKEN=... # a GitHub token
13
+ export GIT_MIRROR_DESTINATION_TOKEN=... # a Gitea token
14
+
15
+ git-mirror sync --source github \
16
+ --destination gitea --destination-url https://git.example.com \
17
+ --org my-org --all
18
+ ```
19
+
20
+ - **Three operations**: `clone` only adds, `sync` makes the destination equal to the source, `migrate` clones, verifies and can archive the source
21
+ - **Creates what is missing**: destination repositories are created with the description and visibility of the source
22
+ - **All branches and tags**, for one repository or every repository of an organization
23
+ - **Cheap to repeat**: a repository which did not change costs two short requests and no download
24
+ - **Careful with tokens**: read from the environment, never written to a file, a URL or a command line
25
+ - **No dependencies**: needs Python 3.11 and git 2.31, nothing else
26
+ - **Typed**: type hints throughout, checked with mypy in strict mode
27
+
28
+ Full documentation: **https://pygitmirror.readthedocs.io/**
29
+
30
+ ## Installation
31
+
32
+ ```shell
33
+ pip install pygitmirror
34
+ ```
35
+
36
+ ## Operations
37
+
38
+ | | `clone` | `sync` | `migrate` |
39
+ | --- | --- | --- | --- |
40
+ | adds missing branches and tags | yes | yes | yes |
41
+ | moves a branch forward | yes | yes | yes |
42
+ | overwrites a branch or tag which differs | no, fails | yes | no, fails |
43
+ | deletes what the source does not have | no | yes | no, fails |
44
+ | checks the destination afterwards | no | no | yes |
45
+ | can archive the source | no | no | yes |
46
+
47
+ Add `--dry-run` to any of them to see what would be done.
48
+
49
+ ```shell
50
+ # A first copy which cannot overwrite anything
51
+ git-mirror clone --source github --destination gitlab --org my-org --repo api web
52
+
53
+ # Keep a copy up to date, for example from cron
54
+ git-mirror sync --source github --destination gitlab --org my-org --all
55
+
56
+ # Move to a new home and make the old one read-only
57
+ git-mirror migrate --source bitbucket --destination github \
58
+ --org my-workspace --destination-org my-org --all
59
+ ```
60
+
61
+ Only branches and tags are copied: not issues, pull requests, wikis, releases or Git LFS files.
62
+
63
+ ## Hosts
64
+
65
+ | Provider | Servers | Creates repositories |
66
+ | --- | --- | --- |
67
+ | `github` | github.com, GitHub Enterprise Server | yes |
68
+ | `gitlab` | gitlab.com, self-managed GitLab | yes |
69
+ | `gitea` | Gitea, Forgejo | yes |
70
+ | `bitbucket` | bitbucket.org | yes |
71
+ | `plain` | any git server or local folder | no, the destination must exist |
72
+
73
+ Without `--source` or `--destination` a host is plain, and the URL of a repository is the address followed by the owner and the name:
74
+
75
+ ```shell
76
+ git-mirror clone --source-url ssh://git@old.example.com:7999 \
77
+ --destination-url https://git.example.com --org my-project --repo api
78
+ ```
79
+
80
+ ## Settings file
81
+
82
+ To name many repositories at once, use a JSON file, in which lines starting with `//` are comments:
83
+
84
+ ```
85
+ {
86
+ "sync_path": "/var/lib/git-mirror",
87
+ "source": { "provider": "github" },
88
+ "destination": { "provider": "gitea", "url": "https://git.example.com" },
89
+ "repos": {
90
+ // These two only.
91
+ "organization-1": ["repo-1", "repo-2"],
92
+ // Every repository of the organization.
93
+ "organization-2": "*"
94
+ }
95
+ }
96
+ ```
97
+
98
+ ```shell
99
+ git-mirror sync --config settings.json
100
+ ```
101
+
102
+ ## Python
103
+
104
+ ```python
105
+ from pygitmirror import Mirror, make_host
106
+
107
+ source = make_host("github", token=github_token)
108
+ destination = make_host("gitea", url="https://git.example.com", token=gitea_token)
109
+
110
+ mirror = Mirror(source, destination, workdir="/var/lib/git-mirror")
111
+ result = mirror.sync("my-org/api")
112
+ print(result.summary())
113
+ ```
114
+
115
+ ## Upgrading from 0.0
116
+
117
+ Calls such as `git-mirror --source_url ... --destination_url ... --org ... --repo ...` and the settings files of the first versions still work; they run `clone`. The [changelog](https://pygitmirror.readthedocs.io/en/latest/project/changelog.html) lists what changed.
118
+
119
+ ## Development
120
+
121
+ ```shell
122
+ git clone https://github.com/pygitmirror/pygitmirror.git
123
+ cd pygitmirror
124
+ make install # create the environment with uv
125
+ make check # lint, type check, test and build the docs
126
+ ```
127
+
128
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
129
+
130
+ ## License
131
+
132
+ MIT. Maintained by [Bassem Girgis](https://girgis.me).
@@ -0,0 +1,127 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+
6
+ [project]
7
+ name = "pygitmirror"
8
+ dynamic = ["version"]
9
+ description = "Clone, sync and migrate git repositories between GitHub, GitLab, Gitea and Bitbucket"
10
+ readme = "README.md"
11
+ requires-python = ">=3.11"
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ authors = [{ name = "Bassem Girgis", email = "brgirgis@gmail.com" }]
15
+ maintainers = [{ name = "Bassem Girgis", email = "brgirgis@gmail.com" }]
16
+ keywords = [
17
+ "git",
18
+ "mirror",
19
+ "clone",
20
+ "sync",
21
+ "migrate",
22
+ "github",
23
+ "gitlab",
24
+ "gitea",
25
+ "bitbucket",
26
+ ]
27
+ classifiers = [
28
+ "Development Status :: 4 - Beta",
29
+ "Environment :: Console",
30
+ "Intended Audience :: Developers",
31
+ "Intended Audience :: System Administrators",
32
+ "Natural Language :: English",
33
+ "Operating System :: OS Independent",
34
+ "Programming Language :: Python :: 3",
35
+ "Programming Language :: Python :: 3.11",
36
+ "Programming Language :: Python :: 3.12",
37
+ "Programming Language :: Python :: 3.13",
38
+ "Programming Language :: Python :: 3.14",
39
+ "Topic :: Software Development :: Version Control :: Git",
40
+ "Topic :: System :: Archiving :: Mirroring",
41
+ "Typing :: Typed",
42
+ ]
43
+ # No dependencies: the package runs the git executable and uses the standard
44
+ # library for everything else. See docs/project/decisions.rst.
45
+ dependencies = []
46
+
47
+
48
+ [project.urls]
49
+ Homepage = "https://github.com/pygitmirror/pygitmirror"
50
+ Documentation = "https://pygitmirror.readthedocs.io/"
51
+ Repository = "https://github.com/pygitmirror/pygitmirror"
52
+ Issues = "https://github.com/pygitmirror/pygitmirror/issues"
53
+ Author = "https://girgis.me"
54
+
55
+
56
+ [project.scripts]
57
+ git-mirror = "pygitmirror.cli:main"
58
+
59
+
60
+ [dependency-groups]
61
+ test = ["pytest>=9.0.2", "pytest-cov>=7.0.0", "pytest-xdist>=3.8.0"]
62
+ lint = ["mypy>=1.19.1", "ruff>=0.14.0"]
63
+ docs = ["sphinx>=8.1.3", "sphinx-autobuild>=2024.10.3", "furo>=2025.9.25"]
64
+ dev = [
65
+ { include-group = "test" },
66
+ { include-group = "lint" },
67
+ { include-group = "docs" },
68
+ ]
69
+
70
+
71
+ # The version is the git tag of the release, for example v0.2.0 gives 0.2.0.
72
+ [tool.hatch.version]
73
+ source = "vcs"
74
+
75
+
76
+ [tool.hatch.build.targets.sdist]
77
+ include = ["/src", "/tests", "/README.md", "/LICENSE"]
78
+
79
+
80
+ [tool.pytest.ini_options]
81
+ testpaths = ["tests"]
82
+
83
+
84
+ [tool.coverage.run]
85
+ source = ["pygitmirror"]
86
+
87
+
88
+ [tool.ruff]
89
+ line-length = 100
90
+ target-version = "py311"
91
+ src = ["src", "tests"]
92
+
93
+ [tool.ruff.lint]
94
+ select = [
95
+ "E", # pycodestyle errors
96
+ "W", # pycodestyle warnings
97
+ "F", # pyflakes
98
+ "I", # isort
99
+ "B", # flake8-bugbear
100
+ "UP", # pyupgrade
101
+ "S", # flake8-bandit: the package handles tokens and runs a subprocess
102
+ "T20", # flake8-print
103
+ "D", # pydocstyle
104
+ ]
105
+ ignore = [
106
+ "D105", # magic methods need no docstring
107
+ "D107", # constructor parameters are documented in the class docstring
108
+ ]
109
+
110
+ [tool.ruff.lint.pydocstyle]
111
+ convention = "pep257"
112
+ # An overriding method inherits the docstring of the method it overrides.
113
+ ignore-decorators = ["pygitmirror._compat.override", "typing.override"]
114
+
115
+ [tool.ruff.lint.per-file-ignores]
116
+ # Tests assert, run git on repositories they made and use made-up tokens.
117
+ "tests/**" = ["D", "S"]
118
+ "docs/conf.py" = ["D"]
119
+ ".github/scripts/*.py" = ["T20"]
120
+
121
+
122
+ [tool.mypy]
123
+ python_version = "3.11"
124
+ strict = true
125
+ warn_unreachable = true
126
+ disallow_any_unimported = true
127
+ show_error_codes = true
@@ -0,0 +1,74 @@
1
+ """Clone, sync and migrate git repositories between hosts.
2
+
3
+ The package copies the branches and tags of repositories from one host to
4
+ another: GitHub, GitLab, Gitea, Bitbucket or any git server.
5
+
6
+ .. code-block:: python
7
+
8
+ from pygitmirror import Mirror, make_host
9
+
10
+ source = make_host("github", token="...")
11
+ destination = make_host("gitea", url="https://git.example.com", token="...")
12
+ mirror = Mirror(source, destination, workdir="~/.cache/git-mirror")
13
+ result = mirror.sync("owner/name")
14
+ """
15
+
16
+ from importlib.metadata import PackageNotFoundError, version
17
+
18
+ from pygitmirror.errors import (
19
+ ApiError,
20
+ ConfigError,
21
+ DivergedError,
22
+ EmptySourceError,
23
+ GitError,
24
+ GitMirrorError,
25
+ UnsupportedError,
26
+ VerificationError,
27
+ )
28
+ from pygitmirror.git import Git, LocalMirror
29
+ from pygitmirror.hosts import (
30
+ PROVIDERS,
31
+ BitbucketHost,
32
+ GiteaHost,
33
+ GitHubHost,
34
+ GitLabHost,
35
+ Host,
36
+ PlainHost,
37
+ RepositoryInfo,
38
+ make_host,
39
+ )
40
+ from pygitmirror.mirror import Mirror, MirrorPlan, MirrorResult, Operation
41
+ from pygitmirror.repository_ref import RepositoryRef
42
+
43
+ try:
44
+ __version__ = version("pygitmirror")
45
+ except PackageNotFoundError: # pragma: no cover - a source tree which is not installed
46
+ __version__ = "0+unknown"
47
+
48
+ __all__ = [
49
+ "PROVIDERS",
50
+ "ApiError",
51
+ "BitbucketHost",
52
+ "ConfigError",
53
+ "DivergedError",
54
+ "EmptySourceError",
55
+ "Git",
56
+ "GitError",
57
+ "GitHubHost",
58
+ "GitLabHost",
59
+ "GitMirrorError",
60
+ "GiteaHost",
61
+ "Host",
62
+ "LocalMirror",
63
+ "Mirror",
64
+ "MirrorPlan",
65
+ "MirrorResult",
66
+ "Operation",
67
+ "PlainHost",
68
+ "RepositoryInfo",
69
+ "RepositoryRef",
70
+ "UnsupportedError",
71
+ "VerificationError",
72
+ "__version__",
73
+ "make_host",
74
+ ]
@@ -0,0 +1,8 @@
1
+ """Run the command line with ``python -m pygitmirror``."""
2
+
3
+ import sys
4
+
5
+ from pygitmirror.cli import main
6
+
7
+ if __name__ == "__main__":
8
+ sys.exit(main())
@@ -0,0 +1,20 @@
1
+ """Names which the supported Python versions provide in different places."""
2
+
3
+ import sys
4
+ from collections.abc import Callable
5
+ from typing import TypeVar
6
+
7
+ __all__ = ["override"]
8
+
9
+ if sys.version_info >= (3, 12):
10
+ from typing import override
11
+ else:
12
+ _F = TypeVar("_F", bound=Callable[..., object])
13
+
14
+ def override(method: _F, /) -> _F:
15
+ """Mark a method which overrides one of a base class.
16
+
17
+ :param method: the overriding method
18
+ :returns: the method, unchanged
19
+ """
20
+ return method
@@ -0,0 +1,5 @@
1
+ """The ``git-mirror`` command."""
2
+
3
+ from pygitmirror.cli._main import main
4
+
5
+ __all__ = ["main"]
@@ -0,0 +1,76 @@
1
+ """The entry point of the command line."""
2
+
3
+ import logging
4
+ import os
5
+ import sys
6
+ from collections.abc import Sequence
7
+
8
+ from pygitmirror.cli._parser import build_parser
9
+ from pygitmirror.config import Settings, load_settings
10
+ from pygitmirror.errors import GitMirrorError
11
+ from pygitmirror.mirror import Mirror, Operation
12
+ from pygitmirror.repository_ref import RepositoryRef
13
+
14
+ _logger = logging.getLogger("pygitmirror")
15
+
16
+ #: Options which are answered without a command.
17
+ _NO_COMMAND = ("-h", "--help", "--version")
18
+
19
+
20
+ def _repositories(mirror: Mirror, settings: Settings) -> list[RepositoryRef]:
21
+ """Return the repositories of the settings, listing the owners named in full."""
22
+ repositories = []
23
+ for owner, names in settings.repos.items():
24
+ if names is None:
25
+ repositories += mirror.repositories(owner)
26
+ else:
27
+ repositories += [RepositoryRef(owner, name) for name in names]
28
+ return repositories
29
+
30
+
31
+ def _run(settings: Settings) -> int:
32
+ """Run the operation of the settings and return the number of failures."""
33
+ mirror = Mirror(
34
+ settings.source.make_host("source", os.environ),
35
+ settings.destination.make_host("destination", os.environ),
36
+ workdir=settings.sync_path,
37
+ owners=settings.owners,
38
+ )
39
+ repositories = _repositories(mirror, settings)
40
+ results = mirror.run(
41
+ settings.operation,
42
+ repositories,
43
+ prune=settings.prune,
44
+ archive_source=settings.archive_source,
45
+ dry_run=settings.dry_run,
46
+ )
47
+ failed = 0
48
+ for result in results:
49
+ _logger.log(logging.INFO if result.ok else logging.ERROR, "%s", result.summary())
50
+ failed += not result.ok
51
+ _logger.info("%d of %d repositories failed", failed, len(repositories))
52
+ return failed
53
+
54
+
55
+ def main(argv: Sequence[str] | None = None) -> int:
56
+ """Run the ``git-mirror`` command.
57
+
58
+ :param argv: the arguments, without the name of the program; those of
59
+ the process when not given
60
+ :returns: the exit status: 0 when every repository succeeded, 1 when
61
+ one failed, 2 when the settings are invalid or nothing could be
62
+ started
63
+ """
64
+ args = list(sys.argv[1:] if argv is None else argv)
65
+ operations = [operation.value for operation in Operation]
66
+ # The first versions had no commands and did what clone does.
67
+ if args and args[0] not in operations and args[0] not in _NO_COMMAND:
68
+ args.insert(0, Operation.CLONE.value)
69
+ options = vars(build_parser().parse_args(args))
70
+ logging.basicConfig(level=options["log"], format="%(asctime)s %(levelname)-7s %(message)s")
71
+ try:
72
+ failed = _run(load_settings(Operation(options["operation"]), options))
73
+ except GitMirrorError as error:
74
+ _logger.error("%s", error)
75
+ return 2
76
+ return 1 if failed else 0