From: Abhishek Agarwal <agab0323@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>,
Jacob Keller <jacob.keller@gmail.com>,
Adrian Ratiu <adrian.ratiu@collabora.com>
Subject: [PATCH 1/2] clone: reject a negative --jobs before cloning
Date: Wed, 2 Dec 2026 22:43:27 +0530 [thread overview]
Message-ID: <20261202171328.805150-2-agab0323@gmail.com> (raw)
In-Reply-To: <20261202171328.805150-1-agab0323@gmail.com>
"git clone --recurse-submodules --jobs=<n>" passes "--jobs=<n>" on to
"git submodule update", but only when <n> is not -1, because max_jobs
starts at -1 to mean that the option was not given. So "--jobs=-1" is
dropped without a word and the submodules are fetched with the default
number of jobs, while "--jobs=-2" is passed on and rejected by
"submodule update". That happens only after the superproject has been
cloned, so the user waits for the whole clone and is left with one
whose submodules are not checked out.
Parse the option with a callback that rejects a negative value, like
"git submodule update --jobs" and "submodule.fetchJobs" already do.
The error now comes before anything is cloned, and -1 can again only
mean that the option was not given. "--no-jobs" still means the same
as "--jobs=0". A value that is not a number is still rejected, now
with the "invalid value for" message that other options already use.
Reported-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Abhishek Agarwal <agab0323@gmail.com>
---
builtin/clone.c | 18 ++++++++++++++++--
t/t7406-submodule-update.sh | 10 ++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index ac40250d25..f9ecbede1b 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -94,6 +94,19 @@ static int recurse_submodules_cb(const struct option *opt,
return 0;
}
+static int parse_jobs_cb(const struct option *opt, const char *arg, int unset)
+{
+ int *jobs = opt->value;
+
+ if (unset)
+ *jobs = 0;
+ else if (!git_parse_int(arg, jobs))
+ return error(_("invalid value for '%s': '%s'"), "--jobs", arg);
+ else if (*jobs < 0)
+ return error(_("'%s' cannot be negative"), "--jobs");
+ return 0;
+}
+
static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
{
static const char *suffix[] = { "/.git", "", ".git/.git", ".git" };
@@ -949,8 +962,9 @@ int cmd_clone(int argc,
.defval = (intptr_t)".",
},
OPT_ALIAS(0, "recursive", "recurse-submodules"),
- OPT_INTEGER('j', "jobs", &max_jobs,
- N_("number of submodules cloned in parallel")),
+ OPT_CALLBACK('j', "jobs", &max_jobs, N_("n"),
+ N_("number of submodules cloned in parallel"),
+ parse_jobs_cb),
OPT_STRING(0, "template", &option_template, N_("template-directory"),
N_("directory from which templates will be used")),
OPT_STRING_LIST(0, "reference", &option_required_reference, N_("repo"),
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 2b5551044a..7a440709aa 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1116,6 +1116,16 @@ test_expect_success 'git clone --recurse-submodules --jobs 0 uses the number of
test_grep "up to $(test-tool online-cpus) tasks" trace-jobs.out
'
+test_expect_success 'git clone --recurse-submodules rejects a negative --jobs' '
+ test_when_finished "rm -rf super6" &&
+ for jobs in -1 -2
+ do
+ test_must_fail git clone --recurse-submodules --jobs $jobs . super6 2>err &&
+ test_grep "${SQ}--jobs${SQ} cannot be negative" err &&
+ test_path_is_missing super6 || return 1
+ done
+'
+
test_expect_success 'submodule update --quiet passes quietness to merge/rebase' '
(cd super &&
test_commit -C rebasing message &&
--
2.56.0
next prev parent reply other threads:[~2026-12-02 17:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 17:13 [PATCH 0/2] clone, fetch: reject a negative --jobs Abhishek Agarwal
2026-12-02 17:13 ` Abhishek Agarwal [this message]
2026-12-02 17:13 ` [PATCH 2/2] " Abhishek Agarwal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202171328.805150-2-agab0323@gmail.com \
--to=agab0323@gmail.com \
--cc=adrian.ratiu@collabora.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox