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

[PATCH 1/5] "git checkout -- paths..." should error out when paths cannot be written

From
Junio C Hamano <gitster@pobox.com>
Date
May 29, 2008, 00:17 UTC
Message-ID
<1212020246-26480-2-git-send-email-gitster@pobox.com>
In-Reply-To
<1212020246-26480-1-git-send-email-gitster@pobox.com>

When "git checkout -- paths..." cannot update work tree for whatever reason, checkout_entry() correctly issued an error message for the path to the end user, but the command ignored the error, causing the entire command to succeed. This fixes it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-checkout.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 1ea017f..00dc8ca 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -84,6 +84,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec)
 	unsigned char rev[20];
 	int flag;
 	struct commit *head;
+	int errs = 0;
 
 	int newfd;
 	struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
@@ -106,13 +107,14 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec)
 	if (report_path_error(ps_matched, pathspec, 0))
 		return 1;
 
+	/* Now we are committed to check them out */
 	memset(&state, 0, sizeof(state));
 	state.force = 1;
 	state.refresh_cache = 1;
 	for (pos = 0; pos < active_nr; pos++) {
 		struct cache_entry *ce = active_cache[pos];
 		if (pathspec_match(pathspec, NULL, ce->name, 0)) {
-			checkout_entry(ce, &state, NULL);
+			errs |= checkout_entry(ce, &state, NULL);
 		}
 	}
 
@@ -123,7 +125,8 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec)
 	resolve_ref("HEAD", rev, 0, &flag);
 	head = lookup_commit_reference_gently(rev, 1);
 
-	return post_checkout_hook(head, head, 0);
+	errs |= post_checkout_hook(head, head, 0);
+	return errs;
 }
 
 static void show_local_changes(struct object *head)
-- 
1.5.6.rc0.43.g823ea
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 20 in “"best effort" checkout”
  1. 0/5 "best effort" checkoutJunio C Hamano, May 29, 2008
  2. 1/5 "git checkout -- paths..." should error out when paths cannot be writtenJunio C Hamano, May 29, 2008
  3. 2/5 checkout: make reset_clean_to_new() not die by itselfJunio C Hamano, May 29, 2008
  4. 3/5 checkout: consolidate reset_{to_new,clean_to_new|()Junio C Hamano, May 29, 2008
  5. 4/5 unpack_trees(): allow callers to differentiate worktree errors from merge errorsJunio C Hamano, May 29, 2008
  6. 5/5 checkout: "best effort" checkoutJunio C Hamano, May 29, 2008
  7. 6/5 NUL hack to create_file()Junio C Hamano, May 29, 2008
  8. Johannes SixtMay 29, 2008
  9. Marius Storm-OlsenMay 29, 2008
  10. Johannes SixtMay 29, 2008
  11. Daniel BarkalowMay 29, 2008
  12. Brian DessentMay 29, 2008
  13. Daniel BarkalowMay 29, 2008
  14. Johannes SchindelinMay 29, 2008
  15. Daniel BarkalowMay 29, 2008
  16. Junio C HamanoMay 29, 2008
  17. Alex RiesenMay 29, 2008
  18. Mark LevedahlMay 29, 2008
  19. Junio C HamanoMay 30, 2008
  20. Mark LevedahlMay 30, 2008

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.