1 from stgit
import argparse
, utils
2 from stgit
.argparse
import opt
3 from stgit
.commands
.common
import (
5 DirectoryHasRepository
,
9 from stgit
.config
import config
10 from stgit
.lib
.git
import CommitData
, Person
11 from stgit
.lib
.transaction
import StackTransaction
14 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License version 2 as
18 published by the Free Software Foundation.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, see http://www.gnu.org/licenses/.
29 help = 'Create a new, empty patch'
31 usage
= ['[options] [--] [<name>]']
33 Create a new, empty patch on the current stack. The new patch is
34 created on top of the currently applied patches, and is made the new
35 top of the stack. Uncommitted changes in the work tree are not
36 included in the patch -- that is handled by linkstg:refresh[].
38 The given name must be unique in the stack, and may only contain
39 alphanumeric characters, dashes and underscores. If no name is given,
40 one is generated from the first line of the patch's commit message.
42 An editor will be launched to edit the commit message to be used for
43 the patch, unless the '--message' flag already specified one. The
44 'patchdescr.tmpl' template file (if available) is used to pre-fill the
53 short
='show diff in patch commit message template',
55 In addition to the names of files that have been changed, also show a
56 diff of staged and unstaged changes.''',
59 options
.extend(argparse
.author_options())
60 options
.extend(argparse
.message_options(save_template
=True))
61 options
.extend(argparse
.trailer_options())
62 options
.extend(argparse
.hook_options())
65 directory
= DirectoryHasRepository()
68 def func(parser
, options
, args
):
69 """Create a new patch."""
70 stack
= directory
.repository
.current_stack
71 if stack
.repository
.default_index
.conflicts():
72 raise CmdException('Cannot create a new patch -- resolve conflicts first')
74 # Choose a name for the new patch -- or None, which means make one
75 # up later when we've gotten hold of the commit message.
80 if not stack
.patches
.is_name_valid(name
):
81 raise CmdException('Invalid patch name: "%s"' % name
)
82 elif name
in stack
.patches
:
83 raise CmdException('%s: patch already exists' % name
)
85 parser
.error('incorrect number of arguments')
88 verbose
= options
.verbose
90 verbose
= config
.getbool('stgit.new.verbose') or False
93 tree
=stack
.head
.data
.tree
,
96 author
=Person
.author(),
97 committer
=Person
.committer(),
99 cd
= update_commit_data(
102 message
=options
.message
,
103 author
=options
.author(cd
.author
),
104 trailers
=options
.trailers
,
105 edit
=(not options
.save_template
and options
.message
is None),
109 if options
.save_template
:
110 options
.save_template(cd
.message
)
111 return utils
.STGIT_SUCCESS
113 if not options
.no_verify
:
114 cd
= run_commit_msg_hook(stack
.repository
, cd
)
117 name
= stack
.patches
.make_name(cd
.message_str
)
119 # Write the new patch.
120 stack
.repository
.default_iw
121 trans
= StackTransaction(stack
, 'new: %s' % name
)
122 trans
.patches
[name
] = stack
.repository
.commit(cd
)
123 trans
.applied
.append(name
)