Fix the added to both but different conflict
[stgit] / stgit / gitmergeonefile.py
index 586cef9..c3aaa2a 100644 (file)
@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
+from stgit import basedir
 from stgit.config import config
 from stgit.utils import append_string
 
@@ -31,15 +32,11 @@ class GitMergeException(Exception):
 # Options
 #
 try:
-    merger = config.get('gitmergeonefile', 'merger')
+    merger = config.get('stgit', 'merger')
+    keeporig = config.get('stgit', 'keeporig')
 except Exception, err:
     raise GitMergeException, 'Configuration error: %s' % err
 
-if config.has_option('gitmergeonefile', 'keeporig'):
-    keeporig = config.get('gitmergeonefile', 'keeporig')
-else:
-    keeporig = 'yes'
-
 
 #
 # Utility functions
@@ -91,21 +88,10 @@ def __remove_files(orig_hash, file1_hash, file2_hash):
         os.remove(src2)
     pass
 
-# GIT_DIR value cached
-__base_dir = None
-
 def __conflict(path):
     """Write the conflict file for the 'path' variable and exit
     """
-    global __base_dir
-
-    if not __base_dir:
-        if 'GIT_DIR' in os.environ:
-            __base_dir = os.environ['GIT_DIR']
-        else:
-            __base_dir = __output('git-rev-parse --git-dir')
-
-    append_string(os.path.join(__base_dir, 'conflicts'), path)
+    append_string(os.path.join(basedir.get(), 'conflicts'), path)
 
 
 #
@@ -219,6 +205,8 @@ def merge(orig_hash, file1_hash, file2_hash,
                     return 1
             # files are different
             else:
+                # reset the index to the current file
+                os.system('git-update-index -- %s' % path)
                 print >> sys.stderr, \
                       'Error: File "%s" added in branches but different' % path
                 __conflict(path)