]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/commit.c
Sync with maint
[thirdparty/git.git] / builtin / commit.c
index 294dc574cdda59f85e07a136ef1807f18710da3f..aa1332308a243802f2fb8bc98d276fd66510949b 100644 (file)
@@ -107,9 +107,9 @@ static int all, also, interactive, patch_interactive, only, amend, signoff;
 static int edit_flag = -1; /* unspecified */
 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
 static int config_commit_verbose = -1; /* unspecified */
-static int no_post_rewrite, allow_empty_message;
+static int no_post_rewrite, allow_empty_message, pathspec_file_nul;
 static char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
-static char *sign_commit;
+static char *sign_commit, *pathspec_from_file;
 
 /*
  * The default commit message cleanup mode will remove the lines
@@ -343,6 +343,26 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
                       PATHSPEC_PREFER_FULL,
                       prefix, argv);
 
+       if (pathspec_from_file) {
+               if (interactive)
+                       die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
+
+               if (all)
+                       die(_("--pathspec-from-file with -a does not make sense"));
+
+               if (pathspec.nr)
+                       die(_("--pathspec-from-file is incompatible with pathspec arguments"));
+
+               parse_pathspec_file(&pathspec, 0,
+                                   PATHSPEC_PREFER_FULL,
+                                   prefix, pathspec_from_file, pathspec_file_nul);
+       } else if (pathspec_file_nul) {
+               die(_("--pathspec-file-nul requires --pathspec-from-file"));
+       }
+
+       if (!pathspec.nr && (also || (only && !amend && !allow_empty)))
+               die(_("No paths with --include/--only does not make sense."));
+
        if (read_cache_preload(&pathspec) < 0)
                die(_("index file corrupt"));
 
@@ -537,7 +557,7 @@ static void export_one(const char *var, const char *s, const char *e, int hack)
        struct strbuf buf = STRBUF_INIT;
        if (hack)
                strbuf_addch(&buf, hack);
-       strbuf_addf(&buf, "%.*s", (int)(e - s), s);
+       strbuf_add(&buf, s, e - s);
        setenv(var, buf.buf, 1);
        strbuf_release(&buf);
 }
@@ -1198,8 +1218,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
 
        if (also + only + all + interactive > 1)
                die(_("Only one of --include/--only/--all/--interactive/--patch can be used."));
-       if (argc == 0 && (also || (only && !amend && !allow_empty)))
-               die(_("No paths with --include/--only does not make sense."));
        cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor);
 
        handle_untracked_files_arg(s);
@@ -1513,6 +1531,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "amend", &amend, N_("amend previous commit")),
                OPT_BOOL(0, "no-post-rewrite", &no_post_rewrite, N_("bypass post-rewrite hook")),
                { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, N_("mode"), N_("show untracked files, optional modes: all, normal, no. (Default: all)"), PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
+               OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
+               OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
                /* end commit contents options */
 
                OPT_HIDDEN_BOOL(0, "allow-empty", &allow_empty,