fromupstream.py: Reset head as late as possible with --replace
If the --replace argument is provided, reset the git head only after
all other possible operations have completed, right before applying the
replacement patch. Otherwise the top patch gets lost if there is an error
in one of the earlier operations.
BUG=None
TEST=Run command with bad --replace option
Change-Id: Iacc6c8793438e506d5db5c456f4ea68a230c9b4c
Signed-off-by: Guenter Roeck <groeck@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1150730
Reviewed-by: Brian Norris <briannorris@chromium.org>
diff --git a/contrib/fromupstream.py b/contrib/fromupstream.py
index 9442db2..9df74c9 100755
--- a/contrib/fromupstream.py
+++ b/contrib/fromupstream.py
@@ -159,7 +159,6 @@
old_commit_message,
re.MULTILINE))
# TODO: deal with multiline BUG/TEST better
- subprocess.call(['git', 'reset', '--hard', 'HEAD~1'])
while len(args['locations']) > 0:
location = args['locations'].pop(0)
@@ -196,6 +195,10 @@
if not s:
sys.stderr.write('Error: No patch content found\n')
sys.exit(1)
+
+ if args['replace']:
+ subprocess.call(['git', 'reset', '--hard', 'HEAD~1'])
+
git_am = subprocess.Popen(['git', 'am', '-3'], stdin=subprocess.PIPE)
git_am.communicate(s)
ret = git_am.returncode
@@ -225,6 +228,9 @@
if args['tag'] is None:
args['tag'] = 'UPSTREAM: '
+ if args['replace']:
+ subprocess.call(['git', 'reset', '--hard', 'HEAD~1'])
+
ret = subprocess.call(['git', 'cherry-pick', commit])
elif fromgit_match is not None:
remote = fromgit_match.group(1)
@@ -253,6 +259,9 @@
if args['tag'] is None:
args['tag'] = 'FROMGIT: '
+ if args['replace']:
+ subprocess.call(['git', 'reset', '--hard', 'HEAD~1'])
+
ret = subprocess.call(['git', 'cherry-pick', commit])
else:
sys.stderr.write('Don\'t know what "%s" means.\n' % location)