Skip to content

Commit 4368e40

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 546f822 commit 4368e40

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

contrib/scalar/scalar.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,15 @@ static char *remote_default_branch(const char *url)
327327
static int cmd_clone(int argc, const char **argv)
328328
{
329329
const char *branch = NULL;
330-
int full_clone = 0;
330+
int full_clone = 0, single_branch = 0;
331331
struct option clone_options[] = {
332332
OPT_STRING('b', "branch", &branch, N_("<branch>"),
333333
N_("branch to checkout after clone")),
334334
OPT_BOOL(0, "full-clone", &full_clone,
335335
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")),
336339
OPT_END(),
337340
};
338341
const char * const clone_usage[] = {
@@ -403,7 +406,9 @@ static int cmd_clone(int argc, const char **argv)
403406

404407
if (set_config("remote.origin.url=%s", url) ||
405408
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 : "*") ||
407412
set_config("remote.origin.promisor=true") ||
408413
set_config("remote.origin.partialCloneFilter=blob:none")) {
409414
res = error(_("could not configure remote in '%s'"), dir);

contrib/scalar/scalar.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ scalar - an opinionated repository management tool
88
SYNOPSIS
99
--------
1010
[verse]
11-
scalar clone [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
11+
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
1212
scalar list
1313
scalar register [<enlistment>]
1414
scalar unregister [<enlistment>]
@@ -57,6 +57,16 @@ HEAD[:<directory>]`.
5757
Instead of checking out the branch pointed to by the cloned
5858
repository's HEAD, check out the `<name>` branch instead.
5959

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+
6070
--[no-]full-clone::
6171
A sparse-checkout is initialized by default. This behavior can be
6272
turned off via `--full-clone`.

contrib/scalar/t/t9099-scalar.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ test_expect_success 'set up repository to clone' '
4545

4646
test_expect_success 'scalar clone' '
4747
second=$(git rev-parse --verify second:second.t) &&
48-
scalar clone "file://$(pwd)" cloned &&
48+
scalar clone "file://$(pwd)" cloned --single-branch &&
4949
(
5050
cd cloned/src &&
5151
5252
git config --get --global --fixed-value maintenance.repo \
5353
"$(pwd)" &&
5454
55+
git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
56+
echo "refs/remotes/origin/parallel" >expect &&
57+
test_cmp expect actual &&
58+
5559
test_path_is_missing 1/2 &&
5660
test_must_fail git rev-list --missing=print $second &&
5761
git rev-list $second &&

0 commit comments

Comments
 (0)