Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 3 | # Copyright (C) 2013-15 The CyanogenMod Project |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | # |
| 19 | # Run repopick.py -h for a description of this utility. |
| 20 | # |
| 21 | |
| 22 | from __future__ import print_function |
| 23 | |
| 24 | import sys |
| 25 | import json |
| 26 | import os |
| 27 | import subprocess |
| 28 | import re |
| 29 | import argparse |
| 30 | import textwrap |
Tom Powell | 8b3a67d | 2015-09-25 14:23:26 -0700 | [diff] [blame] | 31 | from xml.etree import ElementTree |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 32 | |
| 33 | try: |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 34 | # For python3 |
| 35 | import urllib.error |
| 36 | import urllib.request |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 37 | except ImportError: |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 38 | # For python2 |
| 39 | import imp |
| 40 | import urllib2 |
| 41 | urllib = imp.new_module('urllib') |
| 42 | urllib.error = urllib2 |
| 43 | urllib.request = urllib2 |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 44 | |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 45 | |
| 46 | # Verifies whether pathA is a subdirectory (or the same) as pathB |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 47 | def is_subdir(a, b): |
| 48 | a = os.path.realpath(a) + '/' |
| 49 | b = os.path.realpath(b) + '/' |
| 50 | return b == a[:len(b)] |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 51 | |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 52 | |
| 53 | def fetch_query_via_ssh(remote_url, query): |
| 54 | """Given a remote_url and a query, return the list of changes that fit it |
| 55 | This function is slightly messy - the ssh api does not return data in the same structure as the HTTP REST API |
| 56 | We have to get the data, then transform it to match what we're expecting from the HTTP RESET API""" |
| 57 | if remote_url.count(':') == 2: |
| 58 | (uri, userhost, port) = remote_url.split(':') |
Tom Powell | ff0032a | 2015-09-01 16:52:40 -0700 | [diff] [blame] | 59 | userhost = userhost[2:] |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 60 | elif remote_url.count(':') == 1: |
| 61 | (uri, userhost) = remote_url.split(':') |
Tom Powell | ff0032a | 2015-09-01 16:52:40 -0700 | [diff] [blame] | 62 | userhost = userhost[2:] |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 63 | port = 29418 |
| 64 | else: |
| 65 | raise Exception('Malformed URI: Expecting ssh://[user@]host[:port]') |
| 66 | |
| 67 | |
| 68 | out = subprocess.check_output(['ssh', '-x', '-p{0}'.format(port), userhost, 'gerrit', 'query', '--format=JSON --patch-sets --current-patch-set', query]) |
| 69 | |
| 70 | reviews = [] |
| 71 | for line in out.split('\n'): |
| 72 | try: |
| 73 | data = json.loads(line) |
| 74 | # make our data look like the http rest api data |
| 75 | review = { |
| 76 | 'branch': data['branch'], |
| 77 | 'change_id': data['id'], |
| 78 | 'current_revision': data['currentPatchSet']['revision'], |
| 79 | 'number': int(data['number']), |
| 80 | 'revisions': {patch_set['revision']: { |
| 81 | 'number': int(patch_set['number']), |
| 82 | 'fetch': { |
| 83 | 'ssh': { |
| 84 | 'ref': patch_set['ref'], |
| 85 | 'url': u'ssh://{0}:{1}/{2}'.format(userhost, port, data['project']) |
| 86 | } |
| 87 | } |
| 88 | } for patch_set in data['patchSets']}, |
| 89 | 'subject': data['subject'], |
| 90 | 'project': data['project'], |
| 91 | 'status': data['status'] |
| 92 | } |
| 93 | reviews.append(review) |
Tom Powell | ff0032a | 2015-09-01 16:52:40 -0700 | [diff] [blame] | 94 | except: |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 95 | pass |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 96 | args.quiet or print('Found {0} reviews'.format(len(reviews))) |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 97 | return reviews |
| 98 | |
| 99 | |
| 100 | def fetch_query_via_http(remote_url, query): |
| 101 | |
| 102 | """Given a query, fetch the change numbers via http""" |
| 103 | url = '{0}/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS'.format(remote_url, query) |
| 104 | data = urllib.request.urlopen(url).read().decode('utf-8') |
| 105 | reviews = json.loads(data[5:]) |
| 106 | |
| 107 | for review in reviews: |
| 108 | review[u'number'] = review.pop('_number') |
| 109 | |
| 110 | return reviews |
| 111 | |
| 112 | |
| 113 | def fetch_query(remote_url, query): |
| 114 | """Wrapper for fetch_query_via_proto functions""" |
Tom Powell | ff0032a | 2015-09-01 16:52:40 -0700 | [diff] [blame] | 115 | if remote_url[0:3] == 'ssh': |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 116 | return fetch_query_via_ssh(remote_url, query) |
| 117 | elif remote_url[0:4] == 'http': |
| 118 | return fetch_query_via_http(remote_url, query.replace(' ', '+')) |
| 119 | else: |
| 120 | raise Exception('Gerrit URL should be in the form http[s]://hostname/ or ssh://[user@]host[:port]') |
| 121 | |
| 122 | if __name__ == '__main__': |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 123 | # Default to CyanogenMod Gerrit |
| 124 | default_gerrit = 'http://review.cyanogenmod.org' |
| 125 | |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 126 | parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=textwrap.dedent('''\ |
| 127 | repopick.py is a utility to simplify the process of cherry picking |
| 128 | patches from CyanogenMod's Gerrit instance (or any gerrit instance of your choosing) |
| 129 | |
| 130 | Given a list of change numbers, repopick will cd into the project path |
| 131 | and cherry pick the latest patch available. |
| 132 | |
| 133 | With the --start-branch argument, the user can specify that a branch |
| 134 | should be created before cherry picking. This is useful for |
| 135 | cherry-picking many patches into a common branch which can be easily |
| 136 | abandoned later (good for testing other's changes.) |
| 137 | |
| 138 | The --abandon-first argument, when used in conjunction with the |
| 139 | --start-branch option, will cause repopick to abandon the specified |
| 140 | branch in all repos first before performing any cherry picks.''')) |
| 141 | parser.add_argument('change_number', nargs='*', help='change number to cherry pick. Use {change number}/{patchset number} to get a specific revision.') |
| 142 | parser.add_argument('-i', '--ignore-missing', action='store_true', help='do not error out if a patch applies to a missing directory') |
| 143 | parser.add_argument('-s', '--start-branch', nargs=1, help='start the specified branch before cherry picking') |
| 144 | parser.add_argument('-a', '--abandon-first', action='store_true', help='before cherry picking, abandon the branch specified in --start-branch') |
| 145 | parser.add_argument('-b', '--auto-branch', action='store_true', help='shortcut to "--start-branch auto --abandon-first --ignore-missing"') |
| 146 | parser.add_argument('-q', '--quiet', action='store_true', help='print as little as possible') |
| 147 | parser.add_argument('-v', '--verbose', action='store_true', help='print extra information to aid in debug') |
jrior001 | fd11d07 | 2015-08-21 17:23:25 -0400 | [diff] [blame] | 148 | parser.add_argument('-f', '--force', action='store_true', help='force cherry pick even if change is closed') |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 149 | parser.add_argument('-p', '--pull', action='store_true', help='execute pull instead of cherry-pick') |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 150 | parser.add_argument('-P', '--path', help='use the specified path for the change') |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 151 | parser.add_argument('-t', '--topic', help='pick all commits from a specified topic') |
| 152 | parser.add_argument('-Q', '--query', help='pick all commits using the specified query') |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 153 | parser.add_argument('-g', '--gerrit', default=default_gerrit, help='Gerrit Instance to use. Form proto://[user@]host[:port]') |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 154 | args = parser.parse_args() |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 155 | if not args.start_branch and args.abandon_first: |
| 156 | parser.error('if --abandon-first is set, you must also give the branch name with --start-branch') |
| 157 | if args.auto_branch: |
| 158 | args.abandon_first = True |
| 159 | args.ignore_missing = True |
| 160 | if not args.start_branch: |
| 161 | args.start_branch = ['auto'] |
| 162 | if args.quiet and args.verbose: |
| 163 | parser.error('--quiet and --verbose cannot be specified together') |
| 164 | |
| 165 | if (1 << bool(args.change_number) << bool(args.topic) << bool(args.query)) != 2: |
| 166 | parser.error('One (and only one) of change_number, topic, and query are allowed') |
| 167 | |
| 168 | # Change current directory to the top of the tree |
| 169 | if 'ANDROID_BUILD_TOP' in os.environ: |
| 170 | top = os.environ['ANDROID_BUILD_TOP'] |
| 171 | |
| 172 | if not is_subdir(os.getcwd(), top): |
| 173 | sys.stderr.write('ERROR: You must run this tool from within $ANDROID_BUILD_TOP!\n') |
| 174 | sys.exit(1) |
| 175 | os.chdir(os.environ['ANDROID_BUILD_TOP']) |
| 176 | |
| 177 | # Sanity check that we are being run from the top level of the tree |
| 178 | if not os.path.isdir('.repo'): |
| 179 | sys.stderr.write('ERROR: No .repo directory found. Please run this from the top of your tree.\n') |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 180 | sys.exit(1) |
| 181 | |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 182 | # If --abandon-first is given, abandon the branch before starting |
| 183 | if args.abandon_first: |
| 184 | # Determine if the branch already exists; skip the abandon if it does not |
| 185 | plist = subprocess.check_output(['repo', 'info']) |
| 186 | needs_abandon = False |
| 187 | for pline in plist: |
| 188 | matchObj = re.match(r'Local Branches.*\[(.*)\]', pline) |
| 189 | if matchObj: |
| 190 | local_branches = re.split('\s*,\s*', matchObj.group(1)) |
| 191 | if any(args.start_branch[0] in s for s in local_branches): |
| 192 | needs_abandon = True |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 193 | |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 194 | if needs_abandon: |
| 195 | # Perform the abandon only if the branch already exists |
| 196 | if not args.quiet: |
| 197 | print('Abandoning branch: %s' % args.start_branch[0]) |
| 198 | subprocess.check_output(['repo', 'abandon', args.start_branch[0]]) |
| 199 | if not args.quiet: |
| 200 | print('') |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 201 | |
Tom Powell | 8b3a67d | 2015-09-25 14:23:26 -0700 | [diff] [blame] | 202 | # Get the master manifest from repo |
| 203 | # - convert project name and revision to a path |
| 204 | project_name_to_data = {} |
| 205 | manifest = subprocess.check_output(['repo', 'manifest']) |
| 206 | xml_root = ElementTree.fromstring(manifest) |
| 207 | projects = xml_root.findall('project') |
| 208 | default_revision = xml_root.findall('default')[0].get('revision').split('/')[-1] |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 209 | |
Tom Powell | 8b3a67d | 2015-09-25 14:23:26 -0700 | [diff] [blame] | 210 | #dump project data into the a list of dicts with the following data: |
| 211 | #{project: {path, revision}} |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 212 | |
Tom Powell | 8b3a67d | 2015-09-25 14:23:26 -0700 | [diff] [blame] | 213 | for project in projects: |
| 214 | name = project.get('name') |
| 215 | path = project.get('path') |
| 216 | revision = project.get('revision') |
| 217 | if revision is None: |
| 218 | revision = default_revision |
| 219 | |
| 220 | if not name in project_name_to_data: |
| 221 | project_name_to_data[name] = {} |
| 222 | project_name_to_data[name][revision] = path |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 223 | |
| 224 | # get data on requested changes |
| 225 | reviews = [] |
| 226 | change_numbers = [] |
| 227 | if args.topic: |
| 228 | reviews = fetch_query(args.gerrit, 'topic:{0}'.format(args.topic)) |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 229 | change_numbers = sorted([str(r['number']) for r in reviews]) |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 230 | if args.query: |
| 231 | reviews = fetch_query(args.gerrit, args.query) |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 232 | change_numbers = sorted([str(r['number']) for r in reviews]) |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 233 | if args.change_number: |
| 234 | reviews = fetch_query(args.gerrit, ' OR '.join('change:{0}'.format(x.split('/')[0]) for x in args.change_number)) |
| 235 | change_numbers = args.change_number |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 236 | |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 237 | # make list of things to actually merge |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 238 | mergables = [] |
| 239 | |
| 240 | for change in change_numbers: |
| 241 | patchset = None |
| 242 | if '/' in change: |
| 243 | (change, patchset) = change.split('/') |
| 244 | change = int(change) |
| 245 | |
| 246 | review = [x for x in reviews if x['number'] == change][0] |
| 247 | mergables.append({ |
| 248 | 'subject': review['subject'], |
| 249 | 'project': review['project'], |
| 250 | 'branch': review['branch'], |
| 251 | 'change_number': review['number'], |
| 252 | 'status': review['status'], |
| 253 | 'fetch': None |
| 254 | }) |
| 255 | mergables[-1]['fetch'] = review['revisions'][review['current_revision']]['fetch'] |
| 256 | mergables[-1]['id'] = change |
| 257 | if patchset: |
| 258 | try: |
| 259 | mergables[-1]['fetch'] = [x['fetch'] for x in review['revisions'] if x['_number'] == patchset][0] |
| 260 | mergables[-1]['id'] = '{0}/{1}'.format(change, patchset) |
| 261 | except (IndexError, ValueError): |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 262 | args.quiet or print('ERROR: The patch set {0}/{1} could not be found, using CURRENT_REVISION instead.'.format(change, patchset)) |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 263 | |
| 264 | for item in mergables: |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 265 | args.quiet or print('Applying change number {0}...'.format(item['id'])) |
jrior001 | fd11d07 | 2015-08-21 17:23:25 -0400 | [diff] [blame] | 266 | # Check if change is open and exit if it's not, unless -f is specified |
Tom Powell | c627f07 | 2015-09-02 05:46:55 +0000 | [diff] [blame] | 267 | if (item['status'] != 'OPEN' and item['status'] != 'NEW') and not args.query: |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 268 | if args.force: |
jrior001 | fd11d07 | 2015-08-21 17:23:25 -0400 | [diff] [blame] | 269 | print('!! Force-picking a closed change !!\n') |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 270 | else: |
Dan Pasanen | fe63628 | 2015-09-09 23:38:16 -0500 | [diff] [blame] | 271 | print('Change status is ' + item['status'] + '. Skipping the cherry pick.\nUse -f to force this pick.') |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 272 | continue |
| 273 | |
| 274 | # Convert the project name to a project path |
| 275 | # - check that the project path exists |
| 276 | project_path = None |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 277 | |
Tom Powell | 8b3a67d | 2015-09-25 14:23:26 -0700 | [diff] [blame] | 278 | if item['project'] in project_name_to_data and item['branch'] in project_name_to_data[item['project']]: |
| 279 | project_path = project_name_to_data[item['project']][item['branch']] |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 280 | elif args.path: |
| 281 | project_path = args.path |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 282 | elif args.ignore_missing: |
| 283 | print('WARNING: Skipping {0} since there is no project directory for: {1}\n'.format(item['id'], item['project'])) |
| 284 | continue |
| 285 | else: |
| 286 | sys.stderr.write('ERROR: For {0}, could not determine the project path for project {1}\n'.format(item['id'], item['project'])) |
| 287 | sys.exit(1) |
| 288 | |
| 289 | # If --start-branch is given, create the branch (more than once per path is okay; repo ignores gracefully) |
| 290 | if args.start_branch: |
| 291 | subprocess.check_output(['repo', 'start', args.start_branch[0], project_path]) |
| 292 | |
| 293 | # Print out some useful info |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 294 | if not args.quiet: |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 295 | print('--> Subject: "{0}"'.format(item['subject'])) |
| 296 | print('--> Project path: {0}'.format(project_path)) |
| 297 | print('--> Change number: {0} (Patch Set {0})'.format(item['id'])) |
| 298 | |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 299 | if 'anonymous http' in item['fetch']: |
| 300 | method = 'anonymous http' |
| 301 | else: |
| 302 | method = 'ssh' |
| 303 | |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 304 | # Try fetching from GitHub first if using default gerrit |
| 305 | if args.gerrit == default_gerrit: |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 306 | if args.verbose: |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 307 | print('Trying to fetch the change from GitHub') |
| 308 | |
| 309 | if args.pull: |
| 310 | cmd = ['git pull --no-edit github', item['fetch'][method]['ref']] |
| 311 | else: |
| 312 | cmd = ['git fetch github', item['fetch'][method]['ref']] |
| 313 | if args.quiet: |
| 314 | cmd.append('--quiet') |
| 315 | else: |
| 316 | print(cmd) |
| 317 | result = subprocess.call([' '.join(cmd)], cwd=project_path, shell=True) |
Chirayu Desai | eaba041 | 2015-11-14 15:21:57 +0530 | [diff] [blame^] | 318 | FETCH_HEAD = '{0}/.git/FETCH_HEAD'.format(project_path) |
| 319 | if result != 0 and os.stat(FETCH_HEAD).st_size != 0: |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 320 | print('ERROR: git command failed') |
| 321 | sys.exit(result) |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 322 | # Check if it worked |
| 323 | if args.gerrit != default_gerrit or os.stat(FETCH_HEAD).st_size == 0: |
| 324 | # If not using the default gerrit or github failed, fetch from gerrit. |
| 325 | if args.verbose: |
| 326 | if args.gerrit == default_gerrit: |
| 327 | print('Fetching from GitHub didn\'t work, trying to fetch the change from Gerrit') |
| 328 | else: |
| 329 | print('Fetching from {0}'.format(args.gerrit)) |
| 330 | |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 331 | if args.pull: |
| 332 | cmd = ['git pull --no-edit', item['fetch'][method]['url'], item['fetch'][method]['ref']] |
| 333 | else: |
| 334 | cmd = ['git fetch', item['fetch'][method]['url'], item['fetch'][method]['ref']] |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 335 | if args.quiet: |
| 336 | cmd.append('--quiet') |
| 337 | else: |
| 338 | print(cmd) |
| 339 | result = subprocess.call([' '.join(cmd)], cwd=project_path, shell=True) |
| 340 | if result != 0: |
| 341 | print('ERROR: git command failed') |
| 342 | sys.exit(result) |
Tom Powell | c858030 | 2015-08-04 15:37:12 -0700 | [diff] [blame] | 343 | # Perform the cherry-pick |
| 344 | if not args.pull: |
| 345 | cmd = ['git cherry-pick FETCH_HEAD'] |
Brint E. Kriebel | 9c1a3c3 | 2015-09-09 22:29:28 -0700 | [diff] [blame] | 346 | if args.quiet: |
| 347 | cmd_out = open(os.devnull, 'wb') |
| 348 | else: |
| 349 | cmd_out = None |
| 350 | result = subprocess.call(cmd, cwd=project_path, shell=True, stdout=cmd_out, stderr=cmd_out) |
| 351 | if result != 0: |
| 352 | print('ERROR: git command failed') |
| 353 | sys.exit(result) |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 354 | if not args.quiet: |
| 355 | print('') |