Merge branch 'jk/maint-advice-empty-amend' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 22 Jun 2010 16:31:48 +0000 (09:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 Jun 2010 16:31:48 +0000 (09:31 -0700)
* jk/maint-advice-empty-amend:
commit: give advice on empty amend

1  2 
builtin/commit.c
diff --combined builtin/commit.c
index b71d8f62d119393c54fbff9fdac70c68509f15b7,216ecc91d18457aad91156bde46dfe669dbb828b..9d59af034423142e45218b072c24e8c9bf77c43b
@@@ -48,6 -48,11 +48,11 @@@ static const char implicit_ident_advice
  "\n"
  "    git commit --amend --author='Your Name <you@example.com>'\n";
  
+ static const char empty_amend_advice[] =
+ "You asked to amend the most recent commit, but doing so would make\n"
+ "it empty. You can repeat your command with --allow-empty, or you can\n"
+ "remove the commit entirely with \"git reset HEAD^\".\n";
  static unsigned char head_sha1[20];
  
  static char *use_message_buffer;
@@@ -455,21 -460,15 +460,21 @@@ static void determine_author_info(void
                if (!a)
                        die("invalid commit: %s", use_message);
  
 -              lb = strstr(a + 8, " <");
 -              rb = strstr(a + 8, "> ");
 -              eol = strchr(a + 8, '\n');
 -              if (!lb || !rb || !eol)
 +              lb = strchrnul(a + strlen("\nauthor "), '<');
 +              rb = strchrnul(lb, '>');
 +              eol = strchrnul(rb, '\n');
 +              if (!*lb || !*rb || !*eol)
                        die("invalid commit: %s", use_message);
  
 -              name = xstrndup(a + 8, lb - (a + 8));
 -              email = xstrndup(lb + 2, rb - (lb + 2));
 -              date = xstrndup(rb + 2, eol - (rb + 2));
 +              if (lb == a + strlen("\nauthor "))
 +                      /* \nauthor <foo@example.com> */
 +                      name = xcalloc(1, 1);
 +              else
 +                      name = xmemdupz(a + strlen("\nauthor "),
 +                                      (lb - strlen(" ") -
 +                                       (a + strlen("\nauthor "))));
 +              email = xmemdupz(lb + strlen("<"), rb - (lb + strlen("<")));
 +              date = xmemdupz(rb + strlen("> "), eol - (rb + strlen("> ")));
        }
  
        if (force_author) {
@@@ -699,6 -698,8 +704,8 @@@ static int prepare_to_commit(const cha
        if (!commitable && !in_merge && !allow_empty &&
            !(amend && is_a_merge(head_sha1))) {
                run_status(stdout, index_file, prefix, 0, s);
+               if (amend)
+                       fputs(empty_amend_advice, stderr);
                return 0;
        }
  
@@@ -1023,7 -1024,6 +1030,7 @@@ static int git_status_config(const cha
  int cmd_status(int argc, const char **argv, const char *prefix)
  {
        struct wt_status s;
 +      int fd;
        unsigned char sha1[20];
        static struct option builtin_status_options[] = {
                OPT__VERBOSE(&verbose),
  
        read_cache_preload(s.pathspec);
        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);
 +
 +      fd = hold_locked_index(&index_lock, 0);
 +      if (0 <= fd) {
 +              if (!write_cache(fd, active_cache, active_nr))
 +                      commit_locked_index(&index_lock);
 +              rollback_lock_file(&index_lock);
 +      }
 +
        s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
        s.in_merge = in_merge;
        wt_status_collect(&s);
@@@ -1153,11 -1145,13 +1160,11 @@@ static void print_summary(const char *p
                initial_commit ? " (root-commit)" : "");
  
        if (!log_tree_commit(&rev, commit)) {
 -              struct pretty_print_context ctx = {0};
 -              struct strbuf buf = STRBUF_INIT;
 -              ctx.date_mode = DATE_NORMAL;
 -              format_commit_message(commit, format.buf + 7, &buf, &ctx);
 -              printf("%s\n", buf.buf);
 -              strbuf_release(&buf);
 +              rev.always_show_header = 1;
 +              rev.use_terminator = 1;
 +              log_tree_commit(&rev, commit);
        }
 +
        strbuf_release(&format);
  }