| 1 | |
| 2 | __copyright__ = """ |
| 3 | Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License version 2 as |
| 7 | published by the Free Software Foundation. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | """ |
| 18 | |
| 19 | import sys, os |
| 20 | from optparse import OptionParser, make_option |
| 21 | |
| 22 | from stgit.commands.common import * |
| 23 | from stgit.utils import * |
| 24 | from stgit import stack, git |
| 25 | |
| 26 | |
| 27 | help = 'create a new patch and make it the topmost one' |
| 28 | usage = """%prog [options] <name> |
| 29 | |
| 30 | Create a new, empty patch and make it the topmost one. If the |
| 31 | '--message' option is not passed, an editor is invoked with the |
| 32 | .git/patchdescr.tmpl file used a as template, together with generated |
| 33 | lines. By default, if there are local changes in the working tree, the |
| 34 | command fails and a 'refresh' command is needed. This behaviour can be |
| 35 | overridden with the '--force' option.""" |
| 36 | |
| 37 | options = [make_option('-m', '--message', |
| 38 | help = 'use MESSAGE as the patch description'), |
| 39 | make_option('--force', |
| 40 | help = 'proceed even if there are local changes', |
| 41 | action = 'store_true'), |
| 42 | make_option('-s', '--showpatch', |
| 43 | help = 'show the patch content in the editor buffer', |
| 44 | action = 'store_true'), |
| 45 | make_option('-a', '--author', metavar = '"NAME <EMAIL>"', |
| 46 | help = 'use "NAME <EMAIL>" as the author details'), |
| 47 | make_option('--authname', |
| 48 | help = 'use AUTHNAME as the author name'), |
| 49 | make_option('--authemail', |
| 50 | help = 'use AUTHEMAIL as the author e-mail'), |
| 51 | make_option('--authdate', |
| 52 | help = 'use AUTHDATE as the author date'), |
| 53 | make_option('--commname', |
| 54 | help = 'use COMMNAME as the committer name'), |
| 55 | make_option('--commemail', |
| 56 | help = 'use COMMEMAIL as the committer e-mail')] |
| 57 | |
| 58 | |
| 59 | def func(parser, options, args): |
| 60 | """Creates a new patch |
| 61 | """ |
| 62 | if len(args) != 1: |
| 63 | parser.error('incorrect number of arguments') |
| 64 | |
| 65 | if not options.force: |
| 66 | check_local_changes() |
| 67 | check_conflicts() |
| 68 | check_head_top_equal() |
| 69 | # No local changes -> no patch to show |
| 70 | options.showpatch = False |
| 71 | |
| 72 | if options.author: |
| 73 | options.authname, options.authemail = name_email(options.author) |
| 74 | |
| 75 | crt_series.new_patch(args[0], message = options.message, |
| 76 | show_patch = options.showpatch, |
| 77 | author_name = options.authname, |
| 78 | author_email = options.authemail, |
| 79 | author_date = options.authdate, |
| 80 | committer_name = options.commname, |
| 81 | committer_email = options.commemail) |