fromupstream.py: -t and -b are only mandatory w/o --replace
If fromupstream.py is executed with --replace argument, it does not make
sense to mandate --bug and --test arguments since those would override
existing BUG and TEST statements.
The code specifically retains existing behavior, which explicitly
permits empty BUG= and TEST= lines.
Change-Id: Ibecef3fb06ebf0e66d49ceb7d4811f28fc047be0
Signed-off-by: Guenter Roeck <groeck@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1150609
Reviewed-by: Brian Norris <briannorris@chromium.org>
diff --git a/contrib/fromupstream.py b/contrib/fromupstream.py
index 9df74c9..0ea3225 100755
--- a/contrib/fromupstream.py
+++ b/contrib/fromupstream.py
@@ -113,9 +113,9 @@
parser = argparse.ArgumentParser()
parser.add_argument('--bug', '-b',
- type=str, required=True, help='BUG= line')
+ type=str, help='BUG= line')
parser.add_argument('--test', '-t',
- type=str, required=True, help='TEST= line')
+ type=str, help='TEST= line')
parser.add_argument('--changeid', '-c',
help='Overrides the gerrit generated Change-Id line')
@@ -150,16 +150,21 @@
).strip('\n')
args['changeid'] = re.findall('Change-Id: (.*)$',
old_commit_message, re.MULTILINE)[0]
- if args['bug'] == parser.get_default('bug'):
+ if args['bug'] == parser.get_default('bug') and \
+ re.findall('BUG=(.*)$', old_commit_message, re.MULTILINE):
args['bug'] = '\nBUG='.join(re.findall('BUG=(.*)$',
old_commit_message,
re.MULTILINE))
- if args['test'] == parser.get_default('test'):
+ if args['test'] == parser.get_default('test') and \
+ re.findall('TEST=(.*)$', old_commit_message, re.MULTILINE):
args['test'] = '\nTEST='.join(re.findall('TEST=(.*)$',
old_commit_message,
re.MULTILINE))
# TODO: deal with multiline BUG/TEST better
+ if args['bug'] is None or args['test'] is None:
+ parser.error('BUG=/TEST= lines are required; --replace can help automate, or set via --bug/--test')
+
while len(args['locations']) > 0:
location = args['locations'].pop(0)