|
1 | 1 | import argparse |
2 | 2 | import os |
3 | 3 | import subprocess |
| 4 | + |
4 | 5 | import git |
5 | | -from ciq_helpers import CIQ_cherry_pick_commit_standardization |
6 | | -from ciq_helpers import CIQ_original_commit_author_to_tag_string |
| 6 | + |
| 7 | +from ciq_helpers import CIQ_cherry_pick_commit_standardization, CIQ_original_commit_author_to_tag_string |
| 8 | + |
7 | 9 | # from ciq_helpers import * |
8 | 10 |
|
9 | | -MERGE_MSG = git.Repo(os.getcwd()).git_dir + '/MERGE_MSG' |
| 11 | +MERGE_MSG = git.Repo(os.getcwd()).git_dir + "/MERGE_MSG" |
10 | 12 |
|
11 | | -if __name__ == '__main__': |
| 13 | +if __name__ == "__main__": |
12 | 14 | print("CIQ custom cherry picker") |
13 | 15 | parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) |
14 | | - parser.add_argument('--sha', help='Target SHA1 to cherry-pick') |
15 | | - parser.add_argument('--ticket', help='Ticket associated to cherry-pick work, comma separated list is supported.') |
16 | | - parser.add_argument('--ciq-tag', help="Tags for commit message <feature><-optional modifier> <identifier>.\n" |
17 | | - "example: cve CVE-2022-45884 - A patch for a CVE Fix.\n" |
18 | | - " cve-bf CVE-1974-0001 - A bug fix for a CVE currently being patched\n" |
19 | | - " cve-pre CVE-1974-0001 - A pre-condition or dependency needed for the CVE\n" |
20 | | - "Multiple tags are separated with a comma. ex: cve CVE-1974-0001, cve CVE-1974-0002\n") |
| 16 | + parser.add_argument("--sha", help="Target SHA1 to cherry-pick") |
| 17 | + parser.add_argument("--ticket", help="Ticket associated to cherry-pick work, comma separated list is supported.") |
| 18 | + parser.add_argument( |
| 19 | + "--ciq-tag", |
| 20 | + help="Tags for commit message <feature><-optional modifier> <identifier>.\n" |
| 21 | + "example: cve CVE-2022-45884 - A patch for a CVE Fix.\n" |
| 22 | + " cve-bf CVE-1974-0001 - A bug fix for a CVE currently being patched\n" |
| 23 | + " cve-pre CVE-1974-0001 - A pre-condition or dependency needed for the CVE\n" |
| 24 | + "Multiple tags are separated with a comma. ex: cve CVE-1974-0001, cve CVE-1974-0002\n", |
| 25 | + ) |
21 | 26 | args = parser.parse_args() |
22 | 27 |
|
23 | 28 | # 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) |
| 29 | + git_sha_res = subprocess.run(["git", "show", "--pretty=%H", "-s", args.sha], stdout=subprocess.PIPE) |
25 | 30 | if git_sha_res.returncode != 0: |
26 | 31 | print(f"[FAILED] git show --pretty=%H -s {args.sha}") |
27 | 32 | print("Subprocess Call:") |
28 | 33 | print(git_sha_res) |
29 | 34 | print("") |
30 | 35 | else: |
31 | | - args.sha = git_sha_res.stdout.decode('utf-8').strip() |
| 36 | + args.sha = git_sha_res.stdout.decode("utf-8").strip() |
32 | 37 |
|
33 | 38 | tags = [] |
34 | 39 | if args.ciq_tag is not None: |
35 | | - tags = args.ciq_tag.split(',') |
| 40 | + tags = args.ciq_tag.split(",") |
36 | 41 |
|
37 | 42 | author = CIQ_original_commit_author_to_tag_string(repo_path=os.getcwd(), sha=args.sha) |
38 | 43 | if author is None: |
39 | 44 | exit(1) |
40 | 45 |
|
41 | | - git_res = subprocess.run(['git', 'cherry-pick', '-nsx', args.sha]) |
| 46 | + git_res = subprocess.run(["git", "cherry-pick", "-nsx", args.sha]) |
42 | 47 | if git_res.returncode != 0: |
43 | 48 | print(f"[FAILED] git cherry-pick -nsx {args.sha}") |
44 | 49 | print(" Manually resolve conflict and include `upstream-diff` tag in commit message") |
|
47 | 52 | print("") |
48 | 53 |
|
49 | 54 | print(os.getcwd()) |
50 | | - subprocess.run(['cp', MERGE_MSG, f'{MERGE_MSG}.bak']) |
| 55 | + subprocess.run(["cp", MERGE_MSG, f"{MERGE_MSG}.bak"]) |
51 | 56 |
|
52 | 57 | tags.append(author) |
53 | 58 |
|
|
58 | 63 |
|
59 | 64 | print(f"Cherry Pick New Message for {args.sha}") |
60 | 65 | for line in new_msg: |
61 | | - print(line.strip('\n')) |
| 66 | + print(line.strip("\n")) |
62 | 67 | print(f"\n Original Message located here: {MERGE_MSG}.bak") |
63 | 68 |
|
64 | 69 | with open(MERGE_MSG, "w") as file: |
65 | 70 | file.writelines(new_msg) |
66 | 71 |
|
67 | 72 | if git_res.returncode == 0: |
68 | | - subprocess.run(['git', 'commit', '-F', MERGE_MSG]) |
| 73 | + subprocess.run(["git", "commit", "-F", MERGE_MSG]) |
0 commit comments