chiark / gitweb /
Add import -p option
[stgit] / stgit / commands / commit.py
index f8927b5c4b722c2da8768c123a0e180f03844fa6..dd8d6e6ce84a51fdc257c7174507d1fc5806349f 100644 (file)
@@ -15,14 +15,19 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
+from stgit.argparse import opt
 from stgit.commands import common
 from stgit.lib import transaction
 from stgit.out import *
 from stgit.commands import common
 from stgit.lib import transaction
 from stgit.out import *
+from stgit import argparse
 
 
-help = 'permanently store the applied patches into stack base'
-usage = """%prog [<patchnames>] | -n NUM | --all
-
+help = 'Permanently store the applied patches into the stack base'
+kind = 'stack'
+usage = ['',
+         '<patchnames>',
+         '-n NUM',
+         '--all']
+description = """
 Merge one or more patches into the base of the current stack and
 remove them from the series while advancing the base. This is the
 opposite of 'stg uncommit'. Use this command if you no longer want to
 Merge one or more patches into the base of the current stack and
 remove them from the series while advancing the base. This is the
 opposite of 'stg uncommit'. Use this command if you no longer want to
@@ -36,25 +41,27 @@ The -n/--number option specifies the number of applied patches to
 commit (counting from the bottom of the stack). If -a/--all is given,
 all applied patches are committed."""
 
 commit (counting from the bottom of the stack). If -a/--all is given,
 all applied patches are committed."""
 
+args = [argparse.patch_range(argparse.applied_patches,
+                             argparse.unapplied_patches)]
+options = [
+    opt('-n', '--number', type = 'int',
+        short = 'Commit the specified number of patches'),
+    opt('-a', '--all', action = 'store_true',
+        short = 'Commit all applied patches')]
+
 directory = common.DirectoryHasRepositoryLib()
 directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-n', '--number', type = 'int',
-                       help = 'commit the specified number of patches'),
-           make_option('-a', '--all', action = 'store_true',
-                       help = 'commit all applied patches')]
 
 def func(parser, options, args):
     """Commit a number of patches."""
     stack = directory.repository.current_stack
 
 def func(parser, options, args):
     """Commit a number of patches."""
     stack = directory.repository.current_stack
-    args = common.parse_patches(args, (list(stack.patchorder.applied)
-                                       + list(stack.patchorder.unapplied)))
+    args = common.parse_patches(args, list(stack.patchorder.all_visible))
     if len([x for x in [args, options.number != None, options.all] if x]) > 1:
         parser.error('too many options')
     if args:
     if len([x for x in [args, options.number != None, options.all] if x]) > 1:
         parser.error('too many options')
     if args:
-        patches = [pn for pn in (stack.patchorder.applied
-                                 + stack.patchorder.unapplied) if pn in args]
+        patches = [pn for pn in stack.patchorder.all_visible if pn in args]
         bad = set(args) - set(patches)
         if bad:
         bad = set(args) - set(patches)
         if bad:
-            raise common.CmdException('Bad patch names: %s'
+            raise common.CmdException('Nonexistent or hidden patch names: %s'
                                       % ', '.join(sorted(bad)))
     elif options.number != None:
         if options.number <= len(stack.patchorder.applied):
                                       % ', '.join(sorted(bad)))
     elif options.number != None:
         if options.number <= len(stack.patchorder.applied):
@@ -69,7 +76,12 @@ def func(parser, options, args):
         raise common.CmdException('No patches to commit')
 
     iw = stack.repository.default_iw
         raise common.CmdException('No patches to commit')
 
     iw = stack.repository.default_iw
-    trans = transaction.StackTransaction(stack, 'commit')
+    def allow_conflicts(trans):
+        # As long as the topmost patch stays where it is, it's OK to
+        # run "stg commit" with conflicts in the index.
+        return len(trans.applied) >= 1
+    trans = transaction.StackTransaction(stack, 'commit',
+                                         allow_conflicts = allow_conflicts)
     try:
         common_prefix = 0
         for i in xrange(min(len(stack.patchorder.applied), len(patches))):
     try:
         common_prefix = 0
         for i in xrange(min(len(stack.patchorder.applied), len(patches))):