Skip to content

Commit 32504e4

Browse files
committed
[CCP] Resolve the full SHA1 from the user-provided --sha argument
This ensures the CIQ commit message header always uses the full SHA1. Fixes: #7
1 parent 7e72b2b commit 32504e4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ciq-cherry-pick.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
if __name__ == '__main__':
1212
print("CIQ custom cherry picker")
1313
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
14-
parser.add_argument('--sha', help='Taget SHA1 to cherry-pick')
14+
parser.add_argument('--sha', help='Target SHA1 to cherry-pick')
1515
parser.add_argument('--ticket', help='Ticket associated to cherry-pick work')
1616
parser.add_argument('--ciq-tag', help="Tags for commit message <feature><-optional modifier> <identifier>.\n"
1717
"example: cve CVE-2022-45884 - A patch for a CVE Fix.\n"
@@ -20,6 +20,16 @@
2020
"Multiple tags are separated with a comma. ex: cve CVE-1974-0001, cve CVE-1974-0002\n")
2121
args = parser.parse_args()
2222

23+
# Expand the provided SHA1 to the full SHA1 in case it's either abbreviated or an expression
24+
git_sha_res = subprocess.run(['git', 'show', '--pretty=%H', '-s', args.sha], stdout=subprocess.PIPE)
25+
if git_sha_res.returncode != 0:
26+
print(f"[FAILED] git show --pretty=%H -s {args.sha}")
27+
print("Subprocess Call:")
28+
print(git_sha_res)
29+
print("")
30+
else:
31+
args.sha = git_sha_res.stdout.decode('utf-8').strip()
32+
2333
tags = []
2434
if args.ciq_tag is not None:
2535
tags = args.ciq_tag.split(',')

0 commit comments

Comments
 (0)