]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-commit.c
Merge branch 'master' into cc/help
[git.git] / builtin-commit.c
index e635d9963b6ff6ade7742e801bc1cb0583059027..b6b81d531d8b560315298353e5b0ae377581c566 100644 (file)
@@ -163,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;
@@ -171,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();
        }
@@ -179,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.
@@ -285,7 +285,8 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix)
        struct wt_status s;
 
        wt_status_prepare(&s);
-       s.prefix = prefix;
+       if (wt_status_relative_paths)
+               s.prefix = prefix;
 
        if (amend) {
                s.amend = 1;
@@ -496,7 +497,7 @@ static void determine_author_info(struct strbuf *sb)
                email = xstrndup(lb + 2, rb - (lb + 2));
        }
 
-       strbuf_addf(sb, "author %s\n", fmt_ident(name, email, date, 1));
+       strbuf_addf(sb, "author %s\n", fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME));
 }
 
 static int parse_and_validate_options(int argc, const char *argv[],
@@ -603,7 +604,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        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);
 
@@ -703,7 +704,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
        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();
@@ -775,7 +776,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        }
 
        determine_author_info(&sb);
-       strbuf_addf(&sb, "committer %s\n", git_committer_info(1));
+       strbuf_addf(&sb, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
        if (!is_encoding_utf8(git_commit_encoding))
                strbuf_addf(&sb, "encoding %s\n", git_commit_encoding);
        strbuf_addch(&sb, '\n');
@@ -786,15 +787,17 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                char index[PATH_MAX];
                const char *env[2] = { index, NULL };
                snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
-               launch_editor(git_path(commit_editmsg), &sb, env);
-       } else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
-               rollback_index_files();
-               die("could not read commit message");
+               launch_editor(git_path(commit_editmsg), NULL, env);
        }
-       if (run_hook(index_file, "commit-msg", git_path(commit_editmsg))) {
+       if (!no_verify &&
+           run_hook(index_file, "commit-msg", git_path(commit_editmsg))) {
                rollback_index_files();
                exit(1);
        }
+       if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
+               rollback_index_files();
+               die("could not read commit message");
+       }
 
        /* Truncate the message just before the diff, if any. */
        p = strstr(sb.buf, "\ndiff --git a/");