Merge branch 'ah/doc-gitk-config'
[gitweb.git] / builtin / commit.c
index 26b2986abe679b594798748b4776917050b1bd4d..38f34e7cd3c7ffd482eb13fcf810346e1da4d944 100644 (file)
@@ -113,6 +113,7 @@ static char *sign_commit;
 static enum {
        CLEANUP_SPACE,
        CLEANUP_NONE,
+       CLEANUP_SCISSORS,
        CLEANUP_ALL
 } cleanup_mode;
 static const char *cleanup_arg;
@@ -307,7 +308,6 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
        int fd;
        struct string_list partial;
        struct pathspec pathspec;
-       char *old_index_env = NULL;
        int refresh_flags = REFRESH_QUIET;
 
        if (is_status)
@@ -320,6 +320,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
                die(_("index file corrupt"));
 
        if (interactive) {
+               char *old_index_env = NULL;
                fd = hold_locked_index(&index_lock, 1);
 
                refresh_cache_or_die(refresh_flags);
@@ -600,12 +601,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 {
        struct stat statbuf;
        struct strbuf committer_ident = STRBUF_INIT;
-       int commitable, saved_color_setting;
+       int commitable;
        struct strbuf sb = STRBUF_INIT;
-       char *buffer;
        const char *hook_arg1 = NULL;
        const char *hook_arg2 = NULL;
-       int ident_shown = 0;
        int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
        int old_display_comment_prefix;
 
@@ -649,6 +648,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                                  logfile);
                hook_arg1 = "message";
        } else if (use_message) {
+               char *buffer;
                buffer = strstr(use_message_buffer, "\n\n");
                if (!use_editor && (!buffer || buffer[2] == '\0'))
                        die(_("commit has empty message"));
@@ -753,8 +753,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        /* This checks if committer ident is explicitly given */
        strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));
        if (use_editor && include_status) {
+               int ident_shown = 0;
+               int saved_color_setting;
                char *ai_tmp, *ci_tmp;
-               if (whence != FROM_COMMIT)
+               if (whence != FROM_COMMIT) {
+                       if (cleanup_mode == CLEANUP_SCISSORS)
+                               wt_status_add_cut_line(s->fp);
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                            whence == FROM_MERGE
                                ? _("\n"
@@ -770,6 +774,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                                git_path(whence == FROM_MERGE
                                         ? "MERGE_HEAD"
                                         : "CHERRY_PICK_HEAD"));
+               }
 
                fprintf(s->fp, "\n");
                if (cleanup_mode == CLEANUP_ALL)
@@ -777,6 +782,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                                _("Please enter the commit message for your changes."
                                  " Lines starting\nwith '%c' will be ignored, and an empty"
                                  " message aborts the commit.\n"), comment_line_char);
+               else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
+                       wt_status_add_cut_line(s->fp);
                else /* CLEANUP_SPACE, that is. */
                        status_printf(s, GIT_COLOR_NORMAL,
                                _("Please enter the commit message for your changes."
@@ -1132,6 +1139,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
                cleanup_mode = CLEANUP_SPACE;
        else if (!strcmp(cleanup_arg, "strip"))
                cleanup_mode = CLEANUP_ALL;
+       else if (!strcmp(cleanup_arg, "scissors"))
+               cleanup_mode = use_editor ? CLEANUP_SCISSORS : CLEANUP_SPACE;
        else
                die(_("Invalid cleanup mode %s"), cleanup_arg);
 
@@ -1406,6 +1415,10 @@ static int git_commit_config(const char *k, const char *v, void *cb)
        }
        if (!strcmp(k, "commit.cleanup"))
                return git_config_string(&cleanup_arg, k, v);
+       if (!strcmp(k, "commit.gpgsign")) {
+               sign_commit = git_config_bool(k, v) ? "" : NULL;
+               return 0;
+       }
 
        status = git_gpg_config(k, v, NULL);
        if (status)
@@ -1510,7 +1523,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        struct ref_lock *ref_lock;
        struct commit_list *parents = NULL, **pptr = &parents;
        struct stat statbuf;
-       int allow_fast_forward = 1;
        struct commit *current_head = NULL;
        struct commit_extra_header *extra = NULL;
 
@@ -1558,6 +1570,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        } else if (whence == FROM_MERGE) {
                struct strbuf m = STRBUF_INIT;
                FILE *fp;
+               int allow_fast_forward = 1;
 
                if (!reflog_msg)
                        reflog_msg = "commit (merge)";
@@ -1600,8 +1613,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                die(_("could not read commit message: %s"), strerror(saved_errno));
        }
 
-       /* Truncate the message just before the diff, if any. */
-       if (verbose)
+       if (verbose || /* Truncate the message just before the diff, if any. */
+           cleanup_mode == CLEANUP_SCISSORS)
                wt_status_truncate_message_at_cut_line(&sb);
 
        if (cleanup_mode != CLEANUP_NONE)