@matheusbsbs / matheus-bagliano / commits / 7edee32985
Fork 0

git rm submodule: succeed if .gitmodules index stat info is zero

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>

David Turner committed Jan 27, 2020 at 13:58 UTC 7edee32985b1363e35e91c7358a9e60f2359fbba
2 files changed +8 -1
submodule.c
+1 -1
@@ -82,7 +82,7 @@ int is_staging_gitmodules_ok(struct index_state *istate)
82 if ((pos >= 0) && (pos < istate->cache_nr)) {
83 struct stat st;
84 if (lstat(GITMODULES_FILE, &st) == 0 &&
85 - ie_match_stat(istate, istate->cache[pos], &st, 0) & DATA_CHANGED)
85 + ie_modified(istate, istate->cache[pos], &st, 0) & DATA_CHANGED)
86 return 0;
87 }
88
t/t3600-rm.sh
+7
@@ -425,6 +425,13 @@ test_expect_success 'rm will error out on a modified .gitmodules file unless sta
425 git status -s -uno >actual &&
426 test_cmp expect actual
427 '
428 +test_expect_success 'rm will not error out on .gitmodules file with zero stat data' '
429 + git reset --hard &&
430 + git submodule update &&
431 + git read-tree HEAD &&
432 + git rm submod &&
433 + test_path_is_missing submod
434 +'
435
436 test_expect_success 'rm issues a warning when section is not found in .gitmodules' '
437 git reset --hard &&