diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2019-12-13 11:08:06 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-12-13 23:37:14 +0300 |
commit | 2e4083198d1508206488af4c82093ceb6cf20f4e (patch) | |
tree | 2e575d9eb7ba691a96efd9be918f9e4f214219c3 | |
parent | 54d9d9b2eebe1c8f8b54626f98a5e1414ce766ba (diff) |
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>
-rw-r--r-- | add-patch.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/add-patch.c b/add-patch.c index 1eb0ab97bb..2c46fe5b33 100644 --- a/add-patch.c +++ b/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); |