Code

autoconf: Add link tests to each AC_CHECK_FUNC() test
[git.git] / builtin-commit.c
index a2755dc3befeb5ed768f692ee58e5147ad933e26..93ca49635731942c72cb52b27b1a6ba53becd1ca 100644 (file)
@@ -320,7 +320,9 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
                die("unable to write new_index file");
 
        fd = hold_lock_file_for_update(&false_lock,
-                                      git_path("next-index-%"PRIuMAX, (uintmax_t) getpid()), 1);
+                                      git_path("next-index-%"PRIuMAX,
+                                               (uintmax_t) getpid()),
+                                      LOCK_DIE_ON_ERROR);
 
        create_base_index();
        add_remove_files(&partial);
@@ -879,6 +881,9 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
 {
        struct rev_info rev;
        struct commit *commit;
+       static const char *format = "format:%h: \"%s\"";
+       unsigned char junk_sha1[20];
+       const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
 
        commit = lookup_commit(sha1);
        if (!commit)
@@ -896,18 +901,24 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
 
        rev.verbose_header = 1;
        rev.show_root_diff = 1;
-       get_commit_format("format:%h: %s", &rev);
+       get_commit_format(format, &rev);
        rev.always_show_header = 0;
        rev.diffopt.detect_rename = 1;
        rev.diffopt.rename_limit = 100;
        rev.diffopt.break_opt = 0;
        diff_setup_done(&rev.diffopt);
 
-       printf("Created %scommit ", initial_commit ? "initial " : "");
+       printf("[%s%s]: created ",
+               !prefixcmp(head, "refs/heads/") ?
+                       head + 11 :
+                       !strcmp(head, "HEAD") ?
+                               "detached HEAD" :
+                               head,
+               initial_commit ? " (root-commit)" : "");
 
        if (!log_tree_commit(&rev, commit)) {
                struct strbuf buf = STRBUF_INIT;
-               format_commit_message(commit, "%h: %s", &buf, DATE_NORMAL);
+               format_commit_message(commit, format + 7, &buf, DATE_NORMAL);
                printf("%s\n", buf.buf);
                strbuf_release(&buf);
        }
@@ -934,6 +945,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        unsigned char commit_sha1[20];
        struct ref_lock *ref_lock;
        struct commit_list *parents = NULL, **pptr = &parents;
+       struct stat statbuf;
+       int allow_fast_forward = 1;
 
        git_config(git_commit_config, NULL);
 
@@ -980,13 +993,22 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                }
                fclose(fp);
                strbuf_release(&m);
+               if (!stat(git_path("MERGE_MODE"), &statbuf)) {
+                       if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0)
+                               die("could not read MERGE_MODE: %s",
+                                               strerror(errno));
+                       if (!strcmp(sb.buf, "no-ff"))
+                               allow_fast_forward = 0;
+               }
+               if (allow_fast_forward)
+                       parents = reduce_heads(parents);
        } else {
                reflog_msg = "commit";
                pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
        }
-       parents = reduce_heads(parents);
 
        /* Finally, get the commit message */
+       strbuf_reset(&sb);
        if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
                rollback_index_files();
                die("could not read commit message");
@@ -1035,6 +1057,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
        unlink(git_path("MERGE_HEAD"));
        unlink(git_path("MERGE_MSG"));
+       unlink(git_path("MERGE_MODE"));
        unlink(git_path("SQUASH_MSG"));
 
        if (commit_index_files())