diff --git a/python/servo/command_base.py b/python/servo/command_base.py index e3942ef66e0..db9f550e61d 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -734,9 +734,28 @@ install them, let us know by filing a bug!") git_info = [] if os.path.isdir('.git') and is_build: - git_sha = subprocess.check_output([ - 'git', 'rev-parse', '--short', 'HEAD' + # Get the subject of the commit + git_commit_subject = subprocess.check_output([ + 'git', 'show', '-s', '--format=%s', 'HEAD' ]).strip() + + git_sha = None + # Check if it's a bundle commit + if git_commit_subject.startswith(b"Shallow version of commit "): + # This is a bundle commit + # Get the SHA-1 from the bundle subject: "Shallow version of commit {sha1}" + git_sha = git_commit_subject.split(b' ')[-1].strip() + # Shorten hash + # NOTE: Partially verifies the hash, but it will still pass if it's, e.g., a tree + git_sha = subprocess.check_output([ + 'git', 'rev-parse', '--short', git_sha + ]) + else: + # This is a regular commit + git_sha = subprocess.check_output([ + 'git', 'rev-parse', '--short', 'HEAD' + ]).strip() + git_is_dirty = bool(subprocess.check_output([ 'git', 'status', '--porcelain' ]).strip())