@matheusbsbs / matheus-bagliano / commits / 37d07f8f98
Fork 0

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: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 12, 2007 at 19:09 UTC 37d07f8f9841a29cb53a1eda6acd3804c957f0e3
3 files changed +8 -4
builtin-commit.c
+5 -4
@@ -280,7 +280,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
280 return false_lock.filename;
281 }
282
283 -static int run_status(FILE *fp, const char *index_file, const char *prefix)
283 +static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn)
284 {
285 struct wt_status s;
286
@@ -296,6 +296,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix)
296 s.untracked = untracked_files;
297 s.index_file = index_file;
298 s.fp = fp;
299 + s.nowarn = nowarn;
300
301 wt_status_print(&s);
302
@@ -412,7 +413,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)
413
414 saved_color_setting = wt_status_use_color;
415 wt_status_use_color = 0;
415 - commitable = run_status(fp, index_file, prefix);
416 + commitable = run_status(fp, index_file, prefix, 1);
417 wt_status_use_color = saved_color_setting;
418
419 fclose(fp);
@@ -606,7 +607,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
607
608 index_file = prepare_index(argc, argv, prefix);
609
609 - commitable = run_status(stdout, index_file, prefix);
610 + commitable = run_status(stdout, index_file, prefix, 0);
611
612 rollback_index_files();
613
@@ -717,7 +718,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
718
719 if (!prepare_log_message(index_file, prefix) && !in_merge &&
720 !allow_empty && !(amend && is_a_merge(head_sha1))) {
720 - run_status(stdout, index_file, prefix);
721 + run_status(stdout, index_file, prefix, 0);
722 rollback_index_files();
723 unlink(commit_editmsg);
724 return 1;
wt-status.c
+2
@@ -381,6 +381,8 @@ void wt_status_print(struct wt_status *s)
381 if (!s->commitable) {
382 if (s->amend)
383 fprintf(s->fp, "# No changes\n");
384 + else if (s->nowarn)
385 + ; /* nothing */
386 else if (s->workdir_dirty)
387 printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
388 else if (s->workdir_untracked)
wt-status.h
+1
@@ -17,6 +17,7 @@ struct wt_status {
17 int verbose;
18 int amend;
19 int untracked;
20 + int nowarn;
21 /* These are computed during processing of the individual sections */
22 int commitable;
23 int workdir_dirty;