提交 37d07f8f 编写于 作者: J Junio C Hamano

git-commit: squelch needless message during an empty merge

When recording a merge that conflicted and ends up in no changes after
manual resolution, commit callchain looked like this:

	cmd_commit() ->
            prepare_log_message() ->
                run_status() ->
		    wt_status_print()

This invocation of run_status() is asked to find out if there is a
committable change, but it unconditionally gave instructions such as
"use git-add" at the same time.  When in merge, we do allow an empty
change to be recorded, so after showing this message the code still went
ahead and made a commit.

This introduces "nowarn" parameter to run_status() to avoid these
useless messages.  If we are not allowed to create an empty commit, we
already call run_status() again in the original codepath, and the
message will be shown from that call anyway.
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 1e8df762
...@@ -280,7 +280,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix) ...@@ -280,7 +280,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
return false_lock.filename; return false_lock.filename;
} }
static int run_status(FILE *fp, const char *index_file, const char *prefix) static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn)
{ {
struct wt_status s; struct wt_status s;
...@@ -296,6 +296,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix) ...@@ -296,6 +296,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix)
s.untracked = untracked_files; s.untracked = untracked_files;
s.index_file = index_file; s.index_file = index_file;
s.fp = fp; s.fp = fp;
s.nowarn = nowarn;
wt_status_print(&s); wt_status_print(&s);
...@@ -412,7 +413,7 @@ static int prepare_log_message(const char *index_file, const char *prefix) ...@@ -412,7 +413,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)
saved_color_setting = wt_status_use_color; saved_color_setting = wt_status_use_color;
wt_status_use_color = 0; wt_status_use_color = 0;
commitable = run_status(fp, index_file, prefix); commitable = run_status(fp, index_file, prefix, 1);
wt_status_use_color = saved_color_setting; wt_status_use_color = saved_color_setting;
fclose(fp); fclose(fp);
...@@ -606,7 +607,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) ...@@ -606,7 +607,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
index_file = prepare_index(argc, argv, prefix); index_file = prepare_index(argc, argv, prefix);
commitable = run_status(stdout, index_file, prefix); commitable = run_status(stdout, index_file, prefix, 0);
rollback_index_files(); rollback_index_files();
...@@ -717,7 +718,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) ...@@ -717,7 +718,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
if (!prepare_log_message(index_file, prefix) && !in_merge && if (!prepare_log_message(index_file, prefix) && !in_merge &&
!allow_empty && !(amend && is_a_merge(head_sha1))) { !allow_empty && !(amend && is_a_merge(head_sha1))) {
run_status(stdout, index_file, prefix); run_status(stdout, index_file, prefix, 0);
rollback_index_files(); rollback_index_files();
unlink(commit_editmsg); unlink(commit_editmsg);
return 1; return 1;
......
...@@ -381,6 +381,8 @@ void wt_status_print(struct wt_status *s) ...@@ -381,6 +381,8 @@ void wt_status_print(struct wt_status *s)
if (!s->commitable) { if (!s->commitable) {
if (s->amend) if (s->amend)
fprintf(s->fp, "# No changes\n"); fprintf(s->fp, "# No changes\n");
else if (s->nowarn)
; /* nothing */
else if (s->workdir_dirty) else if (s->workdir_dirty)
printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"); printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
else if (s->workdir_untracked) else if (s->workdir_untracked)
......
...@@ -17,6 +17,7 @@ struct wt_status { ...@@ -17,6 +17,7 @@ struct wt_status {
int verbose; int verbose;
int amend; int amend;
int untracked; int untracked;
int nowarn;
/* These are computed during processing of the individual sections */ /* These are computed during processing of the individual sections */
int commitable; int commitable;
int workdir_dirty; int workdir_dirty;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册