git show --pretty=%P sometimes prints a diff. Use git cat-file instead.

This commit is contained in:
Simon Sapin 2019-05-23 18:50:07 +02:00 committed by Josh Matthews
parent 0ed6cdbb42
commit 3d0be552d8
2 changed files with 12 additions and 8 deletions

View file

@ -64,11 +64,17 @@ class Config:
# the merge parents rather that the actual sha of the merge commit. This ensures that tasks
# can be reused if the tree is in an identical state. Otherwise, if the head commit is
# not a merge, we can rely on the head commit sha for that purpose.
merge_parents_output = subprocess.check_output(["git", "show", "--format=%P", "HEAD"])
merge_parents = merge_parents_output.decode("utf8").strip().split(' ')
self._task_id = self.git_sha
if len(merge_parents) > 1:
self._task_id = '-'.join(merge_parents)
raw_commit = subprocess.check_output(["git", "cat-file", "commit", "HEAD"])
parent_commits = [
value.decode("utf8")
for line in raw_commit.split(b"\n")
for key, _, value in [line.partition(b" ")]
if key == b"parent"
]
if len(parent_commits) > 1:
self._task_id = "-".join(parent_commits) # pragma: no cover
else:
self._task_id = self.git_sha # pragma: no cover
return self._task_id
def git_sha_is_current_head(self):