chiark / gitweb /
Fix gitmergeonefile.py to deal with local installation
[stgit] / gitmergeonefile.py
index 5b588dd94a8e27e2d1b33a2d0ffeab61632a8a11..fe416bdb8f1fafbb72c1b123c7906937f2cb7176 100755 (executable)
@@ -20,6 +20,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
+
+# Try to detect where it is run from and set prefix and the search path.
+# It is assumed that the user installed StGIT using the --prefix= option
+prefix, bin = os.path.split(sys.path[0])
+
+if bin == 'bin' and prefix != sys.prefix:
+    major, minor = sys.version_info[0:2]
+    sys.path += [os.path.join(prefix, 'lib', 'python'),
+                 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
+                 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
+                              'site-packages')]
+
 from stgit.config import config
 from stgit.utils import append_string
 
@@ -74,17 +86,17 @@ def __checkout_files():
         orig = '%s.older' % path
         tmp = __output('git-unpack-file %s' % orig_hash)
         os.chmod(tmp, int(orig_mode, 8))
-        os.rename(tmp, orig)
+        os.renames(tmp, orig)
     if file1_hash:
         src1 = '%s.local' % path
         tmp = __output('git-unpack-file %s' % file1_hash)
         os.chmod(tmp, int(file1_mode, 8))
-        os.rename(tmp, src1)
+        os.renames(tmp, src1)
     if file2_hash:
         src2 = '%s.remote' % path
         tmp = __output('git-unpack-file %s' % file2_hash)
         os.chmod(tmp, int(file2_mode, 8))
-        os.rename(tmp, src2)
+        os.renames(tmp, src2)
 
 def __remove_files():
     """Remove any temporary files
@@ -111,7 +123,9 @@ def __conflict():
 #   $5 - orignal file mode (or empty)
 #   $6 - file in branch1 mode (or empty)
 #   $7 - file in branch2 mode (or empty)
-#print 'gitmerge.py "%s" "%s" "%s" "%s" "%s" "%s" "%s"' % tuple(sys.argv[1:8])
+#
+#print 'gitmergeonefile.py "%s" "%s" "%s" "%s" "%s" "%s" "%s"' \
+#      % tuple(sys.argv[1:8])
 orig_hash, file1_hash, file2_hash, path, orig_mode, file1_mode, file2_mode = \
            [__str2none(x) for x in sys.argv[1:8]]
 
@@ -146,7 +160,7 @@ if orig_hash:
                                            'output': path }) == 0
 
             if merge_ok:
-                os.system('git-update-cache %s' % path)
+                os.system('git-update-cache -- %s' % path)
                 __remove_files()
                 sys.exit(0)
             else:
@@ -164,7 +178,7 @@ if orig_hash:
         if os.path.exists(path):
             os.remove(path)
         __remove_files()
-        sys.exit(os.system('git-update-cache --remove %s' % path))
+        sys.exit(os.system('git-update-cache --remove -- %s' % path))
 # file does not exist in origin
 else:
     # file added in both
@@ -205,6 +219,6 @@ else:
 
 # Un-handled case
 print >> sys.stderr, 'Error: Un-handled merge conflict'
-print >> sys.stderr, 'gitmerge.py "%s" "%s" "%s" "%s" "%s" "%s" "%s"' \
+print >> sys.stderr, 'gitmergeonefile.py "%s" "%s" "%s" "%s" "%s" "%s" "%s"' \
       % tuple(sys.argv[1:8])
 __conflict()