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>
This commit is contained in:
parent
546f822d53
commit
4368e40bef
@ -327,12 +327,15 @@ static char *remote_default_branch(const char *url)
|
|||||||
static int cmd_clone(int argc, const char **argv)
|
static int cmd_clone(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
const char *branch = NULL;
|
const char *branch = NULL;
|
||||||
int full_clone = 0;
|
int full_clone = 0, single_branch = 0;
|
||||||
struct option clone_options[] = {
|
struct option clone_options[] = {
|
||||||
OPT_STRING('b', "branch", &branch, N_("<branch>"),
|
OPT_STRING('b', "branch", &branch, N_("<branch>"),
|
||||||
N_("branch to checkout after clone")),
|
N_("branch to checkout after clone")),
|
||||||
OPT_BOOL(0, "full-clone", &full_clone,
|
OPT_BOOL(0, "full-clone", &full_clone,
|
||||||
N_("when cloning, create full working directory")),
|
N_("when cloning, create full working directory")),
|
||||||
|
OPT_BOOL(0, "single-branch", &single_branch,
|
||||||
|
N_("only download metadata for the branch that will "
|
||||||
|
"be checked out")),
|
||||||
OPT_END(),
|
OPT_END(),
|
||||||
};
|
};
|
||||||
const char * const clone_usage[] = {
|
const char * const clone_usage[] = {
|
||||||
@ -403,7 +406,9 @@ static int cmd_clone(int argc, const char **argv)
|
|||||||
|
|
||||||
if (set_config("remote.origin.url=%s", url) ||
|
if (set_config("remote.origin.url=%s", url) ||
|
||||||
set_config("remote.origin.fetch="
|
set_config("remote.origin.fetch="
|
||||||
"+refs/heads/*:refs/remotes/origin/*") ||
|
"+refs/heads/%s:refs/remotes/origin/%s",
|
||||||
|
single_branch ? branch : "*",
|
||||||
|
single_branch ? branch : "*") ||
|
||||||
set_config("remote.origin.promisor=true") ||
|
set_config("remote.origin.promisor=true") ||
|
||||||
set_config("remote.origin.partialCloneFilter=blob:none")) {
|
set_config("remote.origin.partialCloneFilter=blob:none")) {
|
||||||
res = error(_("could not configure remote in '%s'"), dir);
|
res = error(_("could not configure remote in '%s'"), dir);
|
||||||
|
@ -8,7 +8,7 @@ scalar - an opinionated repository management tool
|
|||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
[verse]
|
[verse]
|
||||||
scalar clone [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
|
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
|
||||||
scalar list
|
scalar list
|
||||||
scalar register [<enlistment>]
|
scalar register [<enlistment>]
|
||||||
scalar unregister [<enlistment>]
|
scalar unregister [<enlistment>]
|
||||||
@ -57,6 +57,16 @@ HEAD[:<directory>]`.
|
|||||||
Instead of checking out the branch pointed to by the cloned
|
Instead of checking out the branch pointed to by the cloned
|
||||||
repository's HEAD, check out the `<name>` branch instead.
|
repository's HEAD, check out the `<name>` branch instead.
|
||||||
|
|
||||||
|
--[no-]single-branch::
|
||||||
|
Clone only the history leading to the tip of a single branch, either
|
||||||
|
specified by the `--branch` option or the primary branch remote's
|
||||||
|
`HEAD` points at.
|
||||||
|
+
|
||||||
|
Further fetches into the resulting repository will only update the
|
||||||
|
remote-tracking branch for the branch this option was used for the initial
|
||||||
|
cloning. If the HEAD at the remote did not point at any branch when
|
||||||
|
`--single-branch` clone was made, no remote-tracking branch is created.
|
||||||
|
|
||||||
--[no-]full-clone::
|
--[no-]full-clone::
|
||||||
A sparse-checkout is initialized by default. This behavior can be
|
A sparse-checkout is initialized by default. This behavior can be
|
||||||
turned off via `--full-clone`.
|
turned off via `--full-clone`.
|
||||||
|
@ -45,13 +45,17 @@ test_expect_success 'set up repository to clone' '
|
|||||||
|
|
||||||
test_expect_success 'scalar clone' '
|
test_expect_success 'scalar clone' '
|
||||||
second=$(git rev-parse --verify second:second.t) &&
|
second=$(git rev-parse --verify second:second.t) &&
|
||||||
scalar clone "file://$(pwd)" cloned &&
|
scalar clone "file://$(pwd)" cloned --single-branch &&
|
||||||
(
|
(
|
||||||
cd cloned/src &&
|
cd cloned/src &&
|
||||||
|
|
||||||
git config --get --global --fixed-value maintenance.repo \
|
git config --get --global --fixed-value maintenance.repo \
|
||||||
"$(pwd)" &&
|
"$(pwd)" &&
|
||||||
|
|
||||||
|
git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
|
||||||
|
echo "refs/remotes/origin/parallel" >expect &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
test_path_is_missing 1/2 &&
|
test_path_is_missing 1/2 &&
|
||||||
test_must_fail git rev-list --missing=print $second &&
|
test_must_fail git rev-list --missing=print $second &&
|
||||||
git rev-list $second &&
|
git rev-list $second &&
|
||||||
|
Loading…
Reference in New Issue
Block a user