batchfetch 1.2.8__tar.gz → 1.2.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: batchfetch
3
- Version: 1.2.8
3
+ Version: 1.2.9
4
4
  Summary: Efficiently clone and pull multiple Git repositories.
5
5
  Home-page: https://github.com/jamescherti/batchfetch
6
6
  Author: James Cherti
@@ -59,7 +59,6 @@ class BatchFetchGit(TaskBatchFetch):
59
59
  # Local options
60
60
  self.main_key: str,
61
61
  Optional("revision"): str,
62
- Optional("reference"): str,
63
62
 
64
63
  # Same as global options
65
64
  Optional("git_clone_args"): [str],
@@ -104,11 +103,6 @@ class BatchFetchGit(TaskBatchFetch):
104
103
  """Clone or update a Git repository."""
105
104
  super().update()
106
105
 
107
- # Backward compatibility
108
- if "reference" in self._item_values \
109
- and "revision" not in self._item_values:
110
- self._item_values["revision"] = "reference"
111
-
112
106
  is_clone = False
113
107
  if not self.git_local_dir.exists():
114
108
  is_clone = True
@@ -141,7 +135,18 @@ class BatchFetchGit(TaskBatchFetch):
141
135
  self._repo_fix_remote_origin()
142
136
  self._run_pre_exec(cwd=self.git_local_dir)
143
137
 
144
- # self._repo_reset()
138
+ if not self["revision"]:
139
+ self.values["revision"] = self._run_get_firstline(
140
+ "git symbolic-ref refs/remotes/origin/HEAD"
141
+ ).split("/")[-1]
142
+ if not self["revision"]:
143
+ raise BatchFetchError(
144
+ "Unable to determine the default origin branch"
145
+ )
146
+
147
+ self.add_output(self.indent_spaces +
148
+ f"[INFO] Update revision to: '" +
149
+ self["revision"] + "'\n")
145
150
 
146
151
  git_fetch_done = self._repo_fetch()
147
152
 
@@ -152,9 +157,6 @@ class BatchFetchGit(TaskBatchFetch):
152
157
  if git_fetch_done:
153
158
  git_merge_done = self._git_merge()
154
159
 
155
- # if (git_fetch_done and git_merge_done) or git_branch_changed:
156
- # self._repo_update_submodules()
157
-
158
160
  if self.get_changed():
159
161
  self._run_post_exec(cwd=self.git_local_dir)
160
162
  except BatchFetchError as err:
@@ -173,6 +175,13 @@ class BatchFetchGit(TaskBatchFetch):
173
175
 
174
176
  return self.values
175
177
 
178
+ def _run_get_firstline(self, *args, **kwargs):
179
+ stdout, _ = self._run(*args, **kwargs)
180
+ try:
181
+ return stdout[0]
182
+ except IndexError:
183
+ return ""
184
+
176
185
  def _run(self, cmd: Union[List[str], str],
177
186
  cwd: Union[None, os.PathLike] = None,
178
187
  env: Union[None, dict] = None,
@@ -251,50 +260,39 @@ class BatchFetchGit(TaskBatchFetch):
251
260
  self._run(cmd, cwd=".")
252
261
  self.set_changed(True)
253
262
 
254
- def _repo_reset(self):
255
- # Remove local changes
256
- cmd = ["git", "reset", "--hard", "HEAD"]
257
- self._run(cmd, cwd=".")
258
-
259
263
  def _repo_fetch(self):
260
264
  # Merge
261
265
  do_git_fetch = self["git_pull"]
262
- if not self["revision"]:
266
+ do_git_fetch = False
267
+ commit_ref = None
268
+
269
+ try:
270
+ # Check if the revision such as
271
+ stdout, _ = self._run(["git", "cat-file", "-e",
272
+ self["revision"]])
273
+ except subprocess.CalledProcessError:
263
274
  do_git_fetch = True
264
- self.add_output(self.indent_spaces
265
- + "[INFO] Git fetch origin reason: "
266
- + "No 'revision:' specified\n")
267
- else:
268
- do_git_fetch = False
269
- commit_ref = None
275
+ self.add_output(
276
+ self.indent_spaces
277
+ + "[INFO] Git fetch origin reason: "
278
+ + f"The revision does not exist: {self['revision']}"
279
+ + "\n")
270
280
 
281
+ # The revision exists, but if it a branch, git pull anyway
282
+ if not do_git_fetch:
271
283
  try:
272
- # Check if the revision such as
273
- stdout, _ = self._run(["git", "cat-file", "-e",
274
- self["revision"]])
275
- except subprocess.CalledProcessError:
276
- do_git_fetch = True
284
+ # Check if the branch is a tag or a branch
285
+ cmd = ["git", "show-ref", "--verify", "--quiet",
286
+ f"refs/heads/{self['revision']}"]
287
+ self._run(cmd)
277
288
  self.add_output(
278
289
  self.indent_spaces
279
290
  + "[INFO] Git fetch origin reason: "
280
- + f"The revision does not exist: {self['revision']}"
291
+ + f"{self['revision']} is a branch, not a tag"
281
292
  + "\n")
282
-
283
- # The revision exists, but if it a branch, git pull anyway
284
- if not do_git_fetch:
285
- try:
286
- # Check if the branch is a tag or a branch
287
- cmd = ["git", "show-ref", "--verify", "--quiet",
288
- f"refs/heads/{self['revision']}"]
289
- self._run(cmd)
290
- self.add_output(
291
- self.indent_spaces
292
- + "[INFO] Git fetch origin reason: "
293
- + f"{self['revision']} is a branch, not a tag"
294
- + "\n")
295
- do_git_fetch = True
296
- except subprocess.CalledProcessError:
297
- pass
293
+ do_git_fetch = True
294
+ except subprocess.CalledProcessError:
295
+ pass
298
296
 
299
297
  if not do_git_fetch:
300
298
  self.add_output(self.indent_spaces + "[INFO] git fetch ignored\n")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: batchfetch
3
- Version: 1.2.8
3
+ Version: 1.2.9
4
4
  Summary: Efficiently clone and pull multiple Git repositories.
5
5
  Home-page: https://github.com/jamescherti/batchfetch
6
6
  Author: James Cherti
@@ -22,7 +22,7 @@ from setuptools import find_packages, setup
22
22
 
23
23
  setup(
24
24
  name="batchfetch",
25
- version="1.2.8",
25
+ version="1.2.9",
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