]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/commit.c
Merge branch 'gt/add-u-commit-i-pathspec-check'
[thirdparty/git.git] / builtin / commit.c
index b27b56c8bef3ea0c968392095519017151709ca2..6e1484446b0cc2c98ccade5f8285ad81747c6416 100644 (file)
@@ -441,16 +441,21 @@ static const char *prepare_index(const char **argv, const char *prefix,
         * (B) on failure, rollback the real index.
         */
        if (all || (also && pathspec.nr)) {
+               char *ps_matched = xcalloc(pathspec.nr, 1);
                repo_hold_locked_index(the_repository, &index_lock,
                                       LOCK_DIE_ON_ERROR);
                add_files_to_cache(the_repository, also ? prefix : NULL,
-                                  &pathspec, 0, 0);
+                                  &pathspec, ps_matched, 0, 0);
+               if (!all && report_path_error(ps_matched, &pathspec))
+                       exit(128);
+
                refresh_cache_or_die(refresh_flags);
                cache_tree_update(&the_index, WRITE_TREE_SILENT);
                if (write_locked_index(&the_index, &index_lock, 0))
                        die(_("unable to write new index file"));
                commit_style = COMMIT_NORMAL;
                ret = get_lock_file_path(&index_lock);
+               free(ps_matched);
                goto out;
        }
 
@@ -685,9 +690,10 @@ static void adjust_comment_line_char(const struct strbuf *sb)
        char *candidate;
        const char *p;
 
-       comment_line_char = candidates[0];
-       if (!memchr(sb->buf, comment_line_char, sb->len))
+       if (!memchr(sb->buf, candidates[0], sb->len)) {
+               comment_line_str = xstrfmt("%c", candidates[0]);
                return;
+       }
 
        p = sb->buf;
        candidate = strchr(candidates, *p);
@@ -706,7 +712,7 @@ static void adjust_comment_line_char(const struct strbuf *sb)
        if (!*p)
                die(_("unable to select a comment character that is not used\n"
                      "in the current commit message"));
-       comment_line_char = *p;
+       comment_line_str = xstrfmt("%c", *p);
 }
 
 static void prepare_amend_commit(struct commit *commit, struct strbuf *sb,
@@ -889,7 +895,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        s->hints = 0;
 
        if (clean_message_contents)
-               strbuf_stripspace(&sb, '\0');
+               strbuf_stripspace(&sb, NULL);
 
        if (signoff)
                append_signoff(&sb, ignored_log_message_bytes(sb.buf, sb.len), 0);
@@ -909,18 +915,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                struct ident_split ci, ai;
                const char *hint_cleanup_all = allow_empty_message ?
                        _("Please enter the commit message for your changes."
-                         " Lines starting\nwith '%c' will be ignored.\n") :
+                         " Lines starting\nwith '%s' will be ignored.\n") :
                        _("Please enter the commit message for your changes."
-                         " Lines starting\nwith '%c' will be ignored, and an empty"
+                         " Lines starting\nwith '%s' will be ignored, and an empty"
                          " message aborts the commit.\n");
                const char *hint_cleanup_space = allow_empty_message ?
                        _("Please enter the commit message for your changes."
                          " Lines starting\n"
-                         "with '%c' will be kept; you may remove them"
+                         "with '%s' will be kept; you may remove them"
                          " yourself if you want to.\n") :
                        _("Please enter the commit message for your changes."
                          " Lines starting\n"
-                         "with '%c' will be kept; you may remove them"
+                         "with '%s' will be kept; you may remove them"
                          " yourself if you want to.\n"
                          "An empty message aborts the commit.\n");
                if (whence != FROM_COMMIT) {
@@ -943,12 +949,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 
                fprintf(s->fp, "\n");
                if (cleanup_mode == COMMIT_MSG_CLEANUP_ALL)
-                       status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_char);
+                       status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_str);
                else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
                        if (whence == FROM_COMMIT)
                                wt_status_add_cut_line(s);
                } else /* COMMIT_MSG_CLEANUP_SPACE, that is. */
-                       status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_char);
+                       status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_str);
 
                /*
                 * These should never fail because they come from our own