diff options
Diffstat (limited to 'subcmds/cherry_pick.py')
-rw-r--r-- | subcmds/cherry_pick.py | 76 |
1 files changed, 50 insertions, 26 deletions
diff --git a/subcmds/cherry_pick.py b/subcmds/cherry_pick.py index 4cfb8c88..7a4dd09e 100644 --- a/subcmds/cherry_pick.py +++ b/subcmds/cherry_pick.py | |||
@@ -16,6 +16,7 @@ import re | |||
16 | import sys | 16 | import sys |
17 | from command import Command | 17 | from command import Command |
18 | from git_command import GitCommand | 18 | from git_command import GitCommand |
19 | from error import GitError | ||
19 | 20 | ||
20 | CHANGE_ID_RE = re.compile(r"^\s*Change-Id: I([0-9a-f]{40})\s*$") | 21 | CHANGE_ID_RE = re.compile(r"^\s*Change-Id: I([0-9a-f]{40})\s*$") |
21 | 22 | ||
@@ -44,18 +45,31 @@ change id will be added. | |||
44 | ["rev-parse", "--verify", reference], | 45 | ["rev-parse", "--verify", reference], |
45 | capture_stdout=True, | 46 | capture_stdout=True, |
46 | capture_stderr=True, | 47 | capture_stderr=True, |
48 | verify_command=True, | ||
47 | ) | 49 | ) |
48 | if p.Wait() != 0: | 50 | try: |
51 | p.Wait() | ||
52 | except GitError: | ||
49 | print(p.stderr, file=sys.stderr) | 53 | print(p.stderr, file=sys.stderr) |
50 | sys.exit(1) | 54 | raise |
55 | |||
51 | sha1 = p.stdout.strip() | 56 | sha1 = p.stdout.strip() |
52 | 57 | ||
53 | p = GitCommand(None, ["cat-file", "commit", sha1], capture_stdout=True) | 58 | p = GitCommand( |
54 | if p.Wait() != 0: | 59 | None, |
60 | ["cat-file", "commit", sha1], | ||
61 | capture_stdout=True, | ||
62 | verify_command=True, | ||
63 | ) | ||
64 | |||
65 | try: | ||
66 | p.Wait() | ||
67 | except GitError: | ||
55 | print( | 68 | print( |
56 | "error: Failed to retrieve old commit message", file=sys.stderr | 69 | "error: Failed to retrieve old commit message", file=sys.stderr |
57 | ) | 70 | ) |
58 | sys.exit(1) | 71 | raise |
72 | |||
59 | old_msg = self._StripHeader(p.stdout) | 73 | old_msg = self._StripHeader(p.stdout) |
60 | 74 | ||
61 | p = GitCommand( | 75 | p = GitCommand( |
@@ -63,37 +77,47 @@ change id will be added. | |||
63 | ["cherry-pick", sha1], | 77 | ["cherry-pick", sha1], |
64 | capture_stdout=True, | 78 | capture_stdout=True, |
65 | capture_stderr=True, | 79 | capture_stderr=True, |
80 | verify_command=True, | ||
66 | ) | 81 | ) |
67 | status = p.Wait() | 82 | |
83 | try: | ||
84 | p.Wait() | ||
85 | except GitError as e: | ||
86 | print(str(e)) | ||
87 | print( | ||
88 | "NOTE: When committing (please see above) and editing the " | ||
89 | "commit message, please remove the old Change-Id-line and " | ||
90 | "add:" | ||
91 | ) | ||
92 | print(self._GetReference(sha1), file=sys.stderr) | ||
93 | print(file=sys.stderr) | ||
94 | raise | ||
68 | 95 | ||
69 | if p.stdout: | 96 | if p.stdout: |
70 | print(p.stdout.strip(), file=sys.stdout) | 97 | print(p.stdout.strip(), file=sys.stdout) |
71 | if p.stderr: | 98 | if p.stderr: |
72 | print(p.stderr.strip(), file=sys.stderr) | 99 | print(p.stderr.strip(), file=sys.stderr) |
73 | 100 | ||
74 | if status == 0: | 101 | # The cherry-pick was applied correctly. We just need to edit |
75 | # The cherry-pick was applied correctly. We just need to edit the | 102 | # the commit message. |
76 | # commit message. | 103 | new_msg = self._Reformat(old_msg, sha1) |
77 | new_msg = self._Reformat(old_msg, sha1) | ||
78 | |||
79 | p = GitCommand( | ||
80 | None, | ||
81 | ["commit", "--amend", "-F", "-"], | ||
82 | input=new_msg, | ||
83 | capture_stdout=True, | ||
84 | capture_stderr=True, | ||
85 | ) | ||
86 | if p.Wait() != 0: | ||
87 | print("error: Failed to update commit message", file=sys.stderr) | ||
88 | sys.exit(1) | ||
89 | 104 | ||
90 | else: | 105 | p = GitCommand( |
106 | None, | ||
107 | ["commit", "--amend", "-F", "-"], | ||
108 | input=new_msg, | ||
109 | capture_stdout=True, | ||
110 | capture_stderr=True, | ||
111 | verify_command=True, | ||
112 | ) | ||
113 | try: | ||
114 | p.Wait() | ||
115 | except GitError: | ||
91 | print( | 116 | print( |
92 | "NOTE: When committing (please see above) and editing the " | 117 | "error: Failed to update commit message", |
93 | "commit message, please remove the old Change-Id-line and add:" | 118 | file=sys.stderr, |
94 | ) | 119 | ) |
95 | print(self._GetReference(sha1), file=sys.stderr) | 120 | raise |
96 | print(file=sys.stderr) | ||
97 | 121 | ||
98 | def _IsChangeId(self, line): | 122 | def _IsChangeId(self, line): |
99 | return CHANGE_ID_RE.match(line) | 123 | return CHANGE_ID_RE.match(line) |