built-in add -p: show helpful hint when nothing can be staged
This patch will make `git add -p` show "No changes." or "Only binary files changed." in that case. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
54d9d9b2ee
commit
2e4083198d
17
add-patch.c
17
add-patch.c
@ -44,7 +44,7 @@ struct add_p_state {
|
||||
struct hunk head;
|
||||
struct hunk *hunk;
|
||||
size_t hunk_nr, hunk_alloc;
|
||||
unsigned deleted:1, mode_change:1;
|
||||
unsigned deleted:1, mode_change:1,binary:1;
|
||||
} *file_diff;
|
||||
size_t file_diff_nr;
|
||||
};
|
||||
@ -294,7 +294,9 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
|
||||
BUG("'new mode' does not immediately follow "
|
||||
"'old mode'?\n\n%.*s",
|
||||
(int)(eol - plain->buf), plain->buf);
|
||||
}
|
||||
} else if (hunk == &file_diff->head &&
|
||||
starts_with(p, "Binary files "))
|
||||
file_diff->binary = 1;
|
||||
|
||||
if (file_diff->deleted && file_diff->mode_change)
|
||||
BUG("diff contains delete *and* a mode change?!?\n%.*s",
|
||||
@ -1304,7 +1306,7 @@ int run_add_p(struct repository *r, const struct pathspec *ps)
|
||||
struct add_p_state s = {
|
||||
{ r }, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
|
||||
};
|
||||
size_t i;
|
||||
size_t i, binary_count = 0;
|
||||
|
||||
init_add_i_state(&s.s, r);
|
||||
|
||||
@ -1318,9 +1320,16 @@ int run_add_p(struct repository *r, const struct pathspec *ps)
|
||||
}
|
||||
|
||||
for (i = 0; i < s.file_diff_nr; i++)
|
||||
if (patch_update_file(&s, s.file_diff + i))
|
||||
if (s.file_diff[i].binary && !s.file_diff[i].hunk_nr)
|
||||
binary_count++;
|
||||
else if (patch_update_file(&s, s.file_diff + i))
|
||||
break;
|
||||
|
||||
if (s.file_diff_nr == 0)
|
||||
fprintf(stderr, _("No changes.\n"));
|
||||
else if (binary_count == s.file_diff_nr)
|
||||
fprintf(stderr, _("Only binary files changed.\n"));
|
||||
|
||||
strbuf_release(&s.answer);
|
||||
strbuf_release(&s.buf);
|
||||
strbuf_release(&s.plain);
|
||||
|
Loading…
Reference in New Issue
Block a user