Code

t7800-difftool.sh: Simplify the --extcmd test
[git.git] / builtin-commit.c
index d525b894ec1211476707acb06bdebe25d5828dbb..f54772f74a14e480ae978b38ce3bcd49ee994411 100644 (file)
@@ -51,7 +51,7 @@ static const char *template_file;
 static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, no_verify, allow_empty, dry_run;
+static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
 static char *untracked_files_arg;
 /*
  * The default commit message cleanup mode will remove the lines
@@ -91,8 +91,9 @@ static struct option builtin_commit_options[] = {
        OPT_FILENAME('F', "file", &logfile, "read log from file"),
        OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
        OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
-       OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit "),
+       OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit"),
        OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
+       OPT_BOOLEAN(0, "reset-author", &renew_authorship, "the commit is authored by me now (used with -C-c/--amend)"),
        OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
        OPT_FILENAME('t', "template", &template_file, "use specified template file"),
        OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
@@ -381,7 +382,7 @@ static void determine_author_info(void)
        email = getenv("GIT_AUTHOR_EMAIL");
        date = getenv("GIT_AUTHOR_DATE");
 
-       if (use_message) {
+       if (use_message && !renew_authorship) {
                const char *a, *lb, *rb, *eol;
 
                a = strstr(use_message_buffer, "\nauthor ");
@@ -747,6 +748,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
        if (force_author && !strchr(force_author, '>'))
                force_author = find_author_by_nickname(force_author);
 
+       if (force_author && renew_authorship)
+               die("Using both --reset-author and --author does not make sense");
+
        if (logfile || message.len || use_message)
                use_editor = 0;
        if (edit_flag)
@@ -780,6 +784,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
                use_message = edit_message;
        if (amend && !use_message)
                use_message = "HEAD";
+       if (!use_message && renew_authorship)
+               die("--reset-author can be used only with -C, -c or --amend.");
        if (use_message) {
                unsigned char sha1[20];
                static char utf8[] = "UTF-8";
@@ -884,7 +890,7 @@ static int parse_status_slot(const char *var, int offset)
                return WT_STATUS_NOBRANCH;
        if (!strcasecmp(var+offset, "unmerged"))
                return WT_STATUS_UNMERGED;
-       die("bad config variable '%s'", var);
+       return -1;
 }
 
 static int git_status_config(const char *k, const char *v, void *cb)
@@ -904,6 +910,8 @@ static int git_status_config(const char *k, const char *v, void *cb)
        }
        if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
                int slot = parse_status_slot(k, 13);
+               if (slot < 0)
+                       return 0;
                if (!v)
                        return config_error_nonbool(k);
                color_parse(v, k, s->color_palette[slot]);
@@ -999,7 +1007,7 @@ static int git_commit_config(const char *k, const char *v, void *cb)
        struct wt_status *s = cb;
 
        if (!strcmp(k, "commit.template"))
-               return git_config_string(&template_file, k, v);
+               return git_config_pathname(&template_file, k, v);
 
        return git_status_config(k, v, s);
 }