replace --project-dir argument with --short-name arg

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-04-26 16:15:44 -04:00
parent 39ed06cf55
commit e40c2b2ee2
2 changed files with 55 additions and 25 deletions

View File

@ -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
=========

View File

@ -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__':