Infrastructure for current directory handling
[stgit] / stgit / commands / uncommit.py
index f611d29..a23ae20 100644 (file)
@@ -22,6 +22,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 help = 'turn regular GIT commits into StGIT patches'
@@ -47,10 +48,14 @@ given commit should be uncommitted.
 Only commits with exactly one parent can be uncommitted; in other
 words, you can't uncommit a merge."""
 
+directory = DirectoryHasRepository()
 options = [make_option('-n', '--number', type = 'int',
                        help = 'uncommit the specified number of commits'),
            make_option('-t', '--to',
-                       help = 'uncommit to the specified commit')]
+                       help = 'uncommit to the specified commit'),
+           make_option('-x', '--exclusive',
+                       help = 'exclude the commit specified by the --to option',
+                       action = 'store_true')]
 
 def func(parser, options, args):
     """Uncommit a number of patches.
@@ -61,7 +66,7 @@ def func(parser, options, args):
         if len(args) != 0:
             parser.error('cannot specify patch name with --to')
         patch_nr = patchnames = None
-        to_commit = git.rev_parse(options.to)
+        to_commit = git_id(options.to)
     elif options.number:
         if options.number <= 0:
             parser.error('invalid value passed to --number')
@@ -105,12 +110,17 @@ def func(parser, options, args):
             commits.append((commit, commit_id, parent))
             next_commit = parent
     else:
-        out.start('Uncommitting to %s' % to_commit)
+        if options.exclusive:
+            out.start('Uncommitting to %s (exclusive)' % to_commit)
+        else:
+            out.start('Uncommitting to %s' % to_commit)
         while True:
             commit, commit_id, parent = get_commit(next_commit)
-            commits.append((commit, commit_id, parent))
             if commit_id == to_commit:
+                if not options.exclusive:
+                    commits.append((commit, commit_id, parent))
                 break
+            commits.append((commit, commit_id, parent))
             next_commit = parent
         patch_nr = len(commits)
 
@@ -120,6 +130,7 @@ def func(parser, options, args):
                      name_email_date(commit.get_author())
         crt_series.new_patch(patchname,
                              can_edit = False, before_existing = True,
+                             commit = False,
                              top = commit_id, bottom = parent,
                              message = commit.get_log(),
                              author_name = author_name,