2 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License version 2 as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 from stgit
.argparse
import opt
19 from stgit
.commands
import common
20 from stgit
.lib
import transaction
21 from stgit
.out
import *
22 from stgit
import argparse
24 help = 'Permanently store the applied patches into the stack base'
31 Merge one or more patches into the base of the current stack and
32 remove them from the series while advancing the base. This is the
33 opposite of 'stg uncommit'. Use this command if you no longer want to
34 manage a patch with StGIT.
36 By default, the bottommost patch is committed. If patch names are
37 given, the stack is rearranged so that those patches are at the
38 bottom, and then they are committed.
40 The -n/--number option specifies the number of applied patches to
41 commit (counting from the bottom of the stack). If -a/--all is given,
42 all applied patches are committed."""
44 args
= [argparse
.patch_range(argparse
.applied_patches
,
45 argparse
.unapplied_patches
)]
47 opt('-n', '--number', type = 'int',
48 short
= 'Commit the specified number of patches'),
49 opt('-a', '--all', action
= 'store_true',
50 short
= 'Commit all applied patches')]
52 directory
= common
.DirectoryHasRepositoryLib()
54 def func(parser
, options
, args
):
55 """Commit a number of patches."""
56 stack
= directory
.repository
.current_stack
57 args
= common
.parse_patches(args
, list(stack
.patchorder
.all_visible
))
58 if len([x
for x
in [args
, options
.number
!= None, options
.all
] if x
]) > 1:
59 parser
.error('too many options')
61 patches
= [pn
for pn
in stack
.patchorder
.all_visible
if pn
in args
]
62 bad
= set(args
) - set(patches
)
64 raise common
.CmdException('Nonexistent or hidden patch names: %s'
65 %
', '.join(sorted(bad
)))
66 elif options
.number
!= None:
67 if options
.number
<= len(stack
.patchorder
.applied
):
68 patches
= stack
.patchorder
.applied
[:options
.number
]
70 raise common
.CmdException('There are not that many applied patches')
72 patches
= stack
.patchorder
.applied
74 patches
= stack
.patchorder
.applied
[:1]
76 raise common
.CmdException('No patches to commit')
78 iw
= stack
.repository
.default_iw
79 def allow_conflicts(trans
):
80 # As long as the topmost patch stays where it is, it's OK to
81 # run "stg commit" with conflicts in the index.
82 return len(trans
.applied
) >= 1
83 trans
= transaction
.StackTransaction(stack
, 'commit',
84 allow_conflicts
= allow_conflicts
)
87 for i
in xrange(min(len(stack
.patchorder
.applied
), len(patches
))):
88 if stack
.patchorder
.applied
[i
] == patches
[i
]:
92 if common_prefix
< len(patches
):
93 to_push
= [pn
for pn
in stack
.patchorder
.applied
[common_prefix
:]
94 if pn
not in patches
[common_prefix
:]]
95 # this pops all the applied patches from common_prefix
96 trans
.pop_patches(lambda pn
: pn
in to_push
)
97 for pn
in patches
[common_prefix
:]:
98 trans
.push_patch(pn
, iw
)
101 new_base
= trans
.patches
[patches
[-1]]
103 trans
.patches
[pn
] = None
104 trans
.applied
= [pn
for pn
in trans
.applied
if pn
not in patches
]
105 trans
.base
= new_base
106 out
.info('Committed %d patch%s' %
(len(patches
),
107 ['es', ''][len(patches
) == 1]))
109 trans
.push_patch(pn
, iw
)
110 except transaction
.TransactionHalted
: