]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-commit.c
Open external merge tool with original file extensions for all three files
[git.git] / builtin-commit.c
index 6c1ace32a432825e4c630f572f0169b82784ecfb..2ec8223132807e1df77512d3d77efd71b790496a 100644 (file)
@@ -27,6 +27,11 @@ static const char * const builtin_commit_usage[] = {
        NULL
 };
 
+static const char * const builtin_status_usage[] = {
+       "git-status [options] [--] <filepattern>...",
+       NULL
+};
+
 static unsigned char head_sha1[20], merge_head_sha1[20];
 static char *use_message_buffer;
 static const char commit_editmsg[] = "COMMIT_EDITMSG";
@@ -41,7 +46,7 @@ static enum {
 static char *logfile, *force_author, *template_file;
 static char *edit_message, *use_message;
 static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, untracked_files, no_verify;
+static int quiet, verbose, untracked_files, no_verify, allow_empty;
 
 static int no_edit, initial_commit, in_merge;
 const char *only_include_assumed;
@@ -82,6 +87,7 @@ static struct option builtin_commit_options[] = {
        OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
        OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
        OPT_BOOLEAN(0, "untracked-files", &untracked_files, "show all untracked files"),
+       OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
 
        OPT_END()
 };
@@ -157,7 +163,7 @@ static void add_remove_files(struct path_list *list)
        }
 }
 
-static char *prepare_index(const char **files, const char *prefix)
+static char *prepare_index(int argc, const char **argv, const char *prefix)
 {
        int fd;
        struct tree *tree;
@@ -165,7 +171,7 @@ static char *prepare_index(const char **files, const char *prefix)
        const char **pathspec = NULL;
 
        if (interactive) {
-               interactive_add();
+               interactive_add(argc, argv, prefix);
                commit_style = COMMIT_AS_IS;
                return get_index_file();
        }
@@ -173,8 +179,8 @@ static char *prepare_index(const char **files, const char *prefix)
        if (read_cache() < 0)
                die("index file corrupt");
 
-       if (*files)
-               pathspec = get_pathspec(prefix, files);
+       if (*argv)
+               pathspec = get_pathspec(prefix, argv);
 
        /*
         * Non partial, non as-is commit.
@@ -346,11 +352,9 @@ static int prepare_log_message(const char *index_file, const char *prefix)
 
                strbuf_init(&sob, 0);
                strbuf_addstr(&sob, sign_off_header);
-               strbuf_addstr(&sob, fmt_ident(getenv("GIT_COMMITTER_NAME"),
-                                             getenv("GIT_COMMITTER_EMAIL"),
-                                             "", 1));
+               strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
+                                            getenv("GIT_COMMITTER_EMAIL")));
                strbuf_addch(&sob, '\n');
-
                for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
                        ; /* do nothing */
                if (prefixcmp(sb.buf + i, sob.buf)) {
@@ -495,12 +499,12 @@ static void determine_author_info(struct strbuf *sb)
        strbuf_addf(sb, "author %s\n", fmt_ident(name, email, date, 1));
 }
 
-static int parse_and_validate_options(int argc, const char *argv[])
+static int parse_and_validate_options(int argc, const char *argv[],
+                                     const char * const usage[])
 {
        int f = 0;
 
-       argc = parse_options(argc, argv, builtin_commit_options,
-                            builtin_commit_usage, 0);
+       argc = parse_options(argc, argv, builtin_commit_options, usage, 0);
 
        if (logfile || message.len || use_message)
                no_edit = 1;
@@ -597,9 +601,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        git_config(git_status_config);
 
-       argc = parse_and_validate_options(argc, argv);
+       argc = parse_and_validate_options(argc, argv, builtin_status_usage);
 
-       index_file = prepare_index(argv, prefix);
+       index_file = prepare_index(argc, argv, prefix);
 
        commitable = run_status(stdout, index_file, prefix);
 
@@ -673,6 +677,14 @@ int git_commit_config(const char *k, const char *v)
        return git_status_config(k, v);
 }
 
+static int is_a_merge(const unsigned char *sha1)
+{
+       struct commit *commit = lookup_commit(sha1);
+       if (!commit || parse_commit(commit))
+               die("could not parse HEAD commit");
+       return !!(commit->parents && commit->parents->next);
+}
+
 static const char commit_utf8_warn[] =
 "Warning: commit message does not conform to UTF-8.\n"
 "You may want to amend it after fixing the message, or set the config\n"
@@ -689,16 +701,17 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
        git_config(git_commit_config);
 
-       argc = parse_and_validate_options(argc, argv);
+       argc = parse_and_validate_options(argc, argv, builtin_commit_usage);
 
-       index_file = prepare_index(argv, prefix);
+       index_file = prepare_index(argc, argv, prefix);
 
        if (!no_verify && run_hook(index_file, "pre-commit", NULL)) {
                rollback_index_files();
                return 1;
        }
 
-       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))) {
                run_status(stdout, index_file, prefix);
                rollback_index_files();
                unlink(commit_editmsg);