Browse Source

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

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 11 months ago
parent
commit
e40c2b2ee2
2 changed files with 55 additions and 25 deletions
  1. 41
    0
      README.rst
  2. 14
    25
      git_nit/cmd.py

+ 41
- 0
README.rst View File

@@ -102,6 +102,47 @@ draft older than the most recent patchset.
102 102
 
103 103
   Patch ready in ./release-tools-564559-finish-moving-announce.sh-to-releases-repo-by-deleting-it
104 104
 
105
+Use the ``--short-name`` option to change the default behavior and
106
+name the output directory after the repository without including the
107
+patchset number and subject.
108
+
109
+::
110
+
111
+  $ git-nit -s  https://review.openstack.org/#/c/564559/1/
112
+  Cloning openstack-infra/release-tools into release-tools
113
+  git clone git://git.openstack.org/openstack-infra/release-tools release-tools
114
+  Cloning into 'release-tools'...
115
+  remote: Counting objects: 2320, done.
116
+  remote: Compressing objects: 100% (989/989), done.
117
+  remote: Total 2320 (delta 1493), reused 2115 (delta 1318)
118
+  Receiving objects: 100% (2320/2320), 2.73 MiB | 2.24 MiB/s, done.
119
+  Resolving deltas: 100% (1493/1493), done.
120
+  Checking connectivity... done.
121
+
122
+  Configuring git-review
123
+  git review -s
124
+  Creating a git remote called 'gerrit' that maps to:
125
+     ssh://doug-hellmann@review.openstack.org:29418/openstack-infra/release-tools.git
126
+
127
+  Downloading https://review.openstack.org/#/c/564559/1/
128
+  git review -d 564559,1
129
+  Downloading refs/changes/59/564559/1 from gerrit
130
+  Switched to branch "review/doug_hellmann/announce-script-fixes-patch1"
131
+
132
+  Updating all remotes
133
+  git remote update
134
+  Fetching origin
135
+  remote: Counting objects: 1501, done.
136
+  remote: Compressing objects: 100% (659/659), done.
137
+  remote: Total 1501 (delta 842), reused 1501 (delta 842)
138
+  Receiving objects: 100% (1501/1501), 218.28 KiB | 0 bytes/s, done.
139
+  Resolving deltas: 100% (842/842), done.
140
+  From git://git.openstack.org/openstack-infra/release-tools
141
+   * [new ref]         refs/notes/review -> refs/notes/review
142
+  Fetching gerrit
143
+
144
+  Patch ready in release-tools
145
+
105 146
 Resources
106 147
 =========
107 148
 

+ 14
- 25
git_nit/cmd.py View File

@@ -89,11 +89,10 @@ def main():
89 89
         version=get_version(),
90 90
     )
91 91
     parser.add_argument(
92
-        '--project-dir',
93
-        default=os.environ.get('PROJECT_DIR', '.'),
94
-        help=(
95
-            'parent directory for creating a new project, '
96
-            'defaults to $PROJECT_DIR or "."'),
92
+        '--short-names', '-s',
93
+        action='store_true',
94
+        default=False,
95
+        help='use the short repo name without the subject',
97 96
     )
98 97
     parser.add_argument(
99 98
         'review',
@@ -113,16 +112,10 @@ def main():
113 112
     for old, new in [(' ', '-'), (':', ''), ("'", ''), ('"', '')]:
114 113
         subject = subject.replace(old, new)
115 114
 
116
-    clone_to = '{}-{}-{}'.format(short_repo, review, subject)
117
-    print(clone_to)
118
-
119
-    output_dir = os.path.join(args.project_dir, clone_to)
120
-    if os.path.exists(output_dir):
121
-        sys.exit('{} already exists'.format(output_dir))
122
-
123
-    if not os.path.exists(args.project_dir):
124
-        print('Creating project directory {}'.format(args.project_dir))
125
-        os.makedirs(args.project_dir)
115
+    if args.short_names:
116
+        clone_to = short_repo
117
+    else:
118
+        clone_to = '{}-{}-{}'.format(short_repo, review, subject)
126 119
 
127 120
     git_cmd = [
128 121
         'git',
@@ -130,13 +123,9 @@ def main():
130 123
         'git://git.openstack.org/{}'.format(repo),
131 124
         clone_to,
132 125
     ]
133
-    if args.project_dir != '.':
134
-        cwd = args.project_dir
135
-    else:
136
-        cwd = None
137
-    print('Cloning {} into {}'.format(repo, output_dir))
126
+    print('Cloning {} into {}'.format(repo, clone_to))
138 127
     print(' '.join(git_cmd))
139
-    subprocess.run(git_cmd, cwd=cwd, check=True)
128
+    subprocess.run(git_cmd, check=True)
140 129
 
141 130
     git_cmd = [
142 131
         'git',
@@ -145,7 +134,7 @@ def main():
145 134
     ]
146 135
     print('\nConfiguring git-review')
147 136
     print(' '.join(git_cmd))
148
-    subprocess.run(git_cmd, cwd=output_dir, check=True)
137
+    subprocess.run(git_cmd, cwd=clone_to, check=True)
149 138
 
150 139
     git_cmd = [
151 140
         'git',
@@ -159,7 +148,7 @@ def main():
159 148
     git_cmd.append(target)
160 149
     print('\nDownloading {}'.format(args.review))
161 150
     print(' '.join(git_cmd))
162
-    subprocess.run(git_cmd, cwd=output_dir, check=True)
151
+    subprocess.run(git_cmd, cwd=clone_to, check=True)
163 152
 
164 153
     git_cmd = [
165 154
         'git',
@@ -168,9 +157,9 @@ def main():
168 157
     ]
169 158
     print('\nUpdating all remotes')
170 159
     print(' '.join(git_cmd))
171
-    subprocess.run(git_cmd, cwd=output_dir, check=True)
160
+    subprocess.run(git_cmd, cwd=clone_to, check=True)
172 161
 
173
-    print('\nPatch ready in {}'.format(output_dir))
162
+    print('\nPatch ready in {}'.format(clone_to))
174 163
 
175 164
 
176 165
 if __name__ == '__main__':

Loading…
Cancel
Save