blob: a85b1d8b5e7e7e2394ee46aee4e2efd8924801e9 [file] [log] [blame]
Michael Bestas3952f6c2016-08-26 01:12:08 +03001#!/usr/bin/env python
2#
3# Copyright (C) 2013-15 The CyanogenMod Project
Dan Pasanen0fdc0852016-12-27 10:32:16 -06004# (C) 2017 The LineageOS Project
Michael Bestas3952f6c2016-08-26 01:12:08 +03005#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19#
20# Run repopick.py -h for a description of this utility.
21#
22
23from __future__ import print_function
24
25import sys
26import json
27import os
28import subprocess
29import re
30import argparse
31import textwrap
Gabriele M5b610ae2018-03-31 14:26:59 +020032from functools import cmp_to_key
Michael Bestas3952f6c2016-08-26 01:12:08 +030033from xml.etree import ElementTree
34
35try:
Dan Pasanen1cdd3802017-01-23 15:08:52 -060036 import requests
Michael Bestas3952f6c2016-08-26 01:12:08 +030037except ImportError:
Dan Pasanen1cdd3802017-01-23 15:08:52 -060038 try:
39 # For python3
40 import urllib.error
41 import urllib.request
42 except ImportError:
43 # For python2
44 import imp
45 import urllib2
46 urllib = imp.new_module('urllib')
47 urllib.error = urllib2
48 urllib.request = urllib2
Michael Bestas3952f6c2016-08-26 01:12:08 +030049
50
Luca Weiss5ee35ea2018-11-25 14:07:12 +010051# cmp() is not available in Python 3, define it manually
52# See https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
53def cmp(a, b):
54 return (a > b) - (a < b)
55
56
Michael Bestas3952f6c2016-08-26 01:12:08 +030057# Verifies whether pathA is a subdirectory (or the same) as pathB
58def is_subdir(a, b):
59 a = os.path.realpath(a) + '/'
60 b = os.path.realpath(b) + '/'
61 return b == a[:len(b)]
62
63
64def fetch_query_via_ssh(remote_url, query):
65 """Given a remote_url and a query, return the list of changes that fit it
66 This function is slightly messy - the ssh api does not return data in the same structure as the HTTP REST API
67 We have to get the data, then transform it to match what we're expecting from the HTTP RESET API"""
68 if remote_url.count(':') == 2:
69 (uri, userhost, port) = remote_url.split(':')
70 userhost = userhost[2:]
71 elif remote_url.count(':') == 1:
72 (uri, userhost) = remote_url.split(':')
73 userhost = userhost[2:]
74 port = 29418
75 else:
76 raise Exception('Malformed URI: Expecting ssh://[user@]host[:port]')
77
78
79 out = subprocess.check_output(['ssh', '-x', '-p{0}'.format(port), userhost, 'gerrit', 'query', '--format=JSON --patch-sets --current-patch-set', query])
80 if not hasattr(out, 'encode'):
81 out = out.decode()
82 reviews = []
83 for line in out.split('\n'):
84 try:
85 data = json.loads(line)
86 # make our data look like the http rest api data
87 review = {
88 'branch': data['branch'],
89 'change_id': data['id'],
90 'current_revision': data['currentPatchSet']['revision'],
91 'number': int(data['number']),
92 'revisions': {patch_set['revision']: {
Gabriele M0fcc1222018-04-10 18:35:12 +020093 '_number': int(patch_set['number']),
Michael Bestas3952f6c2016-08-26 01:12:08 +030094 'fetch': {
95 'ssh': {
96 'ref': patch_set['ref'],
97 'url': 'ssh://{0}:{1}/{2}'.format(userhost, port, data['project'])
98 }
Gabriele M0fcc1222018-04-10 18:35:12 +020099 },
100 'commit': {
101 'parents': [{ 'commit': parent } for parent in patch_set['parents']]
102 },
Michael Bestas3952f6c2016-08-26 01:12:08 +0300103 } for patch_set in data['patchSets']},
104 'subject': data['subject'],
105 'project': data['project'],
106 'status': data['status']
107 }
108 reviews.append(review)
109 except:
110 pass
111 args.quiet or print('Found {0} reviews'.format(len(reviews)))
112 return reviews
113
114
115def fetch_query_via_http(remote_url, query):
Dan Pasanen1cdd3802017-01-23 15:08:52 -0600116 if "requests" in sys.modules:
117 auth = None
118 if os.path.isfile(os.getenv("HOME") + "/.gerritrc"):
119 f = open(os.getenv("HOME") + "/.gerritrc", "r")
120 for line in f:
121 parts = line.rstrip().split("|")
122 if parts[0] in remote_url:
123 auth = requests.auth.HTTPBasicAuth(username=parts[1], password=parts[2])
124 statusCode = '-1'
125 if auth:
Gabriele M5b610ae2018-03-31 14:26:59 +0200126 url = '{0}/a/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS&o=ALL_COMMITS'.format(remote_url, query)
Dan Pasanen1cdd3802017-01-23 15:08:52 -0600127 data = requests.get(url, auth=auth)
128 statusCode = str(data.status_code)
129 if statusCode != '200':
130 #They didn't get good authorization or data, Let's try the old way
Gabriele M5b610ae2018-03-31 14:26:59 +0200131 url = '{0}/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS&o=ALL_COMMITS'.format(remote_url, query)
Dan Pasanen1cdd3802017-01-23 15:08:52 -0600132 data = requests.get(url)
133 reviews = json.loads(data.text[5:])
134 else:
135 """Given a query, fetch the change numbers via http"""
Gabriele M5b610ae2018-03-31 14:26:59 +0200136 url = '{0}/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS&o=ALL_COMMITS'.format(remote_url, query)
Dan Pasanen1cdd3802017-01-23 15:08:52 -0600137 data = urllib.request.urlopen(url).read().decode('utf-8')
138 reviews = json.loads(data[5:])
Michael Bestas3952f6c2016-08-26 01:12:08 +0300139
140 for review in reviews:
141 review['number'] = review.pop('_number')
142
143 return reviews
144
145
146def fetch_query(remote_url, query):
147 """Wrapper for fetch_query_via_proto functions"""
148 if remote_url[0:3] == 'ssh':
149 return fetch_query_via_ssh(remote_url, query)
150 elif remote_url[0:4] == 'http':
151 return fetch_query_via_http(remote_url, query.replace(' ', '+'))
152 else:
153 raise Exception('Gerrit URL should be in the form http[s]://hostname/ or ssh://[user@]host[:port]')
154
155if __name__ == '__main__':
Dan Pasanen0fdc0852016-12-27 10:32:16 -0600156 # Default to LineageOS Gerrit
rohanfa44f372020-03-14 23:40:54 -0400157 default_gerrit = 'https://review.blissroms.com'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300158
159 parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=textwrap.dedent('''\
160 repopick.py is a utility to simplify the process of cherry picking
Dan Pasanen0fdc0852016-12-27 10:32:16 -0600161 patches from LineageOS's Gerrit instance (or any gerrit instance of your choosing)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300162
163 Given a list of change numbers, repopick will cd into the project path
164 and cherry pick the latest patch available.
165
166 With the --start-branch argument, the user can specify that a branch
167 should be created before cherry picking. This is useful for
168 cherry-picking many patches into a common branch which can be easily
169 abandoned later (good for testing other's changes.)
170
171 The --abandon-first argument, when used in conjunction with the
172 --start-branch option, will cause repopick to abandon the specified
173 branch in all repos first before performing any cherry picks.'''))
174 parser.add_argument('change_number', nargs='*', help='change number to cherry pick. Use {change number}/{patchset number} to get a specific revision.')
175 parser.add_argument('-i', '--ignore-missing', action='store_true', help='do not error out if a patch applies to a missing directory')
176 parser.add_argument('-s', '--start-branch', nargs=1, help='start the specified branch before cherry picking')
Harry Youd1c9c5a32017-07-18 18:52:42 +0100177 parser.add_argument('-r', '--reset', action='store_true', help='reset to initial state (abort cherry-pick) if there is a conflict')
Michael Bestas3952f6c2016-08-26 01:12:08 +0300178 parser.add_argument('-a', '--abandon-first', action='store_true', help='before cherry picking, abandon the branch specified in --start-branch')
179 parser.add_argument('-b', '--auto-branch', action='store_true', help='shortcut to "--start-branch auto --abandon-first --ignore-missing"')
180 parser.add_argument('-q', '--quiet', action='store_true', help='print as little as possible')
181 parser.add_argument('-v', '--verbose', action='store_true', help='print extra information to aid in debug')
182 parser.add_argument('-f', '--force', action='store_true', help='force cherry pick even if change is closed')
183 parser.add_argument('-p', '--pull', action='store_true', help='execute pull instead of cherry-pick')
184 parser.add_argument('-P', '--path', help='use the specified path for the change')
Giuseppe Maggiobcf8e892019-03-18 17:24:06 +0100185 parser.add_argument('-t', '--topic', nargs='*', help='pick all commits from the specified topics')
Michael Bestas3952f6c2016-08-26 01:12:08 +0300186 parser.add_argument('-Q', '--query', help='pick all commits using the specified query')
187 parser.add_argument('-g', '--gerrit', default=default_gerrit, help='Gerrit Instance to use. Form proto://[user@]host[:port]')
188 parser.add_argument('-e', '--exclude', nargs=1, help='exclude a list of commit numbers separated by a ,')
Adrian DCdf290222017-09-07 22:59:54 +0200189 parser.add_argument('-c', '--check-picked', type=int, default=10, help='pass the amount of commits to check for already picked changes')
Michael Bestas3952f6c2016-08-26 01:12:08 +0300190 args = parser.parse_args()
191 if not args.start_branch and args.abandon_first:
192 parser.error('if --abandon-first is set, you must also give the branch name with --start-branch')
193 if args.auto_branch:
194 args.abandon_first = True
195 args.ignore_missing = True
196 if not args.start_branch:
197 args.start_branch = ['auto']
198 if args.quiet and args.verbose:
199 parser.error('--quiet and --verbose cannot be specified together')
200
201 if (1 << bool(args.change_number) << bool(args.topic) << bool(args.query)) != 2:
202 parser.error('One (and only one) of change_number, topic, and query are allowed')
203
204 # Change current directory to the top of the tree
205 if 'ANDROID_BUILD_TOP' in os.environ:
206 top = os.environ['ANDROID_BUILD_TOP']
207
208 if not is_subdir(os.getcwd(), top):
209 sys.stderr.write('ERROR: You must run this tool from within $ANDROID_BUILD_TOP!\n')
210 sys.exit(1)
211 os.chdir(os.environ['ANDROID_BUILD_TOP'])
212
213 # Sanity check that we are being run from the top level of the tree
214 if not os.path.isdir('.repo'):
215 sys.stderr.write('ERROR: No .repo directory found. Please run this from the top of your tree.\n')
216 sys.exit(1)
217
218 # If --abandon-first is given, abandon the branch before starting
219 if args.abandon_first:
220 # Determine if the branch already exists; skip the abandon if it does not
221 plist = subprocess.check_output(['repo', 'info'])
222 if not hasattr(plist, 'encode'):
223 plist = plist.decode()
224 needs_abandon = False
225 for pline in plist.splitlines():
226 matchObj = re.match(r'Local Branches.*\[(.*)\]', pline)
227 if matchObj:
228 local_branches = re.split('\s*,\s*', matchObj.group(1))
229 if any(args.start_branch[0] in s for s in local_branches):
230 needs_abandon = True
231
232 if needs_abandon:
233 # Perform the abandon only if the branch already exists
234 if not args.quiet:
235 print('Abandoning branch: %s' % args.start_branch[0])
236 subprocess.check_output(['repo', 'abandon', args.start_branch[0]])
237 if not args.quiet:
238 print('')
239
240 # Get the master manifest from repo
241 # - convert project name and revision to a path
242 project_name_to_data = {}
243 manifest = subprocess.check_output(['repo', 'manifest'])
244 xml_root = ElementTree.fromstring(manifest)
245 projects = xml_root.findall('project')
246 remotes = xml_root.findall('remote')
247 default_revision = xml_root.findall('default')[0].get('revision')
248
249 #dump project data into the a list of dicts with the following data:
250 #{project: {path, revision}}
251
252 for project in projects:
253 name = project.get('name')
254 path = project.get('path')
255 revision = project.get('revision')
256 if revision is None:
257 for remote in remotes:
258 if remote.get('name') == project.get('remote'):
259 revision = remote.get('revision')
260 if revision is None:
Simon Shields2bdb18f2016-09-26 17:52:03 +1000261 revision = default_revision
Michael Bestas3952f6c2016-08-26 01:12:08 +0300262
263 if not name in project_name_to_data:
264 project_name_to_data[name] = {}
265 revision = revision.split('refs/heads/')[-1]
266 project_name_to_data[name][revision] = path
267
268 # get data on requested changes
269 reviews = []
270 change_numbers = []
Gabriele M5b610ae2018-03-31 14:26:59 +0200271
272 def cmp_reviews(review_a, review_b):
273 current_a = review_a['current_revision']
274 parents_a = [r['commit'] for r in review_a['revisions'][current_a]['commit']['parents']]
275 current_b = review_b['current_revision']
276 parents_b = [r['commit'] for r in review_b['revisions'][current_b]['commit']['parents']]
277 if current_a in parents_b:
278 return -1
279 elif current_b in parents_a:
280 return 1
281 else:
282 return cmp(review_a['number'], review_b['number'])
283
Michael Bestas3952f6c2016-08-26 01:12:08 +0300284 if args.topic:
Giuseppe Maggiobcf8e892019-03-18 17:24:06 +0100285 for t in args.topic:
286 # Store current topic to process for change_numbers
287 topic = fetch_query(args.gerrit, 'topic:{0}'.format(t))
288 # Append topic to reviews, for later reference
289 reviews += topic
290 # Cycle through the current topic to get the change numbers
291 change_numbers += sorted([str(r['number']) for r in topic], key=int)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300292 if args.query:
293 reviews = fetch_query(args.gerrit, args.query)
Gabriele M5b610ae2018-03-31 14:26:59 +0200294 change_numbers = [str(r['number']) for r in sorted(reviews, key=cmp_to_key(cmp_reviews))]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300295 if args.change_number:
Gabriele Maf970b62018-04-01 17:50:58 +0200296 change_url_re = re.compile('https?://.+?/([0-9]+(?:/[0-9]+)?)/?')
Michael Bestas3952f6c2016-08-26 01:12:08 +0300297 for c in args.change_number:
Gabriele Maf970b62018-04-01 17:50:58 +0200298 change_number = change_url_re.findall(c)
299 if change_number:
300 change_numbers.extend(change_number)
301 elif '-' in c:
Michael Bestas3952f6c2016-08-26 01:12:08 +0300302 templist = c.split('-')
303 for i in range(int(templist[0]), int(templist[1]) + 1):
304 change_numbers.append(str(i))
305 else:
306 change_numbers.append(c)
307 reviews = fetch_query(args.gerrit, ' OR '.join('change:{0}'.format(x.split('/')[0]) for x in change_numbers))
308
309 # make list of things to actually merge
310 mergables = []
311
312 # If --exclude is given, create the list of commits to ignore
313 exclude = []
314 if args.exclude:
315 exclude = args.exclude[0].split(',')
316
317 for change in change_numbers:
318 patchset = None
319 if '/' in change:
320 (change, patchset) = change.split('/')
321
322 if change in exclude:
323 continue
324
325 change = int(change)
LuK1337ad5d9a02017-03-24 23:25:13 +0100326
Gabriele Mde9e0ae2018-04-01 17:50:55 +0200327 if patchset:
LuK1337ad5d9a02017-03-24 23:25:13 +0100328 patchset = int(patchset)
329
Michael Bestas3952f6c2016-08-26 01:12:08 +0300330 review = next((x for x in reviews if x['number'] == change), None)
331 if review is None:
332 print('Change %d not found, skipping' % change)
333 continue
334
335 mergables.append({
336 'subject': review['subject'],
337 'project': review['project'],
338 'branch': review['branch'],
339 'change_id': review['change_id'],
340 'change_number': review['number'],
341 'status': review['status'],
Gabriele M88c0e5d2018-04-01 17:50:57 +0200342 'fetch': None,
343 'patchset': review['revisions'][review['current_revision']]['_number'],
Michael Bestas3952f6c2016-08-26 01:12:08 +0300344 })
Gabriele M88c0e5d2018-04-01 17:50:57 +0200345
Michael Bestas3952f6c2016-08-26 01:12:08 +0300346 mergables[-1]['fetch'] = review['revisions'][review['current_revision']]['fetch']
347 mergables[-1]['id'] = change
348 if patchset:
349 try:
LuK133727564182017-03-24 20:00:48 +0100350 mergables[-1]['fetch'] = [review['revisions'][x]['fetch'] for x in review['revisions'] if review['revisions'][x]['_number'] == patchset][0]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300351 mergables[-1]['id'] = '{0}/{1}'.format(change, patchset)
Gabriele M88c0e5d2018-04-01 17:50:57 +0200352 mergables[-1]['patchset'] = patchset
Michael Bestas3952f6c2016-08-26 01:12:08 +0300353 except (IndexError, ValueError):
354 args.quiet or print('ERROR: The patch set {0}/{1} could not be found, using CURRENT_REVISION instead.'.format(change, patchset))
355
356 for item in mergables:
357 args.quiet or print('Applying change number {0}...'.format(item['id']))
358 # Check if change is open and exit if it's not, unless -f is specified
Dan Pasanen63f767e2017-07-09 09:41:33 -0500359 if (item['status'] != 'OPEN' and item['status'] != 'NEW' and item['status'] != 'DRAFT') and not args.query:
Michael Bestas3952f6c2016-08-26 01:12:08 +0300360 if args.force:
361 print('!! Force-picking a closed change !!\n')
362 else:
363 print('Change status is ' + item['status'] + '. Skipping the cherry pick.\nUse -f to force this pick.')
364 continue
365
366 # Convert the project name to a project path
367 # - check that the project path exists
368 project_path = None
369
370 if item['project'] in project_name_to_data and item['branch'] in project_name_to_data[item['project']]:
371 project_path = project_name_to_data[item['project']][item['branch']]
372 elif args.path:
373 project_path = args.path
Adrian DCff74c6a2019-10-13 12:34:06 +0200374 elif item['project'] in project_name_to_data and len(project_name_to_data[item['project']]) == 1:
375 local_branch = list(project_name_to_data[item['project']])[0]
376 project_path = project_name_to_data[item['project']][local_branch]
377 print('WARNING: Project {0} has a different branch ("{1}" != "{2}")'.format(project_path, local_branch, item['branch']))
Michael Bestas3952f6c2016-08-26 01:12:08 +0300378 elif args.ignore_missing:
379 print('WARNING: Skipping {0} since there is no project directory for: {1}\n'.format(item['id'], item['project']))
380 continue
381 else:
382 sys.stderr.write('ERROR: For {0}, could not determine the project path for project {1}\n'.format(item['id'], item['project']))
383 sys.exit(1)
384
385 # If --start-branch is given, create the branch (more than once per path is okay; repo ignores gracefully)
386 if args.start_branch:
387 subprocess.check_output(['repo', 'start', args.start_branch[0], project_path])
388
389 # Determine the maximum commits to check already picked changes
Adrian DCdf290222017-09-07 22:59:54 +0200390 check_picked_count = args.check_picked
Michael Bestas3952f6c2016-08-26 01:12:08 +0300391 branch_commits_count = int(subprocess.check_output(['git', 'rev-list', '--count', 'HEAD'], cwd=project_path))
392 if branch_commits_count <= check_picked_count:
393 check_picked_count = branch_commits_count - 1
394
395 # Check if change is already picked to HEAD...HEAD~check_picked_count
396 found_change = False
397 for i in range(0, check_picked_count):
Adrian DC13b02ff2016-12-04 12:30:26 +0100398 if subprocess.call(['git', 'cat-file', '-e', 'HEAD~{0}'.format(i)], cwd=project_path, stderr=open(os.devnull, 'wb')):
399 continue
Michael Bestas3952f6c2016-08-26 01:12:08 +0300400 output = subprocess.check_output(['git', 'show', '-q', 'HEAD~{0}'.format(i)], cwd=project_path).split()
401 if 'Change-Id:' in output:
402 head_change_id = ''
403 for j,t in enumerate(reversed(output)):
404 if t == 'Change-Id:':
405 head_change_id = output[len(output) - j]
406 break
407 if head_change_id.strip() == item['change_id']:
408 print('Skipping {0} - already picked in {1} as HEAD~{2}'.format(item['id'], project_path, i))
409 found_change = True
410 break
411 if found_change:
412 continue
413
414 # Print out some useful info
415 if not args.quiet:
LuK1337c62a9fb2019-09-21 11:47:33 +0200416 print(u'--> Subject: "{0}"'.format(item['subject']))
Michael Bestas3952f6c2016-08-26 01:12:08 +0300417 print('--> Project path: {0}'.format(project_path))
Gabriele M88c0e5d2018-04-01 17:50:57 +0200418 print('--> Change number: {0} (Patch Set {1})'.format(item['id'], item['patchset']))
Michael Bestas3952f6c2016-08-26 01:12:08 +0300419
420 if 'anonymous http' in item['fetch']:
421 method = 'anonymous http'
422 else:
423 method = 'ssh'
424
425 # Try fetching from GitHub first if using default gerrit
426 if args.gerrit == default_gerrit:
427 if args.verbose:
428 print('Trying to fetch the change from GitHub')
429
430 if args.pull:
431 cmd = ['git pull --no-edit github', item['fetch'][method]['ref']]
432 else:
433 cmd = ['git fetch github', item['fetch'][method]['ref']]
434 if args.quiet:
435 cmd.append('--quiet')
436 else:
437 print(cmd)
438 result = subprocess.call([' '.join(cmd)], cwd=project_path, shell=True)
439 FETCH_HEAD = '{0}/.git/FETCH_HEAD'.format(project_path)
440 if result != 0 and os.stat(FETCH_HEAD).st_size != 0:
441 print('ERROR: git command failed')
442 sys.exit(result)
443 # Check if it worked
444 if args.gerrit != default_gerrit or os.stat(FETCH_HEAD).st_size == 0:
445 # If not using the default gerrit or github failed, fetch from gerrit.
446 if args.verbose:
447 if args.gerrit == default_gerrit:
448 print('Fetching from GitHub didn\'t work, trying to fetch the change from Gerrit')
449 else:
450 print('Fetching from {0}'.format(args.gerrit))
451
452 if args.pull:
453 cmd = ['git pull --no-edit', item['fetch'][method]['url'], item['fetch'][method]['ref']]
454 else:
455 cmd = ['git fetch', item['fetch'][method]['url'], item['fetch'][method]['ref']]
456 if args.quiet:
457 cmd.append('--quiet')
458 else:
459 print(cmd)
460 result = subprocess.call([' '.join(cmd)], cwd=project_path, shell=True)
461 if result != 0:
462 print('ERROR: git command failed')
463 sys.exit(result)
464 # Perform the cherry-pick
465 if not args.pull:
Tim Schumacher49d26ba2018-10-13 14:37:54 +0200466 cmd = ['git cherry-pick --ff FETCH_HEAD']
Michael Bestas3952f6c2016-08-26 01:12:08 +0300467 if args.quiet:
468 cmd_out = open(os.devnull, 'wb')
469 else:
470 cmd_out = None
471 result = subprocess.call(cmd, cwd=project_path, shell=True, stdout=cmd_out, stderr=cmd_out)
472 if result != 0:
Adrian DC0f8230b2018-08-30 23:07:23 +0200473 cmd = ['git diff-index --quiet HEAD --']
474 result = subprocess.call(cmd, cwd=project_path, shell=True, stdout=cmd_out, stderr=cmd_out)
475 if result == 0:
476 print('WARNING: git command resulted with an empty commit, aborting cherry-pick')
477 cmd = ['git cherry-pick --abort']
478 subprocess.call(cmd, cwd=project_path, shell=True, stdout=cmd_out, stderr=cmd_out)
479 elif args.reset:
Harry Youd1c9c5a32017-07-18 18:52:42 +0100480 print('ERROR: git command failed, aborting cherry-pick')
481 cmd = ['git cherry-pick --abort']
482 subprocess.call(cmd, cwd=project_path, shell=True, stdout=cmd_out, stderr=cmd_out)
Adrian DC0f8230b2018-08-30 23:07:23 +0200483 sys.exit(result)
Harry Youd1c9c5a32017-07-18 18:52:42 +0100484 else:
485 print('ERROR: git command failed')
Adrian DC0f8230b2018-08-30 23:07:23 +0200486 sys.exit(result)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300487 if not args.quiet:
488 print('')