Add a --reset option to resolved
authorCatalin Marinas <catalin.marinas@gmail.com>
Wed, 5 Oct 2005 15:58:18 +0000 (16:58 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 5 Oct 2005 15:58:18 +0000 (16:58 +0100)
With this option one can ask for a conflicted file to be reset to one of
the local, remote or older states.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/common.py
stgit/commands/resolved.py

index 4e4a79f..7a9df6e 100644 (file)
@@ -99,18 +99,26 @@ def print_crt_patch():
     else:
         print 'No patches applied'
 
-def resolved(filename):
+def resolved(filename, reset = None):
+    if reset:
+        reset_file = filename + '.' + reset
+        if os.path.isfile(reset_file):
+            if os.path.isfile(filename):
+                os.remove(filename)
+            os.rename(reset_file, filename)
+
     git.update_cache([filename], force = True)
+
     for ext in ['.local', '.older', '.remote']:
         fn = filename + ext
         if os.path.isfile(fn):
             os.remove(fn)
 
-def resolved_all():
+def resolved_all(reset = None):
     conflicts = git.get_conflicts()
     if conflicts:
         for filename in conflicts:
-            resolved(filename)
+            resolved(filename, reset)
         os.remove(os.path.join(git.base_dir, 'conflicts'))
 
 def name_email(string):
index d98ca9a..d21ecc9 100644 (file)
@@ -33,14 +33,19 @@ Mark a merge conflict as resolved. The conflicts can be seen with the
 
 options = [make_option('-a', '--all',
                        help = 'mark all conflicts as solved',
-                       action = 'store_true')]
+                       action = 'store_true'),
+           make_option('-r', '--reset', metavar = '(local|remote|older)',
+                       help = 'reset the file(s) to the given state')]
 
 
 def func(parser, options, args):
     """Mark the conflict as resolved
     """
+    if options.reset and options.reset not in ['local', 'remote', 'older']:
+        raise CmdException, 'Unknown reset state: %s' % options.reset
+
     if options.all:
-        resolved_all()
+        resolved_all(options.reset)
         return
 
     if len(args) == 0:
@@ -55,7 +60,7 @@ def func(parser, options, args):
             raise CmdException, 'No conflicts for "%s"' % filename
     # resolved
     for filename in args:
-        resolved(filename)
+        resolved(filename, options.reset)
         del conflicts[conflicts.index(filename)]
 
     # save or remove the conflicts file