Let some commands work with detached HEAD
[stgit] / stgit / commands / resolved.py
index ae85f2b..011db91 100644 (file)
@@ -23,6 +23,7 @@ from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git, basedir
 from stgit.config import config, file_extensions
+from stgit.gitmergeonefile import interactive_merge
 
 
 help = 'mark a file conflict as solved'
@@ -33,6 +34,7 @@ Mark a merge conflict as resolved. The conflicts can be seen with the
 'C'. This command also removes any <file>.{ancestor,current,patched}
 files."""
 
+directory = DirectoryHasRepository(needs_current_series = False)
 options = [make_option('-a', '--all',
                        help = 'mark all conflicts as solved',
                        action = 'store_true'),
@@ -42,43 +44,12 @@ options = [make_option('-a', '--all',
                        help = 'run the interactive merging tool',
                        action = 'store_true')]
 
-def interactive_merge(filename):
-    """Run the interactive merger on the given file
-    """
-    try:
-        imerger = config.get('stgit', 'imerger')
-    except Exception, err:
-        raise CmdException, 'Configuration error: %s' % err
-
-    extensions = file_extensions()
-
-    ancestor = filename + extensions['ancestor']
-    current = filename + extensions['current']
-    patched = filename + extensions['patched']
-
-    # check whether we have all the files for a three-way merge
-    for fn in [filename, ancestor, current, patched]:
-        if not os.path.isfile(fn):
-            raise CmdException, \
-                  'Cannot run the interactive merger: "%s" missing' % fn
-
-    mtime = os.path.getmtime(filename)
-
-    err = os.system(imerger % {'branch1': current,
-                               'ancestor': ancestor,
-                               'branch2': patched,
-                               'output': filename})
-
-    if err != 0:
-        raise CmdException, 'The interactive merger failed: %d' % err
-    if not os.path.isfile(filename):
-        raise CmdException, 'The "%s" file is missing' % filename
-    if mtime == os.path.getmtime(filename):
-        raise CmdException, 'The "%s" file was not modified' % filename
-
 def func(parser, options, args):
     """Mark the conflict as resolved
     """
+    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