Skip to content

Commit 3f7ba60

Browse files
matheustavaresgitster
authored andcommitted
checkout-index: omit entries with no tempname from --temp output
With --temp (or --stage=all, which implies --temp), checkout-index writes a list to stdout associating temporary file names to the entries' names. But if it fails to write an entry, and the failure happens before even assigning a temporary filename to that entry, we get an odd output line. This can be seen when trying to check out a symlink whose blob is missing: $ missing_blob=$(git hash-object --stdin </dev/null) $ git update-index --add --cacheinfo 120000,$missing_blob,foo $ git checkout-index --temp foo error: unable to read sha1 file of foo (e69de29) foo The 'TAB foo' line is not much useful and it might break scripts that expect the 'tempname TAB foo' output. So let's omit such entries from the stdout list (but leaving the error message on stderr). We could also consider omitting _all_ failed entries from the output list, but that's probably not a good idea as the associated tempfiles may have been created even when checkout failed, so scripts may want to use the output list for cleanup. Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9334ea8 commit 3f7ba60

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

builtin/checkout-index.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,35 @@ static struct checkout state = CHECKOUT_INIT;
2323
static void write_tempfile_record(const char *name, const char *prefix)
2424
{
2525
int i;
26+
int have_tempname = 0;
2627

2728
if (CHECKOUT_ALL == checkout_stage) {
28-
for (i = 1; i < 4; i++) {
29-
if (i > 1)
30-
putchar(' ');
31-
if (topath[i][0])
32-
fputs(topath[i], stdout);
33-
else
34-
putchar('.');
29+
for (i = 1; i < 4; i++)
30+
if (topath[i][0]) {
31+
have_tempname = 1;
32+
break;
33+
}
34+
35+
if (have_tempname) {
36+
for (i = 1; i < 4; i++) {
37+
if (i > 1)
38+
putchar(' ');
39+
if (topath[i][0])
40+
fputs(topath[i], stdout);
41+
else
42+
putchar('.');
43+
}
3544
}
36-
} else
45+
} else if (topath[checkout_stage][0]) {
46+
have_tempname = 1;
3747
fputs(topath[checkout_stage], stdout);
48+
}
3849

39-
putchar('\t');
40-
write_name_quoted_relative(name, prefix, stdout,
41-
nul_term_line ? '\0' : '\n');
50+
if (have_tempname) {
51+
putchar('\t');
52+
write_name_quoted_relative(name, prefix, stdout,
53+
nul_term_line ? '\0' : '\n');
54+
}
4255

4356
for (i = 0; i < 4; i++) {
4457
topath[i][0] = 0;

0 commit comments

Comments
 (0)