From d82d18933d37117cdceab71d94675afc0a4ebc04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Lehmann?= Date: Wed, 13 Aug 2025 14:20:47 +0200 Subject: [PATCH] import_srpm: make most cli parameters optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the repository path defaults to . the local branch is used if not provided on the command line Signed-off-by: Gaƫtan Lehmann --- scripts/import_srpm.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/scripts/import_srpm.py b/scripts/import_srpm.py index 34da7aaa..37824c40 100755 --- a/scripts/import_srpm.py +++ b/scripts/import_srpm.py @@ -11,9 +11,9 @@ def call_process(args): def main(): parser = argparse.ArgumentParser(description='Imports the contents of a source RPM into a git repository') parser.add_argument('source_rpm', help='local path to source RPM') - parser.add_argument('repository', help='local path to the repository') - parser.add_argument('parent_branch', help='git parent branch from which to branch') - parser.add_argument('branch', help='destination branch') + parser.add_argument('repository', default='./', nargs='?', help='local path to the repository') + parser.add_argument('parent_branch', nargs='?', help='git parent branch from which to branch') + parser.add_argument('branch', nargs='?', help='destination branch') parser.add_argument('tag', nargs='?', help='tag') parser.add_argument('-v', '--verbose', action='count', default=0) parser.add_argument('-p', '--push', action='store_true', help='pull and push') @@ -56,8 +56,14 @@ def main(): if args.push: call_process(['git', 'fetch']) - call_process(['git', 'checkout', args.parent_branch]) - if args.push: + if args.parent_branch: + call_process(['git', 'checkout', args.parent_branch]) + if ( + args.push + # only pull if the branch is already tracked + and subprocess.call(['git', 'rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 + ): call_process(['git', 'pull']) print(" removing everything from SOURCES and SPECS...") @@ -91,10 +97,11 @@ def main(): open(os.path.join('SOURCES', "%s.deleted-by-XCP-ng.txt" % f), 'w').write(deletemsg) deleted.append(f) - if subprocess.call(['git', 'rev-parse', '--quiet', '--verify', args.branch]) != 0: - call_process(['git', 'checkout', '-b', args.branch]) - else: - call_process(['git', 'checkout', args.branch]) + if args.branch: + if subprocess.call(['git', 'rev-parse', '--quiet', '--verify', args.branch]) != 0: + call_process(['git', 'checkout', '-b', args.branch]) + else: + call_process(['git', 'checkout', args.branch]) call_process(['git', 'add', '--all']) print(" committing...") @@ -116,20 +123,21 @@ def main(): if args.tag is not None: call_process(['git', 'tag', args.tag]) + branch = args.branch or subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode().strip() # push to remote if args.push: - call_process(['git', 'push', '--set-upstream', 'origin', args.branch]) + call_process(['git', 'push', '--set-upstream', 'origin', branch]) if args.tag is not None: call_process(['git', 'push', 'origin', args.tag]) - print(" switching to master before leaving...") - - call_process(['git', 'checkout', 'master']) + if args.branch: + print(" switching to master before leaving...") + call_process(['git', 'checkout', 'master']) # merge to master if needed if args.push and args.master: print(" merging to master...") - call_process(['git', 'push', 'origin', '%s:master' % args.branch]) + call_process(['git', 'push', 'origin', '%s:master' % branch]) call_process(['git', 'pull'])