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