Use the default git colouring scheme rather than specific scripts
[stgit] / stgit / commands / resolved.py
index d98ca9a..eba778d 100644 (file)
@@ -17,51 +17,66 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
-from stgit import stack, git
-
-
-help = 'mark a file conflict as solved'
-usage = """%prog [options] [<files...>]
+from stgit import argparse, stack, git, basedir
+from stgit.config import config, file_extensions
 
+help = 'Mark a file conflict as solved'
+kind = 'wc'
+usage = ['[options] [<files...>]']
+description = """
 Mark a merge conflict as resolved. The conflicts can be seen with the
 'status' command, the corresponding files being prefixed with a
-'C'. This command also removes any <file>.{local,remote,older} files."""
+'C'."""
 
-options = [make_option('-a', '--all',
-                       help = 'mark all conflicts as solved',
-                       action = 'store_true')]
+args = [argparse.conflicting_files]
+options = [
+    opt('-a', '--all', action = 'store_true',
+        short = 'Mark all conflicts as solved'),
+    opt('-r', '--reset', metavar = '(ancestor|current|patched)',
+        args = [argparse.strings('ancestor', 'current', 'patched')],
+        short = 'Reset the file(s) to the given state'),
+    opt('-i', '--interactive', action = 'store_true',
+        short = 'Run the interactive merging tool')]
 
+directory = DirectoryHasRepository(needs_current_series = False, log = False)
 
 def func(parser, options, args):
     """Mark the conflict as resolved
     """
-    if options.all:
-        resolved_all()
+    args = git.ls_files(args)
+    directory.cd_to_topdir()
+
+    if options.reset \
+           and options.reset not in file_extensions():
+        raise CmdException, 'Unknown reset state: %s' % options.reset
+
+    if options.all and not options.interactive:
+        resolved_all(options.reset)
         return
 
-    if len(args) == 0:
+    conflicts = git.get_conflicts()
+
+    if len(args) != 0:
+        files = args
+    elif options.all:
+        files = conflicts
+    else:
         parser.error('incorrect number of arguments')
 
-    conflicts = git.get_conflicts()
     if not conflicts:
         raise CmdException, 'No more conflicts'
+
     # check for arguments validity
-    for filename in args:
-        if not filename in conflicts:
-            raise CmdException, 'No conflicts for "%s"' % filename
-    # resolved
-    for filename in args:
-        resolved(filename)
-        del conflicts[conflicts.index(filename)]
+    if not options.all:
+        for filename in files:
+            if not filename in conflicts:
+                raise CmdException, 'No conflicts for "%s"' % filename
 
-    # save or remove the conflicts file
-    if conflicts == []:
-        os.remove(os.path.join(git.base_dir, 'conflicts'))
+    # resolved
+    if options.interactive:
+        git.mergetool(files)
     else:
-        f = file(os.path.join(git.base_dir, 'conflicts'), 'w+')
-        f.writelines([line + '\n' for line in conflicts])
-        f.close()
+        git.resolved(files, options.reset)