]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git rm submodule: succeed if .gitmodules index stat info is zero
authorDavid Turner <dturner@twosigma.com>
Mon, 27 Jan 2020 18:58:56 +0000 (13:58 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Jan 2020 22:46:14 +0000 (14:46 -0800)
The bug was that ie_match_stat() was used to compare if the stat info
for the file was compatible with the stat info in the index, rather
using ie_modified() to check if the file was in fact different from the
version in the index.

A version of this (with deinit instead of rm) was reported here:
https://lore.kernel.org/git/CAPOqYV+C-P9M2zcUBBkD2LALPm4K3sxSut+BjAkZ9T1AKLEr+A@mail.gmail.com/

It seems that in that case, the user's clone command left the index
with empty stat info.  The mailing list was unable to reproduce this.
But we (Two Sigma) hit the bug while using some plumbing commands, so
I'm fixing it.  I manually confirmed that the fix also repairs deinit
in this scenario.

Signed-off-by: David Turner <dturner@twosigma.com>
Reported-by: Thomas Bétous <th.betous@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
t/t3600-rm.sh

index 9da7181321f089e8450ec7e39692f7928f5638a8..86e46d3dcee603524de01522be88a52cd0a3854d 100644 (file)
@@ -82,7 +82,7 @@ int is_staging_gitmodules_ok(struct index_state *istate)
        if ((pos >= 0) && (pos < istate->cache_nr)) {
                struct stat st;
                if (lstat(GITMODULES_FILE, &st) == 0 &&
-                   ie_match_stat(istate, istate->cache[pos], &st, 0) & DATA_CHANGED)
+                   ie_modified(istate, istate->cache[pos], &st, 0) & DATA_CHANGED)
                        return 0;
        }
 
index 0ea858d652fcb5aee58e8a71c6d68cdbcfb974ea..f2c0168941ad043f61a1e082799e75cefa3b5462 100755 (executable)
@@ -425,6 +425,13 @@ test_expect_success 'rm will error out on a modified .gitmodules file unless sta
        git status -s -uno >actual &&
        test_cmp expect actual
 '
+test_expect_success 'rm will not error out on .gitmodules file with zero stat data' '
+       git reset --hard &&
+       git submodule update &&
+       git read-tree HEAD &&
+       git rm submod &&
+       test_path_is_missing submod
+'
 
 test_expect_success 'rm issues a warning when section is not found in .gitmodules' '
        git reset --hard &&