batchfetch 1.1.1__tar.gz → 1.1.3__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.
- {batchfetch-1.1.1/batchfetch.egg-info → batchfetch-1.1.3}/PKG-INFO +2 -2
- {batchfetch-1.1.1 → batchfetch-1.1.3}/README.md +1 -1
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch/__init__.py +1 -1
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch/batchfetch_base.py +3 -3
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch/batchfetch_cli.py +27 -23
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch/batchfetch_git.py +188 -68
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch/helpers.py +1 -1
- {batchfetch-1.1.1 → batchfetch-1.1.3/batchfetch.egg-info}/PKG-INFO +2 -2
- {batchfetch-1.1.1 → batchfetch-1.1.3}/run_tests.sh +1 -1
- {batchfetch-1.1.1 → batchfetch-1.1.3}/setup.py +2 -2
- {batchfetch-1.1.1 → batchfetch-1.1.3}/tests/test_helpers.py +1 -1
- {batchfetch-1.1.1 → batchfetch-1.1.3}/.gitignore +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/LICENSE +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch.egg-info/SOURCES.txt +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch.egg-info/dependency_links.txt +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch.egg-info/entry_points.txt +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch.egg-info/requires.txt +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/batchfetch.egg-info/top_level.txt +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/setup.cfg +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/tests/data/test-md5sum.txt +0 -0
- {batchfetch-1.1.1 → batchfetch-1.1.3}/tests/data/test-run_simple.sh +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: batchfetch
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.3
|
|
4
4
|
Summary: Efficiently clone and pull multiple Git repositories.
|
|
5
5
|
Home-page: https://github.com/jamescherti/batchfetch
|
|
6
6
|
Author: James Cherti
|
|
@@ -95,7 +95,7 @@ options:
|
|
|
95
95
|
|
|
96
96
|
## License
|
|
97
97
|
|
|
98
|
-
Copyright (
|
|
98
|
+
Copyright (C) 2024 [James Cherti](https://www.jamescherti.com)
|
|
99
99
|
|
|
100
100
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
101
101
|
|
|
@@ -71,7 +71,7 @@ options:
|
|
|
71
71
|
|
|
72
72
|
## License
|
|
73
73
|
|
|
74
|
-
Copyright (
|
|
74
|
+
Copyright (C) 2024 [James Cherti](https://www.jamescherti.com)
|
|
75
75
|
|
|
76
76
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
77
77
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
#
|
|
3
|
-
# Copyright (
|
|
3
|
+
# Copyright (C) 2024 James Cherti
|
|
4
4
|
# URL: https://github.com/jamescherti/batchfetch
|
|
5
5
|
#
|
|
6
6
|
# This program is free software: you can redistribute it and/or modify it under
|
|
@@ -58,7 +58,7 @@ class TaskBase:
|
|
|
58
58
|
|
|
59
59
|
# Options
|
|
60
60
|
self.options = {}
|
|
61
|
-
self.options.update(deepcopy(self.global_options_values))
|
|
61
|
+
self.options.update(deepcopy(self.global_options_values))
|
|
62
62
|
self.options.update(deepcopy(self._item_options))
|
|
63
63
|
schema = Schema(self.global_options_schema)
|
|
64
64
|
schema.validate(self.options)
|
|
@@ -94,7 +94,7 @@ class TaskBase:
|
|
|
94
94
|
raise KeyError(f"The item '{key}' was not found in '{self.values}")
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
class
|
|
97
|
+
class TaskBatchFetch(TaskBase):
|
|
98
98
|
"""Plugin downloader base class."""
|
|
99
99
|
|
|
100
100
|
def __init__(self, data: Dict[str, Any], options: Dict[str, Any]):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
#
|
|
3
|
-
# Copyright (
|
|
3
|
+
# Copyright (C) 2024 James Cherti
|
|
4
4
|
# URL: https://github.com/jamescherti/batchfetch
|
|
5
5
|
#
|
|
6
6
|
# This program is free software: you can redistribute it and/or modify it under
|
|
@@ -33,7 +33,7 @@ from colorama import Fore
|
|
|
33
33
|
from schema import Optional, Or, Schema, SchemaError
|
|
34
34
|
from setproctitle import setproctitle
|
|
35
35
|
|
|
36
|
-
from .batchfetch_base import
|
|
36
|
+
from .batchfetch_base import BatchFetchError, TaskBatchFetch
|
|
37
37
|
from .batchfetch_git import BatchFetchGit
|
|
38
38
|
|
|
39
39
|
|
|
@@ -51,7 +51,7 @@ class BatchFetchCli:
|
|
|
51
51
|
|
|
52
52
|
# Plugin
|
|
53
53
|
self.batchfetch_schemas: Dict[Any, Any] = {}
|
|
54
|
-
self.batchfetch_classes: Dict[str,
|
|
54
|
+
self.batchfetch_classes: Dict[str, TaskBatchFetch] = {}
|
|
55
55
|
self.cfg_schema: Dict[Any, Any] = {}
|
|
56
56
|
self._plugin_add("git", BatchFetchGit)
|
|
57
57
|
|
|
@@ -216,8 +216,11 @@ def parse_args():
|
|
|
216
216
|
usage = "%(prog)s [--option] [args]"
|
|
217
217
|
parser = argparse.ArgumentParser(description=desc, usage=usage)
|
|
218
218
|
|
|
219
|
-
parser.add_argument("
|
|
220
|
-
|
|
219
|
+
parser.add_argument("-f",
|
|
220
|
+
"--file",
|
|
221
|
+
default=None,
|
|
222
|
+
required=False,
|
|
223
|
+
help=("Specify the batchfetch YAML file "
|
|
221
224
|
"(default: './batchfetch.yaml')."))
|
|
222
225
|
|
|
223
226
|
parser.add_argument(
|
|
@@ -231,24 +234,24 @@ def parse_args():
|
|
|
231
234
|
)
|
|
232
235
|
|
|
233
236
|
args = parser.parse_args()
|
|
234
|
-
if not args.batchfetch_files:
|
|
235
|
-
args.batchfetch_files = ["./batchfetch.yaml"]
|
|
236
237
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
if not args.file:
|
|
239
|
+
args.file = "./batchfetch.yaml"
|
|
240
|
+
|
|
241
|
+
if not Path(args.file).is_file():
|
|
242
|
+
print(f"Error: File not found: {args.file}",
|
|
243
|
+
file=sys.stderr)
|
|
244
|
+
sys.exit(1)
|
|
242
245
|
|
|
243
246
|
return args
|
|
244
247
|
|
|
245
248
|
|
|
246
|
-
def run_batchfetch_procedure(
|
|
249
|
+
def run_batchfetch_procedure(file: Path, args) -> int:
|
|
247
250
|
errno = 0
|
|
248
251
|
batchfetch_cli = BatchFetchCli(verbose=args.verbose,
|
|
249
252
|
max_workers=int(args.jobs))
|
|
250
|
-
batchfetch_cli.load(
|
|
251
|
-
os.chdir(
|
|
253
|
+
batchfetch_cli.load(file)
|
|
254
|
+
os.chdir(file.parent)
|
|
252
255
|
|
|
253
256
|
try:
|
|
254
257
|
if not batchfetch_cli.run_tasks():
|
|
@@ -276,14 +279,15 @@ def command_line_interface():
|
|
|
276
279
|
|
|
277
280
|
args = parse_args()
|
|
278
281
|
done = []
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
282
|
+
file = Path(args.file)
|
|
283
|
+
file_resolved = file.resolve()
|
|
284
|
+
if not file_resolved:
|
|
285
|
+
print(f"Error: cannot resolve the path {file}",
|
|
286
|
+
file=sys.stderr)
|
|
287
|
+
sys.exit(1)
|
|
288
|
+
|
|
289
|
+
done.append(file_resolved)
|
|
290
|
+
errno |= run_batchfetch_procedure(file, args)
|
|
287
291
|
|
|
288
292
|
sys.exit(errno)
|
|
289
293
|
except BrokenPipeError:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
#
|
|
3
|
-
# Copyright (
|
|
3
|
+
# Copyright (C) 2024 James Cherti
|
|
4
4
|
# URL: https://github.com/jamescherti/batchfetch
|
|
5
5
|
#
|
|
6
6
|
# This program is free software: you can redistribute it and/or modify it under
|
|
@@ -28,18 +28,24 @@ from typing import List, Union
|
|
|
28
28
|
|
|
29
29
|
from schema import Optional
|
|
30
30
|
|
|
31
|
-
from .batchfetch_base import
|
|
31
|
+
from .batchfetch_base import BatchFetchError, TaskBatchFetch
|
|
32
32
|
from .helpers import run_simple
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
class GitReferenceDoesNotExist(Exception):
|
|
36
|
-
"""
|
|
36
|
+
"""The Git reference does not exist."""
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
class
|
|
39
|
+
class GitRemoteError(Exception):
|
|
40
|
+
"""The git remote does not exist."""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class BatchFetchGit(TaskBatchFetch):
|
|
40
44
|
"""Clone or update a Git repository."""
|
|
41
45
|
|
|
42
46
|
def __init__(self, *args, **kwargs):
|
|
47
|
+
self._git_fetch_origin_done = False
|
|
48
|
+
|
|
43
49
|
super().__init__(*args, **kwargs)
|
|
44
50
|
self.env["GIT_TERMINAL_PROMPT"] = "0"
|
|
45
51
|
self.env["GIT_PAGER"] = ""
|
|
@@ -87,25 +93,11 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
87
93
|
posixpath.basename(
|
|
88
94
|
self.values[self.main_key]) # type: ignore
|
|
89
95
|
|
|
90
|
-
def _git_ref(self, cwd: Union[None, Path] = None) -> str:
|
|
91
|
-
"""Get the commit reference of HEAD.
|
|
92
|
-
|
|
93
|
-
The command will fail if the branch is detached.
|
|
94
|
-
"""
|
|
95
|
-
cmd = ["git", "show-ref", "--head", "--verify", "HEAD"]
|
|
96
|
-
try:
|
|
97
|
-
stdout, _ = run_simple(cmd, cwd=cwd, env=self.env)
|
|
98
|
-
output = stdout[0].split(" ")[0]
|
|
99
|
-
except IndexError:
|
|
100
|
-
return ""
|
|
101
|
-
return output
|
|
102
|
-
|
|
103
96
|
def update(self):
|
|
104
97
|
"""Clone or update a Git repository."""
|
|
105
98
|
super().update()
|
|
106
99
|
|
|
107
100
|
is_clone = False
|
|
108
|
-
|
|
109
101
|
if not self.git_local_dir.exists():
|
|
110
102
|
is_clone = True
|
|
111
103
|
|
|
@@ -117,16 +109,15 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
117
109
|
else:
|
|
118
110
|
update_type = "UPDATE"
|
|
119
111
|
|
|
120
|
-
self.add_output(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if self["reference"] else "") + "\n"
|
|
124
|
-
)
|
|
112
|
+
self.add_output(f"[GIT {update_type}] {self[self.main_key]}" +
|
|
113
|
+
(f" (Ref: {self['reference']})"
|
|
114
|
+
if self["reference"] else "") + "\n")
|
|
125
115
|
|
|
126
116
|
try:
|
|
127
117
|
# Delete
|
|
128
118
|
if self["delete"]:
|
|
129
119
|
self._repo_delete()
|
|
120
|
+
|
|
130
121
|
# Clone
|
|
131
122
|
elif is_clone:
|
|
132
123
|
self._repo_clone()
|
|
@@ -134,10 +125,10 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
134
125
|
# Update
|
|
135
126
|
if self.git_local_dir.is_dir():
|
|
136
127
|
# Pre exec
|
|
128
|
+
self._update_current_branch()
|
|
129
|
+
self._repo_fix_remote_origin()
|
|
137
130
|
self._run_pre_exec(cwd=self.git_local_dir)
|
|
138
131
|
|
|
139
|
-
self._repo_check_remote_origin()
|
|
140
|
-
self._update_current_branch()
|
|
141
132
|
self._repo_reset()
|
|
142
133
|
|
|
143
134
|
git_merge_done = self._repo_pull()
|
|
@@ -163,14 +154,28 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
163
154
|
|
|
164
155
|
return self.values
|
|
165
156
|
|
|
157
|
+
def _git_ref(self, cwd: Union[None, Path] = None) -> str:
|
|
158
|
+
"""Get the commit reference of HEAD.
|
|
159
|
+
|
|
160
|
+
The command will fail if the branch is detached.
|
|
161
|
+
"""
|
|
162
|
+
cmd = ["git", "show-ref", "--head", "--verify", "HEAD"]
|
|
163
|
+
try:
|
|
164
|
+
stdout, _ = run_simple(cmd, cwd=cwd, env=self.env)
|
|
165
|
+
output = stdout[0].split(" ")[0]
|
|
166
|
+
except IndexError:
|
|
167
|
+
return ""
|
|
168
|
+
return output
|
|
169
|
+
|
|
166
170
|
def _update_current_branch(self):
|
|
167
171
|
try:
|
|
168
|
-
|
|
172
|
+
stdout, _ = run_simple(
|
|
169
173
|
["git", "symbolic-ref", "--short", "HEAD"],
|
|
170
174
|
env=self.env,
|
|
171
175
|
cwd=self.git_local_dir,
|
|
172
176
|
)
|
|
173
|
-
|
|
177
|
+
self.current_branch = stdout[0]
|
|
178
|
+
except (IndexError, subprocess.CalledProcessError):
|
|
174
179
|
# Not a symbolic ref
|
|
175
180
|
self.current_branch = None
|
|
176
181
|
|
|
@@ -209,47 +214,91 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
209
214
|
|
|
210
215
|
# Merge
|
|
211
216
|
do_git_pull = self["git_pull"]
|
|
212
|
-
if self["reference"]:
|
|
217
|
+
if not self["reference"]:
|
|
218
|
+
self.add_output(
|
|
219
|
+
self.indent_spaces +
|
|
220
|
+
"[INFO] Git fetch origin reason: " +
|
|
221
|
+
f"No 'reference:' specified." +
|
|
222
|
+
"\n")
|
|
223
|
+
else:
|
|
213
224
|
do_git_pull = False
|
|
214
225
|
commit_ref = None
|
|
215
226
|
|
|
216
227
|
try:
|
|
217
|
-
#
|
|
218
|
-
#
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
# points to. Using `git rev-parse <tagname>^{commit}` allows
|
|
222
|
-
# getting the right reference.
|
|
223
|
-
commit_ref = self._git_tags(self["reference"] + "^{commit}")[0]
|
|
228
|
+
# Check if the reference such as
|
|
229
|
+
# 0560fe21d1173b2221fd8c600fab818f7eecbad4 exist
|
|
230
|
+
commit_ref = self._git_tags(self["reference"])[0]
|
|
231
|
+
commit_ref = commit_ref.strip().lower()
|
|
224
232
|
except GitReferenceDoesNotExist:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
else: # The reference exists
|
|
233
|
+
pass
|
|
234
|
+
|
|
235
|
+
if not commit_ref:
|
|
229
236
|
try:
|
|
230
237
|
# If the tag is annotated, it points to a tag object, not
|
|
231
238
|
# directly to a commit. You need to resolve it to the
|
|
232
239
|
# commit it points to. Using `git rev-parse
|
|
233
240
|
# <tagname>^{commit}` allows getting the right reference.
|
|
234
|
-
|
|
241
|
+
commit_ref = self._git_tags("origin/" + self["reference"] +
|
|
242
|
+
"^{commit}")[0]
|
|
243
|
+
commit_ref = commit_ref.strip().lower()
|
|
235
244
|
except GitReferenceDoesNotExist:
|
|
236
|
-
#
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
# The wanted commit reference does not exist
|
|
240
|
-
# Or the commit ref of HEAD hasn't changed
|
|
241
|
-
if commit_ref and commit_ref_head == commit_ref:
|
|
242
|
-
do_git_pull = False
|
|
243
|
-
else:
|
|
245
|
+
# The branch does not exist. We should git pull in case we
|
|
246
|
+
# can get the reference
|
|
244
247
|
do_git_pull = True
|
|
248
|
+
self.add_output(
|
|
249
|
+
self.indent_spaces +
|
|
250
|
+
"[INFO] Git fetch origin reason:" +
|
|
251
|
+
f"The reference does not exist: {self['reference']}" +
|
|
252
|
+
"\n")
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
if not do_git_pull:
|
|
256
|
+
# Check if it is a branch or a tag such as 1.1.3
|
|
257
|
+
is_tag = False
|
|
258
|
+
try:
|
|
259
|
+
# Check if the branch is a tag or a branch
|
|
260
|
+
cmd = ["git", "show-ref", "--verify", "--quiet",
|
|
261
|
+
f"refs/heads/{self['reference']}"]
|
|
262
|
+
run_simple(cmd, env=self.env, cwd=self.git_local_dir)
|
|
263
|
+
self.add_output(
|
|
264
|
+
self.indent_spaces +
|
|
265
|
+
"[INFO] Git fetch origin reason:" +
|
|
266
|
+
f"{self['reference']} is a branch, not a tag" +
|
|
267
|
+
"\n")
|
|
268
|
+
do_git_pull = True
|
|
269
|
+
except subprocess.CalledProcessError:
|
|
270
|
+
pass
|
|
271
|
+
|
|
272
|
+
# if not do_git_pull:
|
|
273
|
+
# try:
|
|
274
|
+
# # If the tag is annotated, it points to a tag object,
|
|
275
|
+
# # not directly to a commit. You need to resolve it to
|
|
276
|
+
# # the commit it points to. Using `git rev-parse
|
|
277
|
+
# # <tagname>^{commit}` allows getting the right
|
|
278
|
+
# # reference.
|
|
279
|
+
# commit_ref_head = self._git_tags("HEAD^{commit}")[0]
|
|
280
|
+
# commit_ref_head = commit_ref_head.strip().lower()
|
|
281
|
+
# except GitReferenceDoesNotExist:
|
|
282
|
+
# # HEAD is detached
|
|
283
|
+
# commit_ref_head = None
|
|
284
|
+
#
|
|
285
|
+
# # The wanted commit reference does not exist
|
|
286
|
+
# # Or the commit ref of HEAD hasn't changed
|
|
287
|
+
# if not commit_ref_head or commit_ref_head != commit_ref:
|
|
288
|
+
# self.add_output(
|
|
289
|
+
# self.indent_spaces +
|
|
290
|
+
# "[INFO] Git fetch origin reason: "
|
|
291
|
+
# f"Commit ref head '{commit_ref_head}' != "
|
|
292
|
+
# f"commit ref '{commit_ref_head}'"
|
|
293
|
+
# "\n")
|
|
294
|
+
# do_git_pull = True
|
|
245
295
|
|
|
246
296
|
if not do_git_pull:
|
|
247
297
|
self.add_output(self.indent_spaces + "[INFO] git pull ignored\n")
|
|
248
298
|
return git_merge
|
|
249
299
|
|
|
250
300
|
# Fetch
|
|
251
|
-
|
|
252
|
-
self._run(cmd, cwd=str(self.git_local_dir), env=self.env)
|
|
301
|
+
self._git_fetch_origin()
|
|
253
302
|
|
|
254
303
|
# Merge
|
|
255
304
|
real_branch = self._git_is_local_branch("HEAD")
|
|
@@ -271,6 +320,44 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
271
320
|
|
|
272
321
|
return git_merge
|
|
273
322
|
|
|
323
|
+
def _git_get_remote_url(self, remote_name: str = "origin") -> str:
|
|
324
|
+
origin_url = ""
|
|
325
|
+
try:
|
|
326
|
+
stdout, _ = run_simple(["git", "config",
|
|
327
|
+
f"remote.{remote_name}.url"],
|
|
328
|
+
env=self.env,
|
|
329
|
+
cwd=self.git_local_dir)
|
|
330
|
+
origin_url = stdout[0]
|
|
331
|
+
except (subprocess.CalledProcessError, IndexError) as err:
|
|
332
|
+
raise GitRemoteError(
|
|
333
|
+
f"Failed to get the Git remote url: {remote_name}") from err
|
|
334
|
+
|
|
335
|
+
return origin_url
|
|
336
|
+
|
|
337
|
+
def _git_set_remote_url(self, url: str,
|
|
338
|
+
remote_name: str = "origin") -> str:
|
|
339
|
+
origin_url = ""
|
|
340
|
+
try:
|
|
341
|
+
run_simple(["git", "remote", "remove", remote_name],
|
|
342
|
+
env=self.env, cwd=self.git_local_dir)
|
|
343
|
+
except subprocess.CalledProcessError:
|
|
344
|
+
# Ignore when it cannot be removed when it does not exist
|
|
345
|
+
pass
|
|
346
|
+
|
|
347
|
+
try:
|
|
348
|
+
stdout, _ = run_simple(
|
|
349
|
+
["git", "remote", "add", remote_name, url],
|
|
350
|
+
env=self.env,
|
|
351
|
+
cwd=self.git_local_dir,
|
|
352
|
+
)
|
|
353
|
+
origin_url = stdout[0]
|
|
354
|
+
except (subprocess.CalledProcessError, IndexError) as err:
|
|
355
|
+
raise GitRemoteError(
|
|
356
|
+
f"Failed to modify the Git remote url: {remote_name}") \
|
|
357
|
+
from err
|
|
358
|
+
|
|
359
|
+
return origin_url
|
|
360
|
+
|
|
274
361
|
def _git_is_local_branch(self, branch: str) -> bool:
|
|
275
362
|
try:
|
|
276
363
|
stdout, _ = run_simple(["git", "rev-parse", "--symbolic-full-name",
|
|
@@ -290,13 +377,19 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
290
377
|
|
|
291
378
|
def _git_tags(self, branch: str) -> List[str]:
|
|
292
379
|
stdout: List[str] = []
|
|
380
|
+
error = False
|
|
293
381
|
try:
|
|
294
382
|
stdout, _ = run_simple(["git", "rev-parse", "--verify", branch],
|
|
295
383
|
env=self.env,
|
|
296
384
|
cwd=self.git_local_dir)
|
|
297
|
-
|
|
385
|
+
if not stdout:
|
|
386
|
+
error = True
|
|
387
|
+
except subprocess.CalledProcessError:
|
|
388
|
+
error = True
|
|
389
|
+
|
|
390
|
+
if error:
|
|
298
391
|
raise GitReferenceDoesNotExist(
|
|
299
|
-
f"The reference '{branch}' does not exist.")
|
|
392
|
+
f"The reference '{branch}' does not exist.")
|
|
300
393
|
|
|
301
394
|
return stdout
|
|
302
395
|
|
|
@@ -337,6 +430,13 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
337
430
|
|
|
338
431
|
return branch_changed
|
|
339
432
|
|
|
433
|
+
def _git_fetch_origin(self):
|
|
434
|
+
# Fetch
|
|
435
|
+
if not self._git_fetch_origin_done:
|
|
436
|
+
cmd = ["git", "fetch", "origin"]
|
|
437
|
+
self._run(cmd, cwd=str(self.git_local_dir), env=self.env)
|
|
438
|
+
self._git_fetch_origin_done = True
|
|
439
|
+
|
|
340
440
|
def _repo_update_submodules(self):
|
|
341
441
|
# This parameter instructs Git to initiate the update
|
|
342
442
|
# process for submodules:
|
|
@@ -354,21 +454,41 @@ class BatchFetchGit(BatchFetchBase):
|
|
|
354
454
|
cmd = ["git", "submodule", "update", "--recursive"]
|
|
355
455
|
self._run(cmd, cwd=str(self.git_local_dir), env=self.env)
|
|
356
456
|
|
|
357
|
-
def
|
|
358
|
-
|
|
457
|
+
def _repo_fix_remote_origin(self):
|
|
458
|
+
correct_origin_url = self[self.main_key]
|
|
459
|
+
update_remote_origin = False
|
|
460
|
+
|
|
359
461
|
try:
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
462
|
+
origin_url = self._git_get_remote_url()
|
|
463
|
+
if origin_url != correct_origin_url:
|
|
464
|
+
update_remote_origin = True
|
|
465
|
+
except GitRemoteError:
|
|
466
|
+
update_remote_origin = True
|
|
467
|
+
|
|
468
|
+
if update_remote_origin:
|
|
469
|
+
# Update remote
|
|
470
|
+
try:
|
|
471
|
+
self._git_set_remote_url(correct_origin_url)
|
|
472
|
+
except GitRemoteError:
|
|
473
|
+
# TODO handle errors
|
|
474
|
+
return
|
|
366
475
|
|
|
367
|
-
|
|
368
|
-
self.
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
476
|
+
# Get the current branch
|
|
477
|
+
if self.current_branch:
|
|
478
|
+
try:
|
|
479
|
+
self.add_output(
|
|
480
|
+
self.indent_spaces +
|
|
481
|
+
"[INFO] Git fetch origin reason: "
|
|
482
|
+
f"we need to set the upstream "
|
|
483
|
+
f"origin to {self.current_branch}"
|
|
484
|
+
"\n"
|
|
485
|
+
)
|
|
486
|
+
self._git_fetch_origin()
|
|
487
|
+
|
|
488
|
+
cmd = ["git", "branch",
|
|
489
|
+
f"--set-upstream-to=origin/{self.current_branch}"]
|
|
490
|
+
_, _ = run_simple(cmd, env=self.env,
|
|
491
|
+
cwd=self.git_local_dir)
|
|
492
|
+
# TODO: handle errors
|
|
493
|
+
except subprocess.CalledProcessError as err:
|
|
494
|
+
raise BatchFetchError(str(err)) from err
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: batchfetch
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.3
|
|
4
4
|
Summary: Efficiently clone and pull multiple Git repositories.
|
|
5
5
|
Home-page: https://github.com/jamescherti/batchfetch
|
|
6
6
|
Author: James Cherti
|
|
@@ -95,7 +95,7 @@ options:
|
|
|
95
95
|
|
|
96
96
|
## License
|
|
97
97
|
|
|
98
|
-
Copyright (
|
|
98
|
+
Copyright (C) 2024 [James Cherti](https://www.jamescherti.com)
|
|
99
99
|
|
|
100
100
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
101
101
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
#
|
|
3
|
-
# Copyright (
|
|
3
|
+
# Copyright (C) 2024 James Cherti
|
|
4
4
|
# URL: https://github.com/jamescherti/batchfetch
|
|
5
5
|
#
|
|
6
6
|
# This program is free software: you can redistribute it and/or modify it under
|
|
@@ -22,7 +22,7 @@ from setuptools import find_packages, setup
|
|
|
22
22
|
|
|
23
23
|
setup(
|
|
24
24
|
name="batchfetch",
|
|
25
|
-
version="1.1.
|
|
25
|
+
version="1.1.3",
|
|
26
26
|
packages=find_packages(),
|
|
27
27
|
description="Efficiently clone and pull multiple Git repositories.",
|
|
28
28
|
license="GPLv3",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|