Merge branch 'ks/commit-abort-on-empty-message-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 21:33:44 +0000 (14:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 21:33:44 +0000 (14:33 -0700)
"git commit" when seeing an totally empty message said "you did not
edit the message", which is clearly wrong. The message has been
corrected.

* ks/commit-abort-on-empty-message-fix:
commit: check for empty message before the check for untouched template

1  2 
builtin/commit.c
diff --combined builtin/commit.c
index 8e93802511e2a798e43d30da9218a56f97404dc7,9c299d792553cddd9e83b2182e3607c5527c53ce..1a0da71a43cfef8818b52a3d27131e340725cef2
@@@ -6,7 -6,6 +6,7 @@@
   */
  
  #include "cache.h"
 +#include "config.h"
  #include "lockfile.h"
  #include "cache-tree.h"
  #include "color.h"
@@@ -140,6 -139,7 +140,6 @@@ static enum commit_whence whence
  static int sequencer_in_use;
  static int use_editor = 1, include_status = 1;
  static int show_ignored_in_status, have_option_m;
 -static const char *only_include_assumed;
  static struct strbuf message = STRBUF_INIT;
  
  static enum wt_status_format status_format = STATUS_FORMAT_UNSPECIFIED;
@@@ -253,8 -253,7 +253,8 @@@ static int list_paths(struct string_lis
  
        if (with_tree) {
                char *max_prefix = common_prefix(pattern);
 -              overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
 +              overlay_tree_on_index(&the_index, with_tree,
 +                                    max_prefix ? max_prefix : prefix);
                free(max_prefix);
        }
  
@@@ -314,7 -313,7 +314,7 @@@ static void create_base_index(const str
        opts.dst_index = &the_index;
  
        opts.fn = oneway_merge;
 -      tree = parse_tree_indirect(current_head->object.oid.hash);
 +      tree = parse_tree_indirect(&current_head->object.oid);
        if (!tree)
                die(_("failed to unpack HEAD tree object"));
        parse_tree(tree);
@@@ -842,6 -841,9 +842,6 @@@ static int prepare_to_commit(const cha
                                  "with '%c' will be kept; you may remove them"
                                  " yourself if you want to.\n"
                                  "An empty message aborts the commit.\n"), comment_line_char);
 -              if (only_include_assumed)
 -                      status_printf_ln(s, GIT_COLOR_NORMAL,
 -                                      "%s", only_include_assumed);
  
                /*
                 * These should never fail because they come from our own
                                (int)(ci.name_end - ci.name_begin), ci.name_begin,
                                (int)(ci.mail_end - ci.mail_begin), ci.mail_begin);
  
 -              if (ident_shown)
 -                      status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
 +              status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); /* Add new line for clarity */
  
                saved_color_setting = s->use_color;
                s->use_color = 0;
@@@ -1205,6 -1208,8 +1205,6 @@@ static int parse_and_validate_options(i
                die(_("Only one of --include/--only/--all/--interactive/--patch can be used."));
        if (argc == 0 && (also || (only && !amend && !allow_empty)))
                die(_("No paths with --include/--only does not make sense."));
 -      if (argc > 0 && !also && !only)
 -              only_include_assumed = _("Explicit paths specified without -i or -o; assuming --only paths...");
        if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
                cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
        else if (!strcmp(cleanup_arg, "verbatim"))
@@@ -1258,10 -1263,6 +1258,10 @@@ static int parse_status_slot(const cha
                return WT_STATUS_NOBRANCH;
        if (!strcasecmp(slot, "unmerged"))
                return WT_STATUS_UNMERGED;
 +      if (!strcasecmp(slot, "localBranch"))
 +              return WT_STATUS_LOCAL_BRANCH;
 +      if (!strcasecmp(slot, "remoteBranch"))
 +              return WT_STATUS_REMOTE_BRANCH;
        return -1;
  }
  
@@@ -1290,10 -1291,6 +1290,10 @@@ static int git_status_config(const cha
                status_deferred_config.show_branch = git_config_bool(k, v);
                return 0;
        }
 +      if (!strcmp(k, "status.showstash")) {
 +              s->show_stash = git_config_bool(k, v);
 +              return 0;
 +      }
        if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
                s->use_color = git_config_colorbool(k, v);
                return 0;
@@@ -1342,8 -1339,6 +1342,8 @@@ int cmd_status(int argc, const char **a
                            N_("show status concisely"), STATUS_FORMAT_SHORT),
                OPT_BOOL('b', "branch", &s.show_branch,
                         N_("show branch information")),
 +              OPT_BOOL(0, "show-stash", &s.show_stash,
 +                       N_("show stash information")),
                { OPTION_CALLBACK, 0, "porcelain", &status_format,
                  N_("version"), N_("machine-readable output"),
                  PARSE_OPT_OPTARG, opt_parse_porcelain },
@@@ -1435,7 -1430,7 +1435,7 @@@ static void print_summary(const char *p
        struct strbuf author_ident = STRBUF_INIT;
        struct strbuf committer_ident = STRBUF_INIT;
  
 -      commit = lookup_commit(oid->hash);
 +      commit = lookup_commit(oid);
        if (!commit)
                die(_("couldn't look up newly created commit"));
        if (parse_commit(commit))
@@@ -1653,14 -1648,13 +1653,14 @@@ int cmd_commit(int argc, const char **a
                usage_with_options(builtin_commit_usage, builtin_commit_options);
  
        status_init_config(&s, git_commit_config);
 +      s.commit_template = 1;
        status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
        s.colopts = 0;
  
        if (get_sha1("HEAD", oid.hash))
                current_head = NULL;
        else {
 -              current_head = lookup_commit_or_die(oid.hash, "HEAD");
 +              current_head = lookup_commit_or_die(&oid, "HEAD");
                if (parse_commit(current_head))
                        die(_("could not parse HEAD commit"));
        }
                if (!reflog_msg)
                        reflog_msg = "commit (merge)";
                pptr = commit_list_append(current_head, pptr);
 -              fp = fopen(git_path_merge_head(), "r");
 -              if (fp == NULL)
 -                      die_errno(_("could not open '%s' for reading"),
 -                                git_path_merge_head());
 +              fp = xfopen(git_path_merge_head(), "r");
                while (strbuf_getline_lf(&m, fp) != EOF) {
                        struct commit *parent;
  
        if (verbose || /* Truncate the message just before the diff, if any. */
            cleanup_mode == CLEANUP_SCISSORS)
                strbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len));
        if (cleanup_mode != CLEANUP_NONE)
                strbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);
-       if (template_untouched(&sb) && !allow_empty_message) {
+       if (message_is_empty(&sb) && !allow_empty_message) {
                rollback_index_files();
-               fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
+               fprintf(stderr, _("Aborting commit due to empty commit message.\n"));
                exit(1);
        }
-       if (message_is_empty(&sb) && !allow_empty_message) {
+       if (template_untouched(&sb) && !allow_empty_message) {
                rollback_index_files();
-               fprintf(stderr, _("Aborting commit due to empty commit message.\n"));
+               fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
                exit(1);
        }
  
                append_merge_tag_headers(parents, &tail);
        }
  
 -      if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,
 +      if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash,
                         parents, oid.hash, author_ident.buf, sign_commit, extra)) {
                rollback_index_files();
                die(_("failed to write commit object"));
                cfg = init_copy_notes_for_rewrite("amend");
                if (cfg) {
                        /* we are amending, so current_head is not NULL */
 -                      copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash);
 +                      copy_note_for_rewrite(cfg, &current_head->object.oid, &oid);
                        finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
                }
                run_rewrite_hook(&current_head->object.oid, &oid);