git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] checkout-index: drop error message from empty --stage=all

From
Jeff King <peff@peff.net>
Date
Oct 27, 2020, 07:36 UTC
Message-ID
<20201027073602.GA3794137@coredump.intra.peff.net>
In-Reply-To
<20201027073000.GA3651896@coredump.intra.peff.net>

If checkout-index is given --stage=all for a specific path, it will try to write stages 1-3 (if present) for that path to temporary files. However, if the file is present only at stage 0, it writes nothing but gives a confusing message:

  $ git checkout-index --stage=all -- Makefile
  git checkout-index: Makefile does not exist at stage 4

This is nonsense. There is no stage 4 (it's just an internal enum value we use for "all"), and the documentation clearly states:

  Paths which only have a stage 0 entry will always be omitted from the
  output.

Here it's talking about the list of tempfiles written to stdout, but it seems clear that this case was not meant to be an error. We even have a test which covers it, but it only checks that the command reports an exit code of 0, not its stderr. And it reports 0 only because of another bug which fails to propagate errors (which will be fixed in a subsequent patch).

So let's make the test more thorough. We'll also cover the case that we found _no_ entry, not even a stage zero, which should still be an error. However, because of the other bug, we'll have to mark this as expecting failure for the moment.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/checkout-index.c       |  8 ++++++++
 t/t2004-checkout-cache-temp.sh | 10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index a854fd16e7..195165d8bd 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -79,6 +79,14 @@ static int checkout_file(const char *name, const char *prefix)
 		return errs > 0 ? -1 : 0;
 	}
 
+	/*
+	 * At this point we know we didn't try to check anything out. If it was
+	 * because we did find an entry but it was stage 0, that's not an
+	 * error.
+	 */
+	if (has_same_name && checkout_stage == CHECKOUT_ALL)
+		return 0;
+
 	if (!state.quiet) {
 		fprintf(stderr, "git checkout-index: %s ", name);
 		if (!has_same_name)
diff --git a/t/t2004-checkout-cache-temp.sh b/t/t2004-checkout-cache-temp.sh
index a12afe93f3..4308d698b9 100755
--- a/t/t2004-checkout-cache-temp.sh
+++ b/t/t2004-checkout-cache-temp.sh
@@ -88,9 +88,17 @@ test_expect_success 'checkout all stage 2 to temporary files' '
 	done
 '
 
+test_expect_failure 'checkout all stages of unknown path' '
+	rm -f path* .merge_* actual &&
+	test_must_fail git checkout-index --stage=all --temp \
+		-- does-not-exist 2>stderr &&
+	test_i18ngrep not.in.the.cache stderr
+'
+
 test_expect_success 'checkout all stages/one file to nothing' '
 	rm -f path* .merge_* actual &&
-	git checkout-index --stage=all --temp -- path0 >actual &&
+	git checkout-index --stage=all --temp -- path0 >actual 2>stderr &&
+	test_must_be_empty stderr &&
 	test_line_count = 0 actual
 '
 
-- 
2.29.1.634.g9e41dc1bf2
Previous: Jeff KingNext: Jeff King
Message 2 of 5 in “fix error handling in checkout-index”
  1. 0/2 fix error handling in checkout-indexJeff King, Oct 27, 2020
  2. 1/2 checkout-index: drop error message from empty --stage=allJeff King, Oct 27, 2020
  3. 2/2 checkout-index: propagate errors to exit codeJeff King, Oct 27, 2020
  4. Junio C HamanoOct 27, 2020
  5. Jeff KingOct 27, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.