git-well 0.2.4__tar.gz → 0.3.1__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.
- git_well-0.3.1/PKG-INFO +53 -0
- {git_well-0.2.4 → git_well-0.3.1}/README.rst +135 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well/__init__.py +3 -1
- {git_well-0.2.4 → git_well-0.3.1}/git_well/__main__.py +3 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well/_utils.py +94 -39
- {git_well-0.2.4 → git_well-0.3.1}/git_well/demo/__init__.py +16 -10
- git_well-0.3.1/git_well/git_archive_source.py +774 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_autoconf_gpgsign.py +120 -43
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_branch_cleanup.py +37 -13
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_branch_upgrade.py +26 -10
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_discover_remote.py +91 -36
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_rebase_add_continue.py +67 -27
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_remote_protocol.py +65 -34
- git_well-0.3.1/git_well/git_squash.py +145 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_squash_streaks.py +348 -238
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_stats.py +45 -9
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_sync.py +91 -41
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_track_upstream.py +38 -13
- {git_well-0.2.4 → git_well-0.3.1}/git_well/git_url_components.py +23 -6
- git_well-0.3.1/git_well/ipfs.py +1283 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well/main.py +8 -2
- git_well-0.3.1/git_well/patchdir/__init__.py +1 -0
- git_well-0.3.1/git_well/patchdir/git_patchdir_apply.py +162 -0
- git_well-0.3.1/git_well/patchdir/git_patchdir_save.py +101 -0
- git_well-0.3.1/git_well/patchdir/patchdir_modal.py +16 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well/repo.py +27 -14
- git_well-0.3.1/git_well.egg-info/PKG-INFO +53 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well.egg-info/SOURCES.txt +9 -16
- {git_well-0.2.4 → git_well-0.3.1}/git_well.egg-info/entry_points.txt +2 -0
- git_well-0.3.1/git_well.egg-info/requires.txt +71 -0
- git_well-0.3.1/pyproject.toml +188 -0
- {git_well-0.2.4 → git_well-0.3.1}/requirements/optional.txt +2 -0
- {git_well-0.2.4 → git_well-0.3.1}/requirements/runtime.txt +2 -1
- git_well-0.3.1/requirements/tests.txt +14 -0
- git_well-0.3.1/tests/test_cli.py +164 -0
- git_well-0.3.1/tests/test_import.py +2 -0
- git_well-0.3.1/tests/test_ipfs.py +333 -0
- git_well-0.2.4/PKG-INFO +0 -350
- git_well-0.2.4/git_well/__main__.pyi +0 -1
- git_well-0.2.4/git_well/_utils.pyi +0 -18
- git_well-0.2.4/git_well/git_autoconf_gpgsign.pyi +0 -33
- git_well-0.2.4/git_well/git_branch_cleanup.pyi +0 -18
- git_well-0.2.4/git_well/git_branch_upgrade.pyi +0 -19
- git_well-0.2.4/git_well/git_discover_remote.pyi +0 -25
- git_well-0.2.4/git_well/git_rebase_add_continue.pyi +0 -20
- git_well-0.2.4/git_well/git_remote_protocol.pyi +0 -38
- git_well-0.2.4/git_well/git_squash_streaks.pyi +0 -134
- git_well-0.2.4/git_well/git_stats.pyi +0 -22
- git_well-0.2.4/git_well/git_sync.pyi +0 -38
- git_well-0.2.4/git_well/git_track_upstream.pyi +0 -20
- git_well-0.2.4/git_well/main.pyi +0 -9
- git_well-0.2.4/git_well/repo.pyi +0 -31
- git_well-0.2.4/git_well.egg-info/PKG-INFO +0 -350
- git_well-0.2.4/git_well.egg-info/requires.txt +0 -386
- git_well-0.2.4/pyproject.toml +0 -44
- git_well-0.2.4/requirements/tests.txt +0 -37
- git_well-0.2.4/setup.py +0 -259
- git_well-0.2.4/tests/test_cli.py +0 -19
- git_well-0.2.4/tests/test_import.py +0 -2
- {git_well-0.2.4 → git_well-0.3.1}/MANIFEST.in +0 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well/py.typed +0 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well.egg-info/dependency_links.txt +0 -0
- {git_well-0.2.4 → git_well-0.3.1}/git_well.egg-info/top_level.txt +0 -0
- {git_well-0.2.4 → git_well-0.3.1}/requirements/docs.txt +0 -0
- {git_well-0.2.4 → git_well-0.3.1}/setup.cfg +0 -0
git_well-0.3.1/PKG-INFO
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: git_well
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: The git_well module
|
|
5
|
+
Author-email: Jon Crall <erotemic@gmail.com>
|
|
6
|
+
License: Apache 2
|
|
7
|
+
Project-URL: Homepage, https://github.com/Erotemic/git_well
|
|
8
|
+
Classifier: Development Status :: 1 - Planning
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Classifier: Topic :: Utilities
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Requires-Dist: ubelt>=1.3.3
|
|
19
|
+
Requires-Dist: scriptconfig>=0.9.1; python_version >= "3.6"
|
|
20
|
+
Requires-Dist: rich>=12.4.4; python_version >= "3.8"
|
|
21
|
+
Requires-Dist: rich>=11.2.0; python_version < "3.8" and python_version >= "3.6"
|
|
22
|
+
Requires-Dist: git-python>=1.0.0; python_version >= "2.7"
|
|
23
|
+
Requires-Dist: packaging>=21.3
|
|
24
|
+
Requires-Dist: pyyaml>=6.0
|
|
25
|
+
Requires-Dist: networkx>=2.8; python_version < "4.0" and python_version >= "3.11"
|
|
26
|
+
Requires-Dist: networkx>=2.7; python_version < "3.11" and python_version >= "3.8"
|
|
27
|
+
Requires-Dist: networkx>=2.6.2; python_version < "3.8" and python_version >= "3.7"
|
|
28
|
+
Requires-Dist: networkx<=2.5.1,>=2.2.0; python_version < "3.7.0" and python_version >= "3.6.0"
|
|
29
|
+
Provides-Extra: docs
|
|
30
|
+
Requires-Dist: sphinx>=5.0.1; extra == "docs"
|
|
31
|
+
Requires-Dist: sphinx-autobuild>=2021.3.14; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "docs"
|
|
33
|
+
Requires-Dist: sphinxcontrib-napoleon>=0.7; extra == "docs"
|
|
34
|
+
Requires-Dist: sphinx-autoapi>=1.8.4; extra == "docs"
|
|
35
|
+
Requires-Dist: Pygments>=2.9.0; extra == "docs"
|
|
36
|
+
Requires-Dist: myst_parser>=0.18.0; extra == "docs"
|
|
37
|
+
Requires-Dist: sphinx-reredirects>=0.0.1; extra == "docs"
|
|
38
|
+
Provides-Extra: optional
|
|
39
|
+
Requires-Dist: argcomplete>=1.0; extra == "optional"
|
|
40
|
+
Requires-Dist: rich_argparse>=1.1.0; python_version >= "3.7" and extra == "optional"
|
|
41
|
+
Requires-Dist: fsspec; extra == "optional"
|
|
42
|
+
Requires-Dist: paramiko; extra == "optional"
|
|
43
|
+
Provides-Extra: tests
|
|
44
|
+
Requires-Dist: xdoctest>=1.1.5; extra == "tests"
|
|
45
|
+
Requires-Dist: pytest>=8.1.1; (python_version < "4.0" and python_version >= "3.13") and extra == "tests"
|
|
46
|
+
Requires-Dist: pytest>=8.1.1; python_version < "3.13" and extra == "tests"
|
|
47
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "tests"
|
|
48
|
+
Requires-Dist: pytest_timeout>=2.3.1; (python_version < "4.0" and python_version >= "3.12") and extra == "tests"
|
|
49
|
+
Requires-Dist: pytest_timeout>=1.4.2; python_version < "3.12" and extra == "tests"
|
|
50
|
+
Requires-Dist: coverage>=7.3.0; (python_version < "4.0" and python_version >= "3.12") and extra == "tests"
|
|
51
|
+
Requires-Dist: coverage>=6.1.1; (python_version < "3.12" and python_version >= "3.10") and extra == "tests"
|
|
52
|
+
Requires-Dist: coverage>=5.3.1; (python_version < "3.10" and python_version >= "3.9") and extra == "tests"
|
|
53
|
+
Requires-Dist: coverage>=6.1.1; (python_version < "3.9" and python_version >= "3.8") and extra == "tests"
|
|
@@ -95,6 +95,141 @@ The tools in this module are derived from:
|
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
|
|
98
|
+
Tracking large files with IPFS
|
|
99
|
+
------------------------------
|
|
100
|
+
|
|
101
|
+
``git-well`` also exposes an experimental ``git ipfs`` helper for keeping
|
|
102
|
+
large payloads out of Git while tracking reproducible IPFS CIDs in small
|
|
103
|
+
``*.ipfs`` sidecar files. There is intentionally no repository-local IPFS
|
|
104
|
+
store and no required ``git ipfs init`` step: Kubo still owns its normal
|
|
105
|
+
``$IPFS_PATH`` repository, while Git only tracks small sidecar metadata.
|
|
106
|
+
|
|
107
|
+
The minimum supported Kubo version is **0.37.0**. This is the first Kubo
|
|
108
|
+
release with ``ipfs add --pin-name``, which ``git ipfs add --name`` uses to
|
|
109
|
+
assign a human-readable name at import time.
|
|
110
|
+
|
|
111
|
+
The intended happy path is:
|
|
112
|
+
|
|
113
|
+
.. code:: bash
|
|
114
|
+
|
|
115
|
+
git ipfs doctor
|
|
116
|
+
git ipfs add data/ --name my-data
|
|
117
|
+
git commit -m "Track data with IPFS"
|
|
118
|
+
|
|
119
|
+
When you know the peer that is likely to provide the content, record it during
|
|
120
|
+
add:
|
|
121
|
+
|
|
122
|
+
.. code:: bash
|
|
123
|
+
|
|
124
|
+
git ipfs add data/ --name my-data --suggested-peers 12D3KooW...
|
|
125
|
+
|
|
126
|
+
A collaborator can then materialize the payloads with:
|
|
127
|
+
|
|
128
|
+
.. code:: bash
|
|
129
|
+
|
|
130
|
+
git clone <repo-url>
|
|
131
|
+
cd <repo>
|
|
132
|
+
git ipfs doctor
|
|
133
|
+
git ipfs pull
|
|
134
|
+
|
|
135
|
+
The sidecar stores the CID, relative path, object kind, byte size, and the
|
|
136
|
+
CID-affecting import settings. Volatile local details such as mtimes, command
|
|
137
|
+
elapsed time, and machine-specific cache state are intentionally left out of
|
|
138
|
+
the committed sidecar so repeated runs stay reviewable.
|
|
139
|
+
|
|
140
|
+
Sidecar schema v1
|
|
141
|
+
~~~~~~~~~~~~~~~~~
|
|
142
|
+
|
|
143
|
+
The ``schema_version: 1`` contract is intentionally small and YAML-first.
|
|
144
|
+
Unknown fields should be ignored by readers, and fields that are not needed to
|
|
145
|
+
materialize content should be treated as advisory. This keeps hand-written
|
|
146
|
+
sidecars easy to review and gives future versions room to add optional metadata
|
|
147
|
+
without breaking old repositories.
|
|
148
|
+
|
|
149
|
+
.. code:: yaml
|
|
150
|
+
|
|
151
|
+
schema_version: 1
|
|
152
|
+
type: ipfs-sidecar
|
|
153
|
+
cid: bafy...
|
|
154
|
+
rel_path: data
|
|
155
|
+
kind: directory
|
|
156
|
+
size_bytes: 123456
|
|
157
|
+
num_files: 42
|
|
158
|
+
pin_name: my-data
|
|
159
|
+
import:
|
|
160
|
+
recursive: true
|
|
161
|
+
cid_version: 1
|
|
162
|
+
raw_leaves: false
|
|
163
|
+
suggested_peers:
|
|
164
|
+
- 12D3KooW...
|
|
165
|
+
- /ip4/203.0.113.10/tcp/4001/p2p/12D3KooW...
|
|
166
|
+
|
|
167
|
+
Required fields for materialization are ``cid`` and ``rel_path``. The
|
|
168
|
+
``import`` mapping records options that affect CID reproducibility.
|
|
169
|
+
``pin_name``, sizes, counts, and ``suggested_peers`` are useful metadata, but a
|
|
170
|
+
reader should still be able to pull content without them.
|
|
171
|
+
|
|
172
|
+
Sidecars may include peer hints. Bare peer IDs are useful hints when routing
|
|
173
|
+
can discover addresses; full multiaddrs are more reliable when known.
|
|
174
|
+
``git ipfs pull`` makes a best-effort attempt to connect to ``suggested_peers``
|
|
175
|
+
before downloading. Peer hints can also be inspected or connected manually:
|
|
176
|
+
|
|
177
|
+
.. code:: bash
|
|
178
|
+
|
|
179
|
+
git ipfs peers
|
|
180
|
+
git ipfs peers --connect
|
|
181
|
+
|
|
182
|
+
To make the data retrievable by others, configure a Kubo remote pinning service
|
|
183
|
+
and push sidecar CIDs:
|
|
184
|
+
|
|
185
|
+
.. code:: bash
|
|
186
|
+
|
|
187
|
+
ipfs pin remote service add <service-name> <endpoint> <key>
|
|
188
|
+
git ipfs push --service <service-name>
|
|
189
|
+
|
|
190
|
+
Useful inspection commands:
|
|
191
|
+
|
|
192
|
+
.. code:: bash
|
|
193
|
+
|
|
194
|
+
git ipfs status
|
|
195
|
+
git ipfs status --full
|
|
196
|
+
git ipfs export --emit_bash
|
|
197
|
+
|
|
198
|
+
Dogfood checklist
|
|
199
|
+
~~~~~~~~~~~~~~~~~
|
|
200
|
+
|
|
201
|
+
When changing this workflow, test it on a scratch branch with a small real
|
|
202
|
+
payload before publishing the change:
|
|
203
|
+
|
|
204
|
+
.. code:: bash
|
|
205
|
+
|
|
206
|
+
git ipfs doctor
|
|
207
|
+
mkdir -p .git-well-ipfs-smoke
|
|
208
|
+
printf 'hello from git ipfs\n' > .git-well-ipfs-smoke/payload.txt
|
|
209
|
+
git ipfs add .git-well-ipfs-smoke --name git-well-ipfs-smoke
|
|
210
|
+
git status --short .gitignore .git-well-ipfs-smoke.ipfs
|
|
211
|
+
rm -rf .git-well-ipfs-smoke
|
|
212
|
+
git ipfs pull .git-well-ipfs-smoke.ipfs
|
|
213
|
+
git ipfs status .git-well-ipfs-smoke.ipfs
|
|
214
|
+
|
|
215
|
+
The helper script ``dev/ipfs_dogfood_smoke.sh`` runs the same smoke flow and
|
|
216
|
+
accepts an optional peer hint as its second argument.
|
|
217
|
+
|
|
218
|
+
Troubleshooting
|
|
219
|
+
~~~~~~~~~~~~~~~
|
|
220
|
+
|
|
221
|
+
``git ipfs doctor`` is the first command to run when retrieval is confusing.
|
|
222
|
+
Common failure modes are reported with actionable hints:
|
|
223
|
+
|
|
224
|
+
* ``ipfs`` is missing from ``PATH``: install Kubo >= 0.37.0.
|
|
225
|
+
* The Kubo repo is missing: run ``ipfs init`` for Kubo itself. This does not
|
|
226
|
+
create anything inside the Git repository.
|
|
227
|
+
* The daemon/API is offline: start ``ipfs daemon`` or check ``IPFS_PATH``.
|
|
228
|
+
* Retrieval cannot find a CID: check that someone is pinning the content, then
|
|
229
|
+
try ``git ipfs peers --connect`` or add more specific ``suggested_peers``.
|
|
230
|
+
* Named pins fail: upgrade to Kubo >= 0.37.0 or omit ``--name``.
|
|
231
|
+
|
|
232
|
+
|
|
98
233
|
Use Cases
|
|
99
234
|
---------
|
|
100
235
|
|
|
@@ -1,25 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
import os
|
|
1
5
|
import ubelt as ub
|
|
2
6
|
|
|
3
7
|
|
|
4
|
-
def rich_print(*args, **kwargs):
|
|
8
|
+
def rich_print(*args: Any, **kwargs: Any) -> Any:
|
|
5
9
|
try:
|
|
6
|
-
from rich import print as
|
|
10
|
+
from rich import print as printer
|
|
7
11
|
except Exception:
|
|
8
|
-
|
|
9
|
-
return
|
|
12
|
+
printer: Any = print
|
|
13
|
+
return printer(*args, **kwargs)
|
|
10
14
|
|
|
11
15
|
|
|
12
|
-
def find_merged_branches(repo, main_branch='main'):
|
|
16
|
+
def find_merged_branches(repo: Any, main_branch: str = 'main') -> Any:
|
|
13
17
|
# git branch --merged main
|
|
14
18
|
# main_branch = 'main'
|
|
15
|
-
merged_branches = [
|
|
19
|
+
merged_branches = [
|
|
20
|
+
p.replace('*', '').strip()
|
|
21
|
+
for p in repo.git.branch(merged=main_branch).split('\n')
|
|
22
|
+
if p.strip()
|
|
23
|
+
]
|
|
16
24
|
merged_branches = ub.oset(merged_branches) - {main_branch}
|
|
17
25
|
return merged_branches
|
|
18
26
|
|
|
19
27
|
|
|
20
|
-
def confirm(msg):
|
|
28
|
+
def confirm(msg: str) -> bool:
|
|
21
29
|
try:
|
|
22
30
|
from rich import prompt
|
|
31
|
+
|
|
23
32
|
ret = prompt.Confirm.ask(msg)
|
|
24
33
|
except ImportError:
|
|
25
34
|
while True:
|
|
@@ -35,7 +44,7 @@ def confirm(msg):
|
|
|
35
44
|
return ret
|
|
36
45
|
|
|
37
46
|
|
|
38
|
-
def choice_prompt(msg, choices):
|
|
47
|
+
def choice_prompt(msg: str, choices: list[str]) -> str:
|
|
39
48
|
"""
|
|
40
49
|
Ignore:
|
|
41
50
|
choice_prompt('which one?', choices=['a', 'b', 'c'])
|
|
@@ -50,9 +59,10 @@ def choice_prompt(msg, choices):
|
|
|
50
59
|
"""
|
|
51
60
|
Assigns an integer to each choice.
|
|
52
61
|
"""
|
|
53
|
-
|
|
62
|
+
|
|
63
|
+
def make_prompt(self, default: Any) -> Any:
|
|
54
64
|
prompt = self.prompt.copy()
|
|
55
|
-
prompt.end =
|
|
65
|
+
prompt.end = ''
|
|
56
66
|
|
|
57
67
|
if self.show_choices and self.choices:
|
|
58
68
|
prompt.append('\n')
|
|
@@ -65,20 +75,20 @@ def choice_prompt(msg, choices):
|
|
|
65
75
|
raise AssertionError('choices cannot be integers')
|
|
66
76
|
|
|
67
77
|
prompt.append(f'{idx}. ', style='json.number')
|
|
68
|
-
prompt.append(f'{choice}\n', style=
|
|
78
|
+
prompt.append(f'{choice}\n', style='prompt')
|
|
69
79
|
if (
|
|
70
80
|
default != ...
|
|
71
81
|
and self.show_default
|
|
72
82
|
and isinstance(default, (str, self.response_type))
|
|
73
83
|
):
|
|
74
|
-
prompt.append(
|
|
84
|
+
prompt.append(' ')
|
|
75
85
|
_default = self.render_default(default)
|
|
76
86
|
prompt.append(_default)
|
|
77
87
|
|
|
78
88
|
prompt.append(self.prompt_suffix)
|
|
79
89
|
return prompt
|
|
80
90
|
|
|
81
|
-
def process_response(self, value: str):
|
|
91
|
+
def process_response(self, value: str) -> str:
|
|
82
92
|
value = value.strip()
|
|
83
93
|
assert self.choices is not None
|
|
84
94
|
try:
|
|
@@ -100,18 +110,27 @@ def choice_prompt(msg, choices):
|
|
|
100
110
|
return ChoiceWithIntPrompt.ask(msg, choices=choices)
|
|
101
111
|
|
|
102
112
|
|
|
103
|
-
def find_git_root(dpath):
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
def find_git_root(dpath: str | os.PathLike[str]) -> ub.Path:
|
|
114
|
+
if 0:
|
|
115
|
+
# Old implementation
|
|
116
|
+
cwd = ub.Path(dpath).absolute()
|
|
117
|
+
parts = cwd.parts
|
|
118
|
+
found = None
|
|
119
|
+
for i in reversed(range(0, len(parts) + 1)):
|
|
120
|
+
p = ub.Path(*parts[0:i])
|
|
121
|
+
cand = p / '.git'
|
|
122
|
+
if cand.exists():
|
|
123
|
+
found = p
|
|
124
|
+
break
|
|
125
|
+
if found is None:
|
|
126
|
+
raise Exception('cannot find git root')
|
|
127
|
+
else:
|
|
128
|
+
# New implementation (should be more robust)
|
|
129
|
+
# allow running inside a subdir of a repo
|
|
130
|
+
info = ub.cmd('git rev-parse --show-toplevel', cwd=dpath, verbose=0)
|
|
131
|
+
if info['ret'] != 0:
|
|
132
|
+
raise RuntimeError(f'Not a git repo: {dpath}')
|
|
133
|
+
found = ub.Path(info['out'].strip())
|
|
115
134
|
return found
|
|
116
135
|
|
|
117
136
|
|
|
@@ -150,15 +169,16 @@ class GitURL(str):
|
|
|
150
169
|
>>> assert recon == url
|
|
151
170
|
"""
|
|
152
171
|
|
|
153
|
-
def __init__(self, data):
|
|
172
|
+
def __init__(self, data: str) -> None:
|
|
154
173
|
# note: inheriting from str so data is handled in __new__
|
|
155
|
-
self._info = None
|
|
174
|
+
self._info: dict[str, Any] | None = None
|
|
156
175
|
|
|
157
|
-
def _parse(self):
|
|
176
|
+
def _parse(self) -> None:
|
|
158
177
|
import parse
|
|
178
|
+
|
|
159
179
|
parse.Parser('ssh://{user}')
|
|
160
180
|
|
|
161
|
-
def _fixup_endpoint(self, repo_endpoint):
|
|
181
|
+
def _fixup_endpoint(self, repo_endpoint: str) -> tuple[str, str]:
|
|
162
182
|
if repo_endpoint.endswith('.git'):
|
|
163
183
|
repo_name = repo_endpoint[:-4]
|
|
164
184
|
else:
|
|
@@ -167,7 +187,7 @@ class GitURL(str):
|
|
|
167
187
|
return repo_name, repo_endpoint
|
|
168
188
|
|
|
169
189
|
@property
|
|
170
|
-
def info(self):
|
|
190
|
+
def info(self) -> dict[str, Any]:
|
|
171
191
|
if self._info is None:
|
|
172
192
|
url = self
|
|
173
193
|
info = {}
|
|
@@ -181,6 +201,17 @@ class GitURL(str):
|
|
|
181
201
|
info['repo_endpoint'] = repo_endpoint
|
|
182
202
|
info['user'] = None
|
|
183
203
|
info['protocol'] = 'https'
|
|
204
|
+
elif url.startswith('http://'):
|
|
205
|
+
# Coerce http to https
|
|
206
|
+
parts = url.split('http://')[1].split('/', 3)
|
|
207
|
+
repo_endpoint = parts[2]
|
|
208
|
+
repo_name, repo_endpoint = self._fixup_endpoint(repo_endpoint)
|
|
209
|
+
info['host'] = parts[0]
|
|
210
|
+
info['group'] = parts[1]
|
|
211
|
+
info['repo_name'] = repo_name
|
|
212
|
+
info['repo_endpoint'] = repo_endpoint
|
|
213
|
+
info['user'] = None
|
|
214
|
+
info['protocol'] = 'http'
|
|
184
215
|
elif url.startswith('git@'):
|
|
185
216
|
parts = url.split('git@')[1].split(':')
|
|
186
217
|
repo_endpoint = parts[1].split('/')[1]
|
|
@@ -208,7 +239,7 @@ class GitURL(str):
|
|
|
208
239
|
elif url.endswith('/.git'):
|
|
209
240
|
# An ssh protocol to an explicit directory
|
|
210
241
|
host, rest = url.split(':', 1)
|
|
211
|
-
parts = rest.rsplit('/',
|
|
242
|
+
parts = rest.rsplit('/', 2)
|
|
212
243
|
info['host'] = host
|
|
213
244
|
info['group'] = parts[0]
|
|
214
245
|
info['repo_name'] = parts[1]
|
|
@@ -216,7 +247,9 @@ class GitURL(str):
|
|
|
216
247
|
info['protocol'] = 'scp'
|
|
217
248
|
elif '//' not in url and '@' not in url:
|
|
218
249
|
parts = url.split(':')
|
|
219
|
-
repo_name, repo_endpoint = self._fixup_endpoint(
|
|
250
|
+
repo_name, repo_endpoint = self._fixup_endpoint(
|
|
251
|
+
parts[1].split('/')[1]
|
|
252
|
+
)
|
|
220
253
|
info['host'] = parts[0]
|
|
221
254
|
info['group'] = parts[1].split('/')[0]
|
|
222
255
|
info['repo_name'] = repo_name
|
|
@@ -228,7 +261,7 @@ class GitURL(str):
|
|
|
228
261
|
self._info = info
|
|
229
262
|
return self._info
|
|
230
263
|
|
|
231
|
-
def to_protocol(self, protocol):
|
|
264
|
+
def to_protocol(self, protocol: str) -> GitURL:
|
|
232
265
|
"""
|
|
233
266
|
Convert the URL to a different protocol
|
|
234
267
|
"""
|
|
@@ -241,22 +274,44 @@ class GitURL(str):
|
|
|
241
274
|
else:
|
|
242
275
|
raise KeyError(protocol)
|
|
243
276
|
|
|
244
|
-
def to_git(self):
|
|
277
|
+
def to_git(self) -> GitURL:
|
|
245
278
|
info = self.info
|
|
246
|
-
new_url =
|
|
279
|
+
new_url = (
|
|
280
|
+
'git@'
|
|
281
|
+
+ info['host']
|
|
282
|
+
+ ':'
|
|
283
|
+
+ info['group']
|
|
284
|
+
+ '/'
|
|
285
|
+
+ info['repo_endpoint']
|
|
286
|
+
)
|
|
247
287
|
return self.__class__(new_url)
|
|
248
288
|
|
|
249
|
-
def to_ssh(self):
|
|
289
|
+
def to_ssh(self) -> GitURL:
|
|
250
290
|
info = self.info
|
|
251
291
|
user = info.get('user', None)
|
|
252
292
|
if user is None:
|
|
253
293
|
user_part = ''
|
|
254
294
|
else:
|
|
255
295
|
user_part = user + '@'
|
|
256
|
-
new_url =
|
|
296
|
+
new_url = (
|
|
297
|
+
'ssh://'
|
|
298
|
+
+ user_part
|
|
299
|
+
+ info['host']
|
|
300
|
+
+ '/'
|
|
301
|
+
+ info['group']
|
|
302
|
+
+ '/'
|
|
303
|
+
+ info['repo_endpoint']
|
|
304
|
+
)
|
|
257
305
|
return self.__class__(new_url)
|
|
258
306
|
|
|
259
|
-
def to_https(self):
|
|
307
|
+
def to_https(self) -> GitURL:
|
|
260
308
|
info = self.info
|
|
261
|
-
new_url =
|
|
309
|
+
new_url = (
|
|
310
|
+
'https://'
|
|
311
|
+
+ info['host']
|
|
312
|
+
+ '/'
|
|
313
|
+
+ info['group']
|
|
314
|
+
+ '/'
|
|
315
|
+
+ info['repo_endpoint']
|
|
316
|
+
)
|
|
262
317
|
return self.__class__(new_url)
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
|
|
2
4
|
def make_dummy_git_repo():
|
|
3
5
|
import ubelt as ub
|
|
6
|
+
|
|
4
7
|
repo_dpath = ub.Path.appdir('git_well', 'tests', 'dummy-git-repo')
|
|
5
8
|
|
|
6
9
|
# On windows we need to use a tempdir because it doesn't seem to let you
|
|
7
10
|
# clean up after yourself.
|
|
8
11
|
if ub.WIN32:
|
|
9
12
|
import tempfile
|
|
13
|
+
|
|
10
14
|
repo_dpath = ub.Path(tempfile.mkdtemp()) / 'dummy-git-repo'
|
|
11
15
|
|
|
12
16
|
# try:
|
|
@@ -28,46 +32,47 @@ def make_dummy_git_repo():
|
|
|
28
32
|
# raise
|
|
29
33
|
|
|
30
34
|
import git
|
|
35
|
+
|
|
31
36
|
repo = git.Repo.init(repo_dpath, initial_branch='main')
|
|
32
37
|
|
|
33
38
|
repo.git.config('user.email', 'demo.user@zombo.com', local=True)
|
|
34
39
|
repo.git.config('user.name', 'Demo User', local=True)
|
|
35
40
|
|
|
36
|
-
fpath =
|
|
41
|
+
fpath = repo_dpath / 'data1.txt'
|
|
37
42
|
fpath.write_text('data')
|
|
38
43
|
|
|
39
44
|
repo.git.add(fpath)
|
|
40
|
-
repo.git.commit(a=True, m=
|
|
45
|
+
repo.git.commit(a=True, m='Add Data1')
|
|
41
46
|
|
|
42
47
|
for idx in range(5):
|
|
43
48
|
fpath.write_text(f'data{idx}')
|
|
44
|
-
repo.git.commit(a=True, m=
|
|
49
|
+
repo.git.commit(a=True, m='wip')
|
|
45
50
|
|
|
46
51
|
repo.git.checkout(b='branch1')
|
|
47
|
-
fpath =
|
|
52
|
+
fpath = repo_dpath / 'data2.txt'
|
|
48
53
|
for idx in range(5):
|
|
49
54
|
fpath.write_text(f'data{idx}')
|
|
50
55
|
repo.git.add(fpath)
|
|
51
|
-
repo.git.commit(a=True, m=
|
|
56
|
+
repo.git.commit(a=True, m='wip')
|
|
52
57
|
|
|
53
58
|
repo.git.checkout('main')
|
|
54
59
|
|
|
55
60
|
repo.git.checkout(b='branch2')
|
|
56
|
-
fpath =
|
|
61
|
+
fpath = repo_dpath / 'data3.txt'
|
|
57
62
|
for idx in range(5):
|
|
58
63
|
fpath.write_text(f'data{idx}')
|
|
59
64
|
repo.git.add(fpath)
|
|
60
|
-
repo.git.commit(a=True, m=
|
|
65
|
+
repo.git.commit(a=True, m='wip')
|
|
61
66
|
|
|
62
67
|
repo.git.checkout('main')
|
|
63
68
|
repo.git.merge('branch1')
|
|
64
69
|
repo.git.merge('branch2')
|
|
65
70
|
|
|
66
|
-
fpath =
|
|
71
|
+
fpath = repo_dpath / 'data3.txt'
|
|
67
72
|
for idx in range(10):
|
|
68
73
|
fpath.write_text(f'data{idx}')
|
|
69
74
|
repo.git.add(fpath)
|
|
70
|
-
repo.git.commit(a=True, m=
|
|
75
|
+
repo.git.commit(a=True, m='wip')
|
|
71
76
|
|
|
72
77
|
return repo_dpath
|
|
73
78
|
|
|
@@ -75,6 +80,7 @@ def make_dummy_git_repo():
|
|
|
75
80
|
def make_dummy_git_repo_with_orphans():
|
|
76
81
|
import ubelt as ub
|
|
77
82
|
import git
|
|
83
|
+
|
|
78
84
|
repo_dpath = ub.Path.appdir('git_well', 'tests', 'dummy-git-orphan-repo')
|
|
79
85
|
repo_dpath.delete().ensuredir()
|
|
80
86
|
|
|
@@ -84,7 +90,7 @@ def make_dummy_git_repo_with_orphans():
|
|
|
84
90
|
repo.git.config('user.name', 'Demo User', local=True)
|
|
85
91
|
|
|
86
92
|
# Write a starting commit
|
|
87
|
-
fpath =
|
|
93
|
+
fpath = repo_dpath / 'data1.txt'
|
|
88
94
|
fpath.write_text('data-base')
|
|
89
95
|
repo.git.add(fpath)
|
|
90
96
|
repo.git.commit(a=True, m='base commit')
|