blob: 11ebf95606117b174cf9b20e1d30003b0c622771 [file] [log] [blame]
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -08001#!/usr/bin/env python2
Mike Frysingerf80ca212018-07-13 15:02:52 -04002# -*- coding: utf-8 -*-
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -08003# Copyright 2017 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
Mike Frysingerf80ca212018-07-13 15:02:52 -04006
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -08007"""This is a tool for picking patches from upstream and applying them."""
8
9from __future__ import print_function
10
Brian Norris9f8a2be2018-06-01 11:14:08 -070011import ConfigParser
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -080012import argparse
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +080013import functools
Brian Norrisc3421042018-08-15 14:17:26 -070014import mailbox
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -080015import os
Tzung-Bi Shih5100c742019-09-02 10:28:32 +080016import pprint
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -080017import re
18import signal
19import subprocess
20import sys
Harry Cuttsae372f32019-02-12 18:01:14 -080021import textwrap
Brian Norris2d4e9762018-08-15 13:11:47 -070022import urllib
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -080023
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +080024errprint = functools.partial(print, file=sys.stderr)
25
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -080026LINUX_URLS = (
27 'git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git',
28 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git',
29 'https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux.git',
30)
31
Harry Cuttsae372f32019-02-12 18:01:14 -080032COMMIT_MESSAGE_WIDTH = 75
33
Brian Norris9f8a2be2018-06-01 11:14:08 -070034_PWCLIENTRC = os.path.expanduser('~/.pwclientrc')
35
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -070036def _get_conflicts():
37 """Report conflicting files."""
38 resolutions = ('DD', 'AU', 'UD', 'UA', 'DU', 'AA', 'UU')
39 conflicts = []
Douglas Anderson46287f92018-04-30 09:58:24 -070040 lines = subprocess.check_output(['git', 'status', '--porcelain',
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -070041 '--untracked-files=no']).split('\n')
Douglas Anderson46287f92018-04-30 09:58:24 -070042 for line in lines:
43 if not line:
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -070044 continue
Douglas Anderson46287f92018-04-30 09:58:24 -070045 resolution, name = line.split(None, 1)
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -070046 if resolution in resolutions:
47 conflicts.append(' ' + name)
48 if not conflicts:
Douglas Andersonb6a10fe2019-08-12 13:53:30 -070049 return ''
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -070050 return '\nConflicts:\n%s\n' % '\n'.join(conflicts)
51
Guenter Roeckd66daa72018-04-19 10:31:25 -070052def _find_linux_remote():
53 """Find a remote pointing to a Linux upstream repository."""
54 git_remote = subprocess.Popen(['git', 'remote'], stdout=subprocess.PIPE)
55 remotes = git_remote.communicate()[0].strip()
56 for remote in remotes.splitlines():
57 rurl = subprocess.Popen(['git', 'remote', 'get-url', remote],
58 stdout=subprocess.PIPE)
59 url = rurl.communicate()[0].strip()
60 if not rurl.returncode and url in LINUX_URLS:
61 return remote
62 return None
63
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -070064def _pause_for_merge(conflicts):
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -080065 """Pause and go in the background till user resolves the conflicts."""
66
67 git_root = subprocess.check_output(['git', 'rev-parse',
68 '--show-toplevel']).strip('\n')
69
70 paths = (
71 os.path.join(git_root, '.git', 'rebase-apply'),
72 os.path.join(git_root, '.git', 'CHERRY_PICK_HEAD'),
73 )
74 for path in paths:
75 if os.path.exists(path):
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +080076 errprint('Found "%s".' % path)
77 errprint(conflicts)
78 errprint('Please resolve the conflicts and restart the '
79 'shell job when done. Kill this job if you '
80 'aborted the conflict.')
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -080081 os.kill(os.getpid(), signal.SIGTSTP)
82 # TODO: figure out what the state is after the merging, and go based on
83 # that (should we abort? skip? continue?)
84 # Perhaps check last commit message to see if it's the one we were using.
85
Brian Norris9f8a2be2018-06-01 11:14:08 -070086def _get_pw_url(project):
87 """Retrieve the patchwork server URL from .pwclientrc.
88
Mike Frysingerf80ca212018-07-13 15:02:52 -040089 Args:
90 project: patchwork project name; if None, we retrieve the default
91 from pwclientrc
Brian Norris9f8a2be2018-06-01 11:14:08 -070092 """
93 config = ConfigParser.ConfigParser()
94 config.read([_PWCLIENTRC])
95
96 if project is None:
97 try:
98 project = config.get('options', 'default')
99 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800100 errprint('Error: no default patchwork project found in %s.'
101 % _PWCLIENTRC)
Brian Norris9f8a2be2018-06-01 11:14:08 -0700102 sys.exit(1)
103
104 if not config.has_option(project, 'url'):
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800105 errprint("Error: patchwork URL not found for project '%s'" % project)
Brian Norris9f8a2be2018-06-01 11:14:08 -0700106 sys.exit(1)
107
108 url = config.get(project, 'url')
Brian Norris2d4e9762018-08-15 13:11:47 -0700109 # Strip trailing 'xmlrpc' and/or trailing slash.
110 return re.sub('/(xmlrpc/)?$', '', url)
Brian Norris9f8a2be2018-06-01 11:14:08 -0700111
Harry Cuttsae372f32019-02-12 18:01:14 -0800112def _wrap_commit_line(prefix, content):
113 line = prefix + '=' + content
114 indent = ' ' * (len(prefix) + 1)
115 return textwrap.fill(line, COMMIT_MESSAGE_WIDTH, subsequent_indent=indent)
116
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800117def _match_patchwork(match, args):
118 """Match location: pw://### or pw://PROJECT/###."""
119 pw_project = match.group(2)
120 patch_id = int(match.group(3))
121
122 if args['debug']:
123 print('_match_patchwork: pw_project=%s, patch_id=%d' %
124 (pw_project, patch_id))
125
126 if args['tag'] is None:
127 args['tag'] = 'FROMLIST: '
128
129 url = _get_pw_url(pw_project)
130 opener = urllib.urlopen('%s/patch/%d/mbox' % (url, patch_id))
131 if opener.getcode() != 200:
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800132 errprint('Error: could not download patch - error code %d'
133 % opener.getcode())
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800134 sys.exit(1)
135 patch_contents = opener.read()
136
137 if not patch_contents:
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800138 errprint('Error: No patch content found')
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800139 sys.exit(1)
140
Douglas Andersonbecd4e62019-09-25 13:40:55 -0700141 message_id = mailbox.Message(patch_contents)['Message-Id']
142 message_id = re.sub('^<|>$', '', message_id.strip())
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800143 if args['source_line'] is None:
144 args['source_line'] = '(am from %s/patch/%d/)' % (url, patch_id)
Tzung-Bi Shiha8f310d2019-09-04 19:10:10 +0800145 args['source_line'] += (
146 '\n(also found at https://lkml.kernel.org/r/%s)' % message_id)
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800147
Douglas Andersonbecd4e62019-09-25 13:40:55 -0700148 # Auto-snarf the Change-Id if it was encoded into the Message-Id.
149 mo = re.match(r'.*(I[a-f0-9]{40})@changeid$', message_id)
150 if mo and args['changeid'] is None:
151 args['changeid'] = mo.group(1)
152
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800153 if args['replace']:
154 subprocess.call(['git', 'reset', '--hard', 'HEAD~1'])
155
156 git_am = subprocess.Popen(['git', 'am', '-3'], stdin=subprocess.PIPE)
157 git_am.communicate(patch_contents)
158 return git_am.returncode
159
160def _match_linux(match, args):
161 """Match location: linux://HASH."""
162 commit = match.group(1)
163
164 if args['debug']:
165 print('_match_linux: commit=%s' % commit)
166
167 # Confirm a 'linux' remote is setup.
168 linux_remote = _find_linux_remote()
169 if not linux_remote:
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800170 errprint('Error: need a valid upstream remote')
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800171 sys.exit(1)
172
173 linux_master = '%s/master' % linux_remote
174 ret = subprocess.call(['git', 'merge-base', '--is-ancestor',
175 commit, linux_master])
176 if ret:
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800177 errprint('Error: Commit not in %s' % linux_master)
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800178 sys.exit(1)
179
180 if args['source_line'] is None:
181 git_pipe = subprocess.Popen(['git', 'rev-parse', commit],
182 stdout=subprocess.PIPE)
183 commit = git_pipe.communicate()[0].strip()
184
185 args['source_line'] = ('(cherry picked from commit %s)' %
186 (commit))
187 if args['tag'] is None:
188 args['tag'] = 'UPSTREAM: '
189
190 if args['replace']:
191 subprocess.call(['git', 'reset', '--hard', 'HEAD~1'])
192
193 return subprocess.call(['git', 'cherry-pick', commit])
194
195def _match_fromgit(match, args):
196 """Match location: git://remote/branch/HASH."""
197 remote = match.group(2)
198 branch = match.group(3)
199 commit = match.group(4)
200
201 if args['debug']:
202 print('_match_fromgit: remote=%s branch=%s commit=%s' %
203 (remote, branch, commit))
204
205 ret = subprocess.call(['git', 'merge-base', '--is-ancestor',
206 commit, '%s/%s' % (remote, branch)])
207 if ret:
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800208 errprint('Error: Commit not in %s/%s' % (remote, branch))
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800209 sys.exit(1)
210
211 git_pipe = subprocess.Popen(['git', 'remote', 'get-url', remote],
212 stdout=subprocess.PIPE)
213 url = git_pipe.communicate()[0].strip()
214
215 if args['source_line'] is None:
216 git_pipe = subprocess.Popen(['git', 'rev-parse', commit],
217 stdout=subprocess.PIPE)
218 commit = git_pipe.communicate()[0].strip()
219
Tzung-Bi Shiha8f310d2019-09-04 19:10:10 +0800220 args['source_line'] = (
221 '(cherry picked from commit %s\n %s %s)' % (commit, url, branch))
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800222 if args['tag'] is None:
223 args['tag'] = 'FROMGIT: '
224
225 if args['replace']:
226 subprocess.call(['git', 'reset', '--hard', 'HEAD~1'])
227
228 return subprocess.call(['git', 'cherry-pick', commit])
229
230def _match_gitfetch(match, args):
231 """Match location: (git|https)://repoURL#branch/HASH."""
232 remote = match.group(1)
233 branch = match.group(3)
234 commit = match.group(4)
235
236 if args['debug']:
237 print('_match_gitfetch: remote=%s branch=%s commit=%s' %
238 (remote, branch, commit))
239
240 ret = subprocess.call(['git', 'fetch', remote, branch])
241 if ret:
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800242 errprint('Error: Branch not in %s' % remote)
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800243 sys.exit(1)
244
245 url = remote
246
247 if args['source_line'] is None:
248 git_pipe = subprocess.Popen(['git', 'rev-parse', commit],
249 stdout=subprocess.PIPE)
250 commit = git_pipe.communicate()[0].strip()
251
Tzung-Bi Shiha8f310d2019-09-04 19:10:10 +0800252 args['source_line'] = (
253 '(cherry picked from commit %s\n %s %s)' % (commit, url, branch))
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800254 if args['tag'] is None:
255 args['tag'] = 'FROMGIT: '
256
257 return subprocess.call(['git', 'cherry-pick', commit])
258
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800259def main(args):
260 """This is the main entrypoint for fromupstream.
261
262 Args:
263 args: sys.argv[1:]
264
265 Returns:
266 An int return code.
267 """
268 parser = argparse.ArgumentParser()
269
270 parser.add_argument('--bug', '-b',
Guenter Roeckf47a50c2018-07-25 12:41:36 -0700271 type=str, help='BUG= line')
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800272 parser.add_argument('--test', '-t',
Guenter Roeckf47a50c2018-07-25 12:41:36 -0700273 type=str, help='TEST= line')
Stephen Boyd24b309b2018-11-06 22:11:00 -0800274 parser.add_argument('--crbug', action='append',
275 type=int, help='BUG=chromium: line')
276 parser.add_argument('--buganizer', action='append',
277 type=int, help='BUG=b: line')
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800278 parser.add_argument('--changeid', '-c',
279 help='Overrides the gerrit generated Change-Id line')
280
Tzung-Bi Shihf5d25a82019-09-02 11:40:09 +0800281 parser.add_argument('--replace', '-r',
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800282 action='store_true',
Tzung-Bi Shih196d31e2019-09-01 18:16:28 +0800283 help='Replaces the HEAD commit with this one, taking '
284 'its properties(BUG, TEST, Change-Id). Useful for '
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800285 'updating commits.')
286 parser.add_argument('--nosignoff',
287 dest='signoff', action='store_false')
Tzung-Bi Shih5100c742019-09-02 10:28:32 +0800288 parser.add_argument('--debug', '-d', action='store_true',
289 help='Prints more verbose logs.')
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800290
291 parser.add_argument('--tag',
292 help='Overrides the tag from the title')
293 parser.add_argument('--source', '-s',
294 dest='source_line', type=str,
Tzung-Bi Shih196d31e2019-09-01 18:16:28 +0800295 help='Overrides the source line, last line, ex: '
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800296 '(am from http://....)')
297 parser.add_argument('locations',
Douglas Andersonc77a8b82018-05-04 17:02:03 -0700298 nargs='+',
Tzung-Bi Shih196d31e2019-09-01 18:16:28 +0800299 help='Patchwork ID (pw://### or pw://PROJECT/###, '
300 'where PROJECT is defined in ~/.pwclientrc; if no '
301 'PROJECT is specified, the default is retrieved from '
302 '~/.pwclientrc), '
303 'linux commit like linux://HASH, or '
304 'git reference like git://remote/branch/HASH or '
305 'git://repoURL#branch/HASH or '
Stephen Boyd66ea1912018-10-30 11:26:54 -0700306 'https://repoURL#branch/HASH')
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800307
308 args = vars(parser.parse_args(args))
309
Stephen Boyd24b309b2018-11-06 22:11:00 -0800310 buglist = [args['bug']] if args['bug'] else []
311 if args['buganizer']:
312 buglist += ['b:{0}'.format(x) for x in args['buganizer']]
313 if args['crbug']:
314 buglist += ['chromium:{0}'.format(x) for x in args['crbug']]
Brian Norris667a0cb2018-12-07 09:28:46 -0800315 if buglist:
316 args['bug'] = ', '.join(buglist)
Stephen Boyd24b309b2018-11-06 22:11:00 -0800317
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800318 if args['replace']:
319 old_commit_message = subprocess.check_output(
320 ['git', 'show', '-s', '--format=%B', 'HEAD']
321 ).strip('\n')
Tzung-Bi Shih231fada2019-09-02 00:54:59 +0800322
323 # It is possible that multiple Change-Ids are in the commit message
324 # (due to cherry picking). We only want to pull out the first one.
325 changeid_match = re.search('^Change-Id: (.*)$',
326 old_commit_message, re.MULTILINE)
327 if changeid_match:
328 args['changeid'] = changeid_match.group(1)
329
Tzung-Bi Shihe1e0e7d2019-09-02 15:04:38 +0800330 bugs = re.findall('^BUG=(.*)$', old_commit_message, re.MULTILINE)
Tzung-Bi Shih04345302019-09-02 12:04:01 +0800331 if args['bug'] is None and bugs:
332 args['bug'] = '\nBUG='.join(bugs)
333
Tzung-Bi Shihe1e0e7d2019-09-02 15:04:38 +0800334 tests = re.findall('^TEST=(.*)$', old_commit_message, re.MULTILINE)
Tzung-Bi Shih04345302019-09-02 12:04:01 +0800335 if args['test'] is None and tests:
336 args['test'] = '\nTEST='.join(tests)
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800337 # TODO: deal with multiline BUG/TEST better
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800338
Guenter Roeckf47a50c2018-07-25 12:41:36 -0700339 if args['bug'] is None or args['test'] is None:
Tzung-Bi Shih196d31e2019-09-01 18:16:28 +0800340 parser.error('BUG=/TEST= lines are required; --replace can help '
Stephen Boyde6fdf912018-11-09 10:30:57 -0800341 'automate, or set via --bug/--test')
Guenter Roeckf47a50c2018-07-25 12:41:36 -0700342
Tzung-Bi Shih5100c742019-09-02 10:28:32 +0800343 if args['debug']:
344 pprint.pprint(args)
345
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800346 re_matches = (
Tzung-Bi Shihe1e0e7d2019-09-02 15:04:38 +0800347 (re.compile(r'^pw://(([^/]+)/)?(\d+)'), _match_patchwork),
348 (re.compile(r'^linux://([0-9a-f]+)'), _match_linux),
349 (re.compile(r'^(from)?git://([^/\#]+)/([^#]+)/([0-9a-f]+)$'),
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800350 _match_fromgit),
Tzung-Bi Shihe1e0e7d2019-09-02 15:04:38 +0800351 (re.compile(r'^((git|https)://.+)#(.+)/([0-9a-f]+)$'), _match_gitfetch),
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800352 )
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800353
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800354 for location in args['locations']:
Tzung-Bi Shih5100c742019-09-02 10:28:32 +0800355 if args['debug']:
356 print('location=%s' % location)
357
Tzung-Bi Shih886c9092019-09-02 12:46:16 +0800358 for reg, handler in re_matches:
359 match = reg.match(location)
360 if match:
361 ret = handler(match, args)
362 break
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800363 else:
Tzung-Bi Shih436fdba2019-09-04 19:05:00 +0800364 errprint('Don\'t know what "%s" means.' % location)
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800365 sys.exit(1)
366
367 if ret != 0:
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -0700368 conflicts = _get_conflicts()
Douglas Anderson2108e532018-04-30 09:50:42 -0700369 if args['tag'] == 'UPSTREAM: ':
370 args['tag'] = 'BACKPORT: '
371 else:
372 args['tag'] = 'BACKPORT: ' + args['tag']
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -0700373 _pause_for_merge(conflicts)
374 else:
Douglas Andersonb6a10fe2019-08-12 13:53:30 -0700375 conflicts = ''
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800376
377 # extract commit message
378 commit_message = subprocess.check_output(
379 ['git', 'show', '-s', '--format=%B', 'HEAD']
380 ).strip('\n')
381
Guenter Roeck2e4f2512018-04-24 09:20:51 -0700382 # Remove stray Change-Id, most likely from merge resolution
383 commit_message = re.sub(r'Change-Id:.*\n?', '', commit_message)
384
Brian Norris7a41b982018-06-01 10:28:29 -0700385 # Note the source location before tagging anything else
386 commit_message += '\n' + args['source_line']
387
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800388 # add automatic Change ID, BUG, and TEST (and maybe signoff too) so
389 # next commands know where to work on
390 commit_message += '\n'
Guenter Roeckbdbb9cc2018-04-19 10:05:08 -0700391 commit_message += conflicts
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800392 commit_message += '\n' + 'BUG=' + args['bug']
Harry Cuttsae372f32019-02-12 18:01:14 -0800393 commit_message += '\n' + _wrap_commit_line('TEST', args['test'])
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800394 if args['signoff']:
395 extra = ['-s']
396 else:
397 extra = []
Stephen Boydaa4e7e02018-11-09 08:48:46 -0800398 subprocess.Popen(
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800399 ['git', 'commit'] + extra + ['--amend', '-F', '-'],
400 stdin=subprocess.PIPE
401 ).communicate(commit_message)
402
403 # re-extract commit message
404 commit_message = subprocess.check_output(
405 ['git', 'show', '-s', '--format=%B', 'HEAD']
406 ).strip('\n')
407
Douglas Andersonbecd4e62019-09-25 13:40:55 -0700408 # If we see a "Link: " that seems to point to a Message-Id with an
409 # automatic Change-Id we'll snarf it out.
410 mo = re.search(r'^Link:.*(I[a-f0-9]{40})@changeid', commit_message,
411 re.MULTILINE)
412 if mo and args['changeid'] is None:
413 args['changeid'] = mo.group(1)
414
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800415 # replace changeid if needed
416 if args['changeid'] is not None:
417 commit_message = re.sub(r'(Change-Id: )(\w+)', r'\1%s' %
418 args['changeid'], commit_message)
419 args['changeid'] = None
420
421 # decorate it that it's from outside
422 commit_message = args['tag'] + commit_message
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800423
424 # commit everything
Stephen Boydaa4e7e02018-11-09 08:48:46 -0800425 subprocess.Popen(
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800426 ['git', 'commit', '--amend', '-F', '-'], stdin=subprocess.PIPE
427 ).communicate(commit_message)
428
Chirantan Ekbote4b08e712019-06-12 15:35:41 +0900429 return 0
Alexandru M Stanfb5b5ee2014-12-04 13:32:55 -0800430
431if __name__ == '__main__':
432 sys.exit(main(sys.argv[1:]))