git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Make git rm submodule succeed if .gitmodules index stat info is zero
@ 2020-01-27 18:58 David Turner
  2020-01-28 23:16 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: David Turner @ 2020-01-27 18:58 UTC (permalink / raw)
  To: git; +Cc: David Turner

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://public-inbox.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>
---
 submodule.c   | 2 +-
 t/t3600-rm.sh | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/submodule.c b/submodule.c
index 9da7181321..86e46d3dce 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
 	}
 
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 0ea858d652..f2c0168941 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -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 &&
-- 
2.11.GIT


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Make git rm submodule succeed if .gitmodules index stat info is zero
  2020-01-27 18:58 [PATCH] Make git rm submodule succeed if .gitmodules index stat info is zero David Turner
@ 2020-01-28 23:16 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2020-01-28 23:16 UTC (permalink / raw)
  To: David Turner; +Cc: git

David Turner <dturner@twosigma.com> writes:

> 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.

Makes sense.  ie_match_stat() often ends up comparing the file
contents in our tests due to sequence Git commands firing too
rapidly, leading to a racy-index status, but read-tree is a reliable
way to clear the cached stat information to force it say "I dunno---
suspect it got modified".  Will queue.

> +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 &&

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-28 23:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-27 18:58 [PATCH] Make git rm submodule succeed if .gitmodules index stat info is zero David Turner
2020-01-28 23:16 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).