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

@ -30,12 +30,10 @@ tasks:
- '--login' - '--login'
- '-e' - '-e'
- '-c' - '-c'
# A depth of 25 is used to work around `git show` ignoring
# any provided format with a depth of 1.
- >- - >-
git init repo && git init repo &&
cd repo && cd repo &&
git fetch --depth 25 "$GIT_URL" "$GIT_REF" && git fetch --depth 1 "$GIT_URL" "$GIT_REF" &&
git reset --hard "$GIT_SHA" && git reset --hard "$GIT_SHA" &&
python3 etc/taskcluster/decision_task.py python3 etc/taskcluster/decision_task.py
in: in:

View file

@ -64,11 +64,17 @@ class Config:
# the merge parents rather that the actual sha of the merge commit. This ensures that tasks # 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 # 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. # 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"]) raw_commit = subprocess.check_output(["git", "cat-file", "commit", "HEAD"])
merge_parents = merge_parents_output.decode("utf8").strip().split(' ') parent_commits = [
self._task_id = self.git_sha value.decode("utf8")
if len(merge_parents) > 1: for line in raw_commit.split(b"\n")
self._task_id = '-'.join(merge_parents) 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 return self._task_id
def git_sha_is_current_head(self): def git_sha_is_current_head(self):