From e40c2b2ee278c413fc900a60cfb558244fa4a662 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 26 Apr 2018 16:15:44 -0400 Subject: [PATCH] replace --project-dir argument with --short-name arg Signed-off-by: Doug Hellmann --- README.rst | 41 +++++++++++++++++++++++++++++++++++++++++ git_nit/cmd.py | 39 ++++++++++++++------------------------- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/README.rst b/README.rst index f50b1cc..fc49b3f 100644 --- a/README.rst +++ b/README.rst @@ -102,6 +102,47 @@ draft older than the most recent patchset. Patch ready in ./release-tools-564559-finish-moving-announce.sh-to-releases-repo-by-deleting-it +Use the ``--short-name`` option to change the default behavior and +name the output directory after the repository without including the +patchset number and subject. + +:: + + $ git-nit -s https://review.openstack.org/#/c/564559/1/ + Cloning openstack-infra/release-tools into release-tools + git clone git://git.openstack.org/openstack-infra/release-tools release-tools + Cloning into 'release-tools'... + remote: Counting objects: 2320, done. + remote: Compressing objects: 100% (989/989), done. + remote: Total 2320 (delta 1493), reused 2115 (delta 1318) + Receiving objects: 100% (2320/2320), 2.73 MiB | 2.24 MiB/s, done. + Resolving deltas: 100% (1493/1493), done. + Checking connectivity... done. + + Configuring git-review + git review -s + Creating a git remote called 'gerrit' that maps to: + ssh://doug-hellmann@review.openstack.org:29418/openstack-infra/release-tools.git + + Downloading https://review.openstack.org/#/c/564559/1/ + git review -d 564559,1 + Downloading refs/changes/59/564559/1 from gerrit + Switched to branch "review/doug_hellmann/announce-script-fixes-patch1" + + Updating all remotes + git remote update + Fetching origin + remote: Counting objects: 1501, done. + remote: Compressing objects: 100% (659/659), done. + remote: Total 1501 (delta 842), reused 1501 (delta 842) + Receiving objects: 100% (1501/1501), 218.28 KiB | 0 bytes/s, done. + Resolving deltas: 100% (842/842), done. + From git://git.openstack.org/openstack-infra/release-tools + * [new ref] refs/notes/review -> refs/notes/review + Fetching gerrit + + Patch ready in release-tools + Resources ========= diff --git a/git_nit/cmd.py b/git_nit/cmd.py index 7eb78fa..e35eec9 100644 --- a/git_nit/cmd.py +++ b/git_nit/cmd.py @@ -89,11 +89,10 @@ def main(): version=get_version(), ) parser.add_argument( - '--project-dir', - default=os.environ.get('PROJECT_DIR', '.'), - help=( - 'parent directory for creating a new project, ' - 'defaults to $PROJECT_DIR or "."'), + '--short-names', '-s', + action='store_true', + default=False, + help='use the short repo name without the subject', ) parser.add_argument( 'review', @@ -113,16 +112,10 @@ def main(): for old, new in [(' ', '-'), (':', ''), ("'", ''), ('"', '')]: subject = subject.replace(old, new) - clone_to = '{}-{}-{}'.format(short_repo, review, subject) - print(clone_to) - - output_dir = os.path.join(args.project_dir, clone_to) - if os.path.exists(output_dir): - sys.exit('{} already exists'.format(output_dir)) - - if not os.path.exists(args.project_dir): - print('Creating project directory {}'.format(args.project_dir)) - os.makedirs(args.project_dir) + if args.short_names: + clone_to = short_repo + else: + clone_to = '{}-{}-{}'.format(short_repo, review, subject) git_cmd = [ 'git', @@ -130,13 +123,9 @@ def main(): 'git://git.openstack.org/{}'.format(repo), clone_to, ] - if args.project_dir != '.': - cwd = args.project_dir - else: - cwd = None - print('Cloning {} into {}'.format(repo, output_dir)) + print('Cloning {} into {}'.format(repo, clone_to)) print(' '.join(git_cmd)) - subprocess.run(git_cmd, cwd=cwd, check=True) + subprocess.run(git_cmd, check=True) git_cmd = [ 'git', @@ -145,7 +134,7 @@ def main(): ] print('\nConfiguring git-review') print(' '.join(git_cmd)) - subprocess.run(git_cmd, cwd=output_dir, check=True) + subprocess.run(git_cmd, cwd=clone_to, check=True) git_cmd = [ 'git', @@ -159,7 +148,7 @@ def main(): git_cmd.append(target) print('\nDownloading {}'.format(args.review)) print(' '.join(git_cmd)) - subprocess.run(git_cmd, cwd=output_dir, check=True) + subprocess.run(git_cmd, cwd=clone_to, check=True) git_cmd = [ 'git', @@ -168,9 +157,9 @@ def main(): ] print('\nUpdating all remotes') print(' '.join(git_cmd)) - subprocess.run(git_cmd, cwd=output_dir, check=True) + subprocess.run(git_cmd, cwd=clone_to, check=True) - print('\nPatch ready in {}'.format(output_dir)) + print('\nPatch ready in {}'.format(clone_to)) if __name__ == '__main__':