Skip to content

Commit d2b3691

Browse files
committed
"git checkout -- paths..." should error out when paths cannot be written
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>
1 parent a7052d3 commit d2b3691

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

builtin-checkout.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec)
8484
unsigned char rev[20];
8585
int flag;
8686
struct commit *head;
87+
int errs = 0;
8788

8889
int newfd;
8990
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)
106107
if (report_path_error(ps_matched, pathspec, 0))
107108
return 1;
108109

110+
/* Now we are committed to check them out */
109111
memset(&state, 0, sizeof(state));
110112
state.force = 1;
111113
state.refresh_cache = 1;
112114
for (pos = 0; pos < active_nr; pos++) {
113115
struct cache_entry *ce = active_cache[pos];
114116
if (pathspec_match(pathspec, NULL, ce->name, 0)) {
115-
checkout_entry(ce, &state, NULL);
117+
errs |= checkout_entry(ce, &state, NULL);
116118
}
117119
}
118120

@@ -123,7 +125,8 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec)
123125
resolve_ref("HEAD", rev, 0, &flag);
124126
head = lookup_commit_reference_gently(rev, 1);
125127

126-
return post_checkout_hook(head, head, 0);
128+
errs |= post_checkout_hook(head, head, 0);
129+
return errs;
127130
}
128131

129132
static void show_local_changes(struct object *head)

0 commit comments

Comments
 (0)