From patchwork Tue Nov 30 11:54:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12647029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C00CC433EF for ; Tue, 30 Nov 2021 11:55:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241075AbhK3L6q (ORCPT ); Tue, 30 Nov 2021 06:58:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233082AbhK3L6U (ORCPT ); Tue, 30 Nov 2021 06:58:20 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA7F3C061757 for ; Tue, 30 Nov 2021 03:55:00 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id l16so43816681wrp.11 for ; Tue, 30 Nov 2021 03:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=zMOqWXrQqZ2IHpZK6hFdtyVBHSAW6HN1jJsmuhexxWc=; b=G2QQD2VZc7hhxW2KHkw3Fuvsm7A3ulefWLpfYKeUc4bFTbkTHM60hQuSxI+KVLL9sI syAb73qGbiNM09ZOeehGtnV7d/EQQo6UN+v24iRCQSYsnhkNr7A8FXdvHqofwTOrfbxv PFq6eZKFGsGizqHBY8UAkPPrtQfjWJaYMJCK9h4/tQLZVk/HUIcRN1oF5S++w0XGP57x 2to9x9N0rCb44oKIZ4BZfC3Rq9Mt2pZbEDtBmLKdODuko8zrCX+uX2QD2X3X6d5Tj6HQ bSwPA0yVm1USedqgNYa52PJjkZoodUrSI0vLznUPas1WfChH9+f2kVhiA2XFpgPJbeLp JNHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=zMOqWXrQqZ2IHpZK6hFdtyVBHSAW6HN1jJsmuhexxWc=; b=4Lz2+Jkp8BFytIVL86/8tTNNuqouK0HXP8XhlDNCf2qmAFnqpcJ1X36valV08FKnT4 432B+zuhMP1Wbu/q0TvDB/yNdsMKdnKmBKh7VUFlTbGWEIE2PCC2xzIG/f2LxP8clGKK EuuYmXt/7stMSIXU5Ctvem+1leDSGT0RNMu728LhkdsfHTXbxtnClr4QtM/Zw58ffeRy FSYe3k8ps4UTmxt9WTJUmM2QrK9ToCSoa/oX2na60+7fCTLzdfLVWqYk7nU1ezJnfTyT caZovXAB2cfMZU3L29TPvnob6BDn7IAYLblB+BdLZ1cu6aHpRaI0HAnDGJj99chVH/JO 7IFA== X-Gm-Message-State: AOAM531jgolFPvtjYCsL5ZWaxNLHRok8m5wNHwL+/d0F93pnEhB3vsQA 029tSqw2cXm+epx58h73yK7kg3ybt+s= X-Google-Smtp-Source: ABdhPJxE8F9yd3RTETOLOi8egX12mIr3oWrKhZB1U+wAoCokROGZ78IAYkcTBL66TeTGCEadrWneVw== X-Received: by 2002:a5d:52c3:: with SMTP id r3mr40411610wrv.115.1638273299384; Tue, 30 Nov 2021 03:54:59 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z18sm16243868wrq.11.2021.11.30.03.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 03:54:58 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 30 Nov 2021 11:54:44 +0000 Subject: [PATCH v9 12/17] scalar: teach 'clone' to support the --single-branch option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Matt Rogers , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Just like `git clone`, the `scalar clone` command now also offers to restrict the clone to a single branch. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 9 +++++++-- contrib/scalar/scalar.txt | 12 +++++++++++- contrib/scalar/t/t9099-scalar.sh | 6 +++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 60a9466421b..61b66e48aa8 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -327,12 +327,15 @@ static char *remote_default_branch(const char *url) static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; - int full_clone = 0; + int full_clone = 0, single_branch = 0; struct option clone_options[] = { OPT_STRING('b', "branch", &branch, N_(""), N_("branch to checkout after clone")), OPT_BOOL(0, "full-clone", &full_clone, 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(), }; 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) || 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.partialCloneFilter=blob:none")) { res = error(_("could not configure remote in '%s'"), dir); diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index e8730967f16..56f744a4aa9 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,7 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] -scalar clone [--branch ] [--full-clone] [] +scalar clone [--single-branch] [--branch ] [--full-clone] [] scalar list scalar register [] scalar unregister [] @@ -57,6 +57,16 @@ HEAD[:]`. Instead of checking out the branch pointed to by the cloned repository's HEAD, check out the `` 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:: A sparse-checkout is initialized by default. This behavior can be turned off via `--full-clone`. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 984d69e8f75..f60e086d6f9 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -45,13 +45,17 @@ test_expect_success 'set up repository to clone' ' test_expect_success 'scalar clone' ' second=$(git rev-parse --verify second:second.t) && - scalar clone "file://$(pwd)" cloned && + scalar clone "file://$(pwd)" cloned --single-branch && ( cd cloned/src && git config --get --global --fixed-value maintenance.repo \ "$(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_must_fail git rev-list --missing=print $second && git rev-list $second &&