Skip to content

Commit 684831e

Browse files
authored
T289718: Extend zodbsync to print commit range (#146)
1 parent 6082175 commit 684831e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

perfact/zodbsync/subcommand.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def gitcmd_run(self, *args):
6868
subprocess.check_call(self.gitcmd(*args))
6969

7070
def gitcmd_try(self, *args):
71-
'''Wrapper to run a git command, ignoring return code.'''
72-
subprocess.call(self.gitcmd(*args))
71+
'''Wrapper to run a git command, returning return code.'''
72+
return subprocess.call(self.gitcmd(*args))
7373

7474
def gitcmd_output(self, *args):
7575
'''Wrapper to run a git command and return the output.'''
@@ -300,6 +300,23 @@ def wrapper(self, *args, **kwargs):
300300
)
301301
raise
302302

303+
if not self.args.dry_run:
304+
is_ancestor = (
305+
self.gitcmd_try(
306+
"merge-base", "--is-ancestor", self.orig_commit, "HEAD"
307+
) == 0
308+
)
309+
if is_ancestor:
310+
merge_commits = self.gitcmd_output(
311+
"log", "--oneline", "--min-parents=2",
312+
f"{self.orig_commit}..HEAD"
313+
).strip()
314+
if not merge_commits:
315+
head_commit = self.gitcmd_output(
316+
"rev-parse", "HEAD"
317+
).strip()
318+
self.logger.info(f"{self.orig_commit}..{head_commit}")
319+
303320
return wrapper
304321

305322
def create_file(self, file_path, content, binary=False):

0 commit comments

Comments
 (0)