scalar: teach 'clone' to support the --single-branch option
Just like `git clone`, the `scalar clone` command now also offers to restrict the clone to a single branch. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 3, 2021 at 13:34 UTC
4368e40befd308d3055e81f8f6aaaa3fb8fe6407
3 files changed
+23
-4
contrib/scalar/scalar.c
+7
-2
@@ -327,12 +327,15 @@ static char *remote_default_branch(const char *url)
327
static int cmd_clone(int argc, const char **argv)
328
{
329
const char *branch = NULL;
330
- int full_clone = 0;
330
+ int full_clone = 0, single_branch = 0;
331
struct option clone_options[] = {
332
OPT_STRING('b', "branch", &branch, N_("<branch>"),
333
N_("branch to checkout after clone")),
334
OPT_BOOL(0, "full-clone", &full_clone,
335
N_("when cloning, create full working directory")),
336
+ OPT_BOOL(0, "single-branch", &single_branch,
337
+ N_("only download metadata for the branch that will "
338
+ "be checked out")),
339
OPT_END(),
340
};
341
const char * const clone_usage[] = {
@@ -403,7 +406,9 @@ static int cmd_clone(int argc, const char **argv)
406
407
if (set_config("remote.origin.url=%s", url) ||
408
set_config("remote.origin.fetch="
406
- "+refs/heads/*:refs/remotes/origin/*") ||
409
+ "+refs/heads/%s:refs/remotes/origin/%s",
410
+ single_branch ? branch : "*",
411
+ single_branch ? branch : "*") ||
412
set_config("remote.origin.promisor=true") ||
413
set_config("remote.origin.partialCloneFilter=blob:none")) {
414
res = error(_("could not configure remote in '%s'"), dir);
contrib/scalar/scalar.txt
+11
-1
@@ -8,7 +8,7 @@ scalar - an opinionated repository management tool
8
SYNOPSIS
9
--------
10
[verse]
11
-scalar clone [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
11
+scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
12
scalar list
13
scalar register [<enlistment>]
14
scalar unregister [<enlistment>]
@@ -57,6 +57,16 @@ HEAD[:<directory>]`.
57
Instead of checking out the branch pointed to by the cloned
58
repository's HEAD, check out the `<name>` branch instead.
59
60
+--[no-]single-branch::
61
+ Clone only the history leading to the tip of a single branch, either
62
+ specified by the `--branch` option or the primary branch remote's
63
+ `HEAD` points at.
64
++
65
+Further fetches into the resulting repository will only update the
66
+remote-tracking branch for the branch this option was used for the initial
67
+cloning. If the HEAD at the remote did not point at any branch when
68
+`--single-branch` clone was made, no remote-tracking branch is created.
69
+
70
--[no-]full-clone::
71
A sparse-checkout is initialized by default. This behavior can be
72
turned off via `--full-clone`.
contrib/scalar/t/t9099-scalar.sh
+5
-1
@@ -45,13 +45,17 @@ test_expect_success 'set up repository to clone' '
45
46
test_expect_success 'scalar clone' '
47
second=$(git rev-parse --verify second:second.t) &&
48
- scalar clone "file://$(pwd)" cloned &&
48
+ scalar clone "file://$(pwd)" cloned --single-branch &&
49
(
50
cd cloned/src &&
51
52
git config --get --global --fixed-value maintenance.repo \
53
"$(pwd)" &&
54
55
+ git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
56
+ echo "refs/remotes/origin/parallel" >expect &&
57
+ test_cmp expect actual &&
58
+
59
test_path_is_missing 1/2 &&
60
test_must_fail git rev-list --missing=print $second &&
61
git rev-list $second &&