Ask git about unmerged files
authorDavid Kågedal <david@virtutech.com>
Wed, 19 Dec 2007 18:00:12 +0000 (18:00 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 19 Dec 2007 23:13:30 +0000 (23:13 +0000)
Don't look in the "conflicts" file for that, since it isn't updated. Also
added a test that the check_conflicts() function works.

Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/common.py
stgit/git.py
t/t0002-status.sh
t/t1203-push-conflict.sh
t/t1205-push-subdir.sh

index 7cf700e..1426aca 100644 (file)
@@ -129,7 +129,7 @@ def check_head_top_equal(crt_series):
    more about what to do next.""")
 
 def check_conflicts():
-    if os.path.exists(os.path.join(basedir.get(), 'conflicts')):
+    if git.get_conflicts():
         raise CmdException, \
               'Unsolved conflicts. Please resolve them first or\n' \
               '  revert the changes with "status --reset"'
@@ -164,10 +164,8 @@ def resolved(filename, reset = None):
 
 def resolved_all(reset = None):
     conflicts = git.get_conflicts()
-    if conflicts:
-        for filename in conflicts:
-            resolved(filename, reset)
-        os.remove(os.path.join(basedir.get(), 'conflicts'))
+    for filename in conflicts:
+        resolved(filename, reset)
 
 def push_patches(crt_series, patches, check_merged = False):
     """Push multiple patches onto the stack. This function is shared
index 43ac204..6629e39 100644 (file)
@@ -162,14 +162,14 @@ def get_commit(id_hash):
 def get_conflicts():
     """Return the list of file conflicts
     """
-    conflicts_file = os.path.join(basedir.get(), 'conflicts')
-    if os.path.isfile(conflicts_file):
-        f = file(conflicts_file)
-        names = [line.strip() for line in f.readlines()]
-        f.close()
-        return names
-    else:
-        return None
+    names = []
+    for line in GRun('ls-files', '-z', '--unmerged'
+                     ).raw_output().split('\0')[:-1]:
+        stat, path = line.split('\t', 1)
+        # Look for entries in stage 2 (could equally well use 3)
+        if stat.endswith(' 2'):
+            names.append(path)
+    return names
 
 def exclude_files():
     files = [os.path.join(basedir.get(), 'info', 'exclude')]
@@ -234,8 +234,6 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
 
     # conflicted files
     conflicts = get_conflicts()
-    if not conflicts:
-        conflicts = []
     cache_files += [('C', filename) for filename in conflicts
                     if not files or filename in files]
     reported_files = set(conflicts)
index 24f42cc..32c01d0 100755 (executable)
@@ -110,7 +110,7 @@ cat > expected.txt <<EOF
 A fie
 C foo/bar
 EOF
-test_expect_failure 'Status after conflicting push' '
+test_expect_success 'Status after conflicting push' '
     ! stg push &&
     stg status > output.txt &&
     diff -u expected.txt output.txt
@@ -119,7 +119,7 @@ test_expect_failure 'Status after conflicting push' '
 cat > expected.txt <<EOF
 C foo/bar
 EOF
-test_expect_failure 'Status of file' '
+test_expect_success 'Status of file' '
     stg status foo/bar > output.txt &&
     diff -u expected.txt output.txt
 '
@@ -127,7 +127,7 @@ test_expect_failure 'Status of file' '
 cat > expected.txt <<EOF
 C foo/bar
 EOF
-test_expect_failure 'Status of dir' '
+test_expect_success 'Status of dir' '
     stg status foo > output.txt &&
     diff -u expected.txt output.txt
 '
@@ -144,7 +144,7 @@ cat > expected.txt <<EOF
 A fie
 M foo/bar
 EOF
-test_expect_success 'Status after resolving the push' '
+test_expect_failure 'Status after resolving the push' '
     stg resolved -a &&
     stg status > output.txt &&
     diff -u expected.txt output.txt
index f9537d9..57119ab 100755 (executable)
@@ -54,6 +54,12 @@ test_expect_success \
        '
 
 test_expect_success \
+       'Check that pop will fail while there are unmerged conflicts' \
+       '
+       ! stg pop
+       '
+
+test_expect_success \
        'Resolve the conflict' \
        '
        echo resolved > test &&
index 88b23c4..54a5b89 100755 (executable)
@@ -42,7 +42,7 @@ test_expect_success 'Modifying push from a subdir' '
     [ "$(echo $(cat foo/y.txt))" = "y0 y1 y2" ]
 '
 
-test_expect_failure 'Conflicting push from subdir' '
+test_expect_success 'Conflicting push from subdir' '
     stg pop p1 p2 &&
     [ "$(echo $(cat x.txt))" = "x0" ] &&
     [ "$(echo $(cat foo/y.txt))" = "y0" ] &&