chiark / gitweb /
Check for disappeared newborn files in git.tree_status (bug #8516)
authorCatalin Marinas <catalin.marinas@gmail.com>
Sat, 1 Dec 2007 23:00:00 +0000 (23:00 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Sat, 1 Dec 2007 23:00:00 +0000 (23:00 +0000)
If a file is added to the index (stg add) but is removed from the shell,
git.tree_status doesn't detect it but other commands like push fail. The
patch adds a call to 'git diff-files' in git.tree_status.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/git.py
t/t0002-status.sh
t/t1202-push-undo.sh

index b5551ded0aba040a7a7e83d3c5878e0314da42f6..6744be0e09750578b8e25a9628c27c37a26b1ce7 100644 (file)
@@ -230,15 +230,27 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
         conflicts = []
     cache_files += [('C', filename) for filename in conflicts
                     if not files or filename in files]
+    reported_files = set(conflicts)
 
-    # the rest
+    # files in the index
     args = diff_flags + [tree_id]
     if files:
         args += ['--'] + files
     for line in GRun('diff-index', *args).output_lines():
         fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
-        if fs[1] not in conflicts:
+        if fs[1] not in reported_files:
             cache_files.append(fs)
+            reported_files.add(fs[1])
+
+    # files in the index but changed on (or removed from) disk
+    args = list(diff_flags)
+    if files:
+        args += ['--'] + files
+    for line in GRun('diff-files', *args).output_lines():
+        fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
+        if fs[1] not in reported_files:
+            cache_files.append(fs)
+            reported_files.add(fs[1])
 
     if verbose:
         out.done()
index 6389a23f0464a52a13213e4b0d1a607bcfbfc6bc..43e1ca08e4deba373408c9914cd04f85c545b3eb 100755 (executable)
@@ -159,4 +159,16 @@ test_expect_success 'Status after deleting a file' '
     diff -u expected.txt output.txt
 '
 
+cat > expected.txt <<EOF
+D foo/bar
+EOF
+test_expect_success 'Status of disappeared newborn' '
+    stg refresh &&
+    touch foo/bar &&
+    stg add foo/bar &&
+    rm foo/bar &&
+    stg status > output.txt &&
+    diff -u expected.txt output.txt
+'
+
 test_done
index 51ae138dea4d603e1be9dbd587da772b8aeb5054..edfa7105e2fced7b2491ebf11288e3b756c09459 100755 (executable)
@@ -58,4 +58,13 @@ test_expect_success \
        ! stg push bar
        '
 
+test_expect_success \
+       'Undo with disappeared newborn' \
+       '
+       touch newfile &&
+       stg add newfile &&
+       rm newfile &&
+       stg push --undo
+       '
+
 test_done