From patchwork Fri Sep 11 18:25:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jean-No=C3=ABl_Avila_via_GitGitGadget?= X-Patchwork-Id: 11771365 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDA2859D for ; Fri, 11 Sep 2020 18:25:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF22B214F1 for ; Fri, 11 Sep 2020 18:25:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CL/LDJD7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725917AbgIKSZn (ORCPT ); Fri, 11 Sep 2020 14:25:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725867AbgIKSZc (ORCPT ); Fri, 11 Sep 2020 14:25:32 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88920C061573 for ; Fri, 11 Sep 2020 11:25:31 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id c18so12364824wrm.9 for ; Fri, 11 Sep 2020 11:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ekSrOQKMCsry37eLIl1yJ3SMCc2KAst0M+YuBeb2DWo=; b=CL/LDJD7b4itIv/BUPHDuIXFM4a1UxpmHkoY03J8a8tv3FpFQB8AdnaYquQCxFpdPU 7yPPNcKu28+HS0TSupwu9oE4Kua/pd/kQF5rI0m4WDelJOGxlcjm9bHORoCVlYaPt7Hv IZ5Uz0ZED4R7DlnGIiiy4kiQKFWX2phINJA92Vmj8YzhDwVl8tht35pysTue3Db0M6hx m8heRpqY9pKM/7lAMgAsHWHXqUeXSiM0cP3D+k8SqpDwEalbQckwESMEkrAXzVgFrBwc 49+TQU/s0yx3gKw2sNWsk0EQ9cQBIfNLsLcEXywsffBDrc5vxnuU4520ahDDZTS7r1zF B6HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ekSrOQKMCsry37eLIl1yJ3SMCc2KAst0M+YuBeb2DWo=; b=BY6NkZFOI/4n+v4gAeF9jGKEBXzc6wKnaxW31u08wAFBWOlKCKE50vGtCgV+GGK8Rw BmuGJ0Zpnjoh1NHjcMcRonD4KmvVay6KNI5OX8xJ1BwtT95PHKS89n32I33pB9Oxg8q8 JPDeR31jyC6rm4BhONYeGB25YDxqK6km2bMex+KerGJK2dTIODOgvC9GZv/e+LUrwBRl qvf67m6fNDqnj4KwT5/Bv8BfL7XblK9kl6tRuLMd8BU6gKFmnAiv4Wve/isfI3T0Y0ky /k0ZbO30agWuJ0YLlJ84v86rHgCp9sYfqqOpvrnYBiexw3iyQTlr+RHjvKQz0eKW7QVm 5+oA== X-Gm-Message-State: AOAM533XsHMd+m0JK5E0+OmYgNNP19DAtcMkBXVuqAkqp2F1FfqKMwtp t/X7xlqBVfPop01DMAX0LJzZeg5v4j4= X-Google-Smtp-Source: ABdhPJyULhTPQWsOn5V6R95Lk6U8DXezleAFM5LZTzSK3TcjW3b3qdz6XV9CNwsgAUdLjm4GgoYkvw== X-Received: by 2002:adf:df81:: with SMTP id z1mr3441147wrl.9.1599848728913; Fri, 11 Sep 2020 11:25:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d6sm6136057wrq.67.2020.09.11.11.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 11:25:28 -0700 (PDT) Message-Id: <4cdcedff313751da8c91d701c095f1051e759ce2.1599848727.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Fri, 11 Sep 2020 18:25:24 +0000 Subject: [PATCH 1/4] clone: add tests for --template and some disallowed option pairs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Sean Barag , Sean Barag Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Sean Barag Some combinations of command-line options to `git clone` are invalid, but there were previously no tests ensuring those combinations reported errors. Similarly, `git clone --template` didn't appear to have any tests. Signed-off-by: Sean Barag --- t/t5606-clone-options.sh | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index e69427f881..d20a78f84b 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -19,6 +19,50 @@ test_expect_success 'clone -o' ' ' +test_expect_success 'disallows --bare with --origin' ' + + test_expect_code 128 git clone -o foo --bare parent clone-bare-o 2>err && + test_debug "cat err" && + test_i18ngrep "\-\-bare and --origin foo options are incompatible" err + +' + +test_expect_success 'disallows --bare with --separate-git-dir' ' + + test_expect_code 128 git clone --bare --separate-git-dir dot-git-destiation parent clone-bare-sgd 2>err && + test_debug "cat err" && + test_i18ngrep "\-\-bare and --separate-git-dir are incompatible" err + +' + +test_expect_success 'uses "origin" for default remote name' ' + + git clone parent clone-default-origin && + (cd clone-default-origin && git rev-parse --verify refs/remotes/origin/master) + +' + +test_expect_success 'prefers --template config over normal config' ' + + template="$TRASH_DIRECTORY/template-with-config" && + mkdir "$template" && + git config --file "$template/config" foo.bar from_template && + test_config_global foo.bar from_global && + git clone "--template=$template" parent clone-template-config && + (cd clone-template-config && test "$(git config --local foo.bar)" = "from_template") + +' + +test_expect_success 'prefers -c config over --template config' ' + + template="$TRASH_DIRECTORY/template-with-ignored-config" && + mkdir "$template" && + git config --file "$template/config" foo.bar from_template && + git clone "--template=$template" -c foo.bar=inline parent clone-template-inline-config && + (cd clone-template-inline-config && test "$(git config --local foo.bar)" = "inline") + +' + test_expect_success 'redirected clone does not show progress' ' git clone "file://$(pwd)/parent" clone-redirected >out 2>err && From patchwork Fri Sep 11 18:25:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jean-No=C3=ABl_Avila_via_GitGitGadget?= X-Patchwork-Id: 11771363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF46659D for ; Fri, 11 Sep 2020 18:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B41AB214F1 for ; Fri, 11 Sep 2020 18:25:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uU3bjdk5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725884AbgIKSZj (ORCPT ); Fri, 11 Sep 2020 14:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725864AbgIKSZb (ORCPT ); Fri, 11 Sep 2020 14:25:31 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B07CC061757 for ; Fri, 11 Sep 2020 11:25:31 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id a65so5242714wme.5 for ; Fri, 11 Sep 2020 11:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=lKnTUaXU42KOdD+nLg+EAN4a8kOc4vtItw71t0XzJ+w=; b=uU3bjdk5qbSHimKwKqz7OlIaqFuJzI64EaBTttM4+wjH0qE64T28maHHX/ThQNkbTB IHKwZozS7ROjg0J+eDccgTmWqTO/nAATKgj2iM/1DpgyXL7Ynbi9JVB58xthr98ngOYT omZ0OyGriypsKGK54Yx/+4XhGI2TgRQ5IZVXRiRwusEDRr/tjWbESl6XBG/R1U21tVw8 zWvla94qOtTHvJ2lxsLwZXTlsnNsuKM/crMcg1X48X/8OY971FTbFD6jYDWrgLmo5y7w qgUyzl2dWihrWgmEyYTOoSzOdH1Jk4TUoW/3N26H2PXom4HhWqSNhX7OpmyJ8deycp1g +KCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=lKnTUaXU42KOdD+nLg+EAN4a8kOc4vtItw71t0XzJ+w=; b=FqTj+Hg6BGJlmrEJGRdESsY3KPcqz+GLgYRn7worq2xo1SZsUPgmTz2xjDdvUhdhBb RfDff7HgcUCq16JqJpA8SmxKUkfimQyhwLXXXFEuLUl7zXhMU8337UB2OLjcXt6CKmmp iGITLoWYTqP8gJ/OWtu698RSAmLP5HkHkDMoM9L+S0jz1Tge9wrG2KegMOg4OqODSH9S J5vZ3+aq/NwgE/769+5xX8vAYCMPf2ndJPDHeu9hgtG2JFp8qWrtdHARNBqwNvH4dOTd vu2jXt7JxhyD/ZP6i8ITo7uVCMbRZTzpsn/OdlOZdc0WEYSUqnhZvnVF93f9/9uYVs1+ BHIQ== X-Gm-Message-State: AOAM532H0zkRVnNzCuZygQrQjdT+aJOsu3e3LCYosvEb+P0H+MSRFmlX MlSVYA7I/qplYkkVAgDGnAYwWXmggvc= X-Google-Smtp-Source: ABdhPJzdbGsJiHTSAQDbYiHpGoFu4eTFron9vwTy9294RMKOWxlKFPRqOOlqDHsgVvUWA3W09Jn4Bg== X-Received: by 2002:a1c:988d:: with SMTP id a135mr3439260wme.8.1599848729673; Fri, 11 Sep 2020 11:25:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z15sm5845973wrv.94.2020.09.11.11.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 11:25:29 -0700 (PDT) Message-Id: <51ef776f8523d29dfe03d15f0d1958f5c456c057.1599848727.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Fri, 11 Sep 2020 18:25:25 +0000 Subject: [PATCH 2/4] clone: call git_config before parse_options Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Sean Barag , Sean Barag Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Sean Barag While Junio's request [1] was to avoids the unusual "write config then immediately read it" pattern that exists in `cmd_clone`, Johannes mentioned that --template can write new config values that aren't automatically included in the environment [2]. This requires a config re-read after `init_db` is called. Moving the initial config up does allow settings from config to be overwritten by ones provided via CLI options in a more natural way though, so that part of Junio's suggestion remains. [1] https://lore.kernel.org/git/pull.710.git.1598456751674.gitgitgadget@gmail.com/ [2] https://github.com/gitgitgadget/git/pull/727#issuecomment-689740195 Signed-off-by: Sean Barag Thanks-to: Junio C Hamano Thanks-to: Johannes Schindelin --- builtin/clone.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/builtin/clone.c b/builtin/clone.c index b087ee40c2..bf095815f0 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -851,8 +851,21 @@ static int checkout(int submodule_progress) return err; } +static int git_clone_config(const char *k, const char *v, void *cb) +{ + return git_default_config(k, v, cb); +} + static int write_one_config(const char *key, const char *value, void *data) { + /* + * give git_config_default a chance to write config values back to the environment, since + * git_config_set_multivar_gently only deals with config-file writes + */ + int apply_failed = git_default_config(key, value, data); + if (apply_failed) + return apply_failed; + return git_config_set_multivar_gently(key, value ? value : "true", CONFIG_REGEX_NONE, 0); @@ -964,6 +977,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) struct strvec ref_prefixes = STRVEC_INIT; packet_trace_identity("clone"); + + git_config(git_clone_config, NULL); + argc = parse_options(argc, argv, prefix, builtin_clone_options, builtin_clone_usage, 0); @@ -1125,9 +1141,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (real_git_dir) git_dir = real_git_dir; + /* + * additional config can be injected with -c, make sure it's included + * after init_db, which clears the entire config environment. + */ write_config(&option_config); - git_config(git_default_config, NULL); + /* + * re-read config after init_db and write_config to pick up any config + * injected by --template and --config, respectively + */ + git_config(git_clone_config, NULL); if (option_bare) { if (option_mirror) From patchwork Fri Sep 11 18:25:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jean-No=C3=ABl_Avila_via_GitGitGadget?= X-Patchwork-Id: 11771367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8106159D for ; Fri, 11 Sep 2020 18:25:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64B94214F1 for ; Fri, 11 Sep 2020 18:25:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CdamSeVx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725794AbgIKSZq (ORCPT ); Fri, 11 Sep 2020 14:25:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbgIKSZc (ORCPT ); Fri, 11 Sep 2020 14:25:32 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2229C0613ED for ; Fri, 11 Sep 2020 11:25:31 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id e16so12409101wrm.2 for ; Fri, 11 Sep 2020 11:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=q92HCblGSsqn+nVZla7ay220xSGLmsSz9h8d+nzPjZY=; b=CdamSeVxHG+r/nIFDrFGaP4ISWIRMrWuwFEVoMZVsmJmokP/NkNlk6mxGj/zWH2Krs mJDbe25hxAwKApLioQnQG4SmAybSB4jO30aPRMUWgIpfKCv1xJsFz+MIfIp0+iSZMDCX Ptl7e/3hki4Y8G6F/tZt6sJeYnygUVBkrnx3UlZeaJviL5zH0bjlUU+zuM8bF7vp+6/O OIG7tWYZmnNkxCEu2khJy4vml7MQRVYcmJNWAf1kQmVRQ8KuxD+53rYsdICfTzPBeftK wZaQ+rR/UJAki94xoZFTpnviSGIMUXYxPA7vYULnIfNzAorKh5Vm3PyR7m5ROzEsPZhP pTAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=q92HCblGSsqn+nVZla7ay220xSGLmsSz9h8d+nzPjZY=; b=mnsrmmciMmOih3fKJ2Rv0T0+qEdrvFrc/3sTgTAgyqf+ag7iW4JegtSNR6Xvbs/cSe aLgxDsfMuY8lyUe7CR9HpTImmZvEOJrGMsakquoKLjMIApA06yK1YZulHFi5hs4GBb84 HrmkiJsRLFQ829Y5gz3E6PhdoBHWnaj/eFiQFdGaK5MLj9OR4DL335lULC1WasLujLPn sPxZhRCLuerXZ0Z6l9tBHyFfWIB7VfwGfmArB0W4N3VUzdwtFgBD8L4rA4O4rwke0ktT 67bffs4Hg5l0xKHT/CkYyN8FjqPTc96XujJYrMVELtzxFNZ09s9//YXdmhPRCyd7DY7/ Ccbw== X-Gm-Message-State: AOAM530tFnM1MS1Ns80qQpj8qner567kQvbfHWfweonLubZar2iaKADT 8P+0q48OVO6JAfd6T7S4h58H2zfargQ= X-Google-Smtp-Source: ABdhPJwUwZVHUtBRvrPPcb9L2KjuZMUDmAegdgJ+C/fjZvtCUeFoD/7vPVaWRDFr06vECjbWhDZoRA== X-Received: by 2002:a5d:630a:: with SMTP id i10mr3193864wru.137.1599848730402; Fri, 11 Sep 2020 11:25:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a74sm5909943wme.11.2020.09.11.11.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 11:25:30 -0700 (PDT) Message-Id: <0dff8cd66930130ffd5f0d7d068ad3ed47cd1c81.1599848727.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Fri, 11 Sep 2020 18:25:26 +0000 Subject: [PATCH 3/4] clone: validate --origin option before use Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Sean Barag , Sean Barag Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Sean Barag Providing a bad origin name to `git clone` currently reports an 'invalid refspec' error instead of a more explicit message explaining that the `--origin` option was malformed. Per Junio, it's been this way since 8434c2f1 (Build in clone, 2008-04-27). This patch reintroduces validation for the provided `--origin` option, but notably _doesn't_ include a multi-level check (e.g. "foo/bar") that was present in the original `git-clone.sh`. It seems `git remote` allows multi-level remote names, so applying that same validation in `git clone` seems reasonable. Signed-off-by: Sean Barag Thanks-to: Junio C Hamano --- builtin/clone.c | 7 +++++++ t/t5606-clone-options.sh | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/builtin/clone.c b/builtin/clone.c index bf095815f0..1cd62d0001 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -967,6 +967,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) const struct ref *ref; struct strbuf key = STRBUF_INIT; struct strbuf default_refspec = STRBUF_INIT; + struct strbuf resolved_refspec = STRBUF_INIT; struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT; struct transport *transport = NULL; const char *src_ref_prefix = "refs/heads/"; @@ -1011,6 +1012,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (!option_origin) option_origin = "origin"; + strbuf_addf(&resolved_refspec, "refs/heads/test:refs/remotes/%s/test", option_origin); + if (!valid_fetch_refspec(resolved_refspec.buf)) + /* TRANSLATORS: %s will be the user-provided --origin / -o option */ + die(_("'%s' is not a valid origin name"), option_origin); + strbuf_release(&resolved_refspec); + repo_name = argv[0]; path = get_repo_path(repo_name, &is_bundle); diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index d20a78f84b..c865f96def 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -19,6 +19,14 @@ test_expect_success 'clone -o' ' ' +test_expect_success 'rejects invalid -o/--origin' ' + + test_expect_code 128 git clone -o "bad...name" parent clone-bad-name 2>err && + test_debug "cat err" && + test_i18ngrep "'\''bad...name'\'' is not a valid origin name" err + +' + test_expect_success 'disallows --bare with --origin' ' test_expect_code 128 git clone -o foo --bare parent clone-bare-o 2>err && From patchwork Fri Sep 11 18:25:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jean-No=C3=ABl_Avila_via_GitGitGadget?= X-Patchwork-Id: 11771369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 592F959D for ; Fri, 11 Sep 2020 18:25:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32D19208E4 for ; Fri, 11 Sep 2020 18:25:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NV7Q+/Y6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725932AbgIKSZu (ORCPT ); Fri, 11 Sep 2020 14:25:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgIKSZd (ORCPT ); Fri, 11 Sep 2020 14:25:33 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A53B4C061786 for ; Fri, 11 Sep 2020 11:25:32 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id m6so12420557wrn.0 for ; Fri, 11 Sep 2020 11:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=VRhngF81EV1+XQU88GXGk0pdQCPViCPjvTA/3RNRBJE=; b=NV7Q+/Y6RDFhA6HXG94rl8iFAriEOehMPohbVNBX6BL54Rqml8Ngd0zaxOSHyjI+cJ ohaky6UtPNe2viPK4l2faowR7NhCAwYOZQnJpoqfcAalC3YbrKU5DvgYJWykBvwDpz2i wo+9LauDdd8pPEtJmYCrn+7v1QY1+d1Iq5CyQQSuykOXfuiOOD9Lb4w2Zs8Q5DkF5SCd 5GYJj2W4Y2yzXATmhQFK/toQ7xVOahIuUSVg0YAEN5H+xMdjmc9FXzkItGKKu0KvYgj3 nimTeEIIhlPAjGALjfAw2lZJyV7FHapl0G3rtggSNVnE6xmJ1fXUBOTjzBeD4sFWE3Z8 Y08g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=VRhngF81EV1+XQU88GXGk0pdQCPViCPjvTA/3RNRBJE=; b=CIDfs3NXlwAkhbCtS/tYakhKJzFkjjgso3njRwoqkKBrCs7lRsEQW4AArwbMatHKu5 EQ1LnoGXQYNH4qx0MH1UAYMy/M3r4QbfZQoAx6pUQJpWPrYzLWeSGGxUTgfhDShOQhDB pf4phIoAUhC851TXqLBB1v4c/NGlLQqckU5W5CyOe8UU9ZPOVjl/tY+M+RYjSB21cEYD O9De9pEoYUiqmGa374p58u29mSV5DMa7OnzLEiUWw7frvZbkyUr9v5HXuPlxXBp/q+Nl MODzkbB62nfnbn3JBLflmJ8DSnSNbW5ColqELE1zNdEGxQx6riVOSu5V2MpEG6K4XKjV ZWpA== X-Gm-Message-State: AOAM531CnQUgaVXv7tn2WE9FYPfwzCAfzRaVOtwXRouV8ILk6omWrPQk Y/6P5t/AT+SajJ5X7eSzFQyDU8ZQl4s= X-Google-Smtp-Source: ABdhPJx9nqO83Iez+neGUuNn76Dky9tFbcmdByq+Rg2dLo3EoE6OVCuLSy0W9FBNgBYrgfvkKBdwDQ== X-Received: by 2002:a5d:4581:: with SMTP id p1mr3354713wrq.345.1599848731104; Fri, 11 Sep 2020 11:25:31 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y2sm5570095wmg.23.2020.09.11.11.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 11:25:30 -0700 (PDT) Message-Id: <5c519376c29a28bd89a712cf0b8125fc1c2c81be.1599848727.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Fri, 11 Sep 2020 18:25:27 +0000 Subject: [PATCH 4/4] clone: allow configurable default for `-o`/`--origin` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Sean Barag , Sean Barag Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Sean Barag While the default remote name of "origin" can be changed at clone-time with `git clone`'s `--origin` option, it was previously not possible to specify a default value for the name of that remote. This commit adds support for a new `clone.defaultRemoteName` config. It's resolved in the expected priority order: 1. (Highest priority) A remote name passed directly to `git clone -o` 2. A `clone.defaultRemoteName=new_name` in config `git clone -c` 3. A `clone.defaultRemoteName` value set in `/path/to/template/config`, where `--template=/path/to/template` is provided 3. A `clone.defaultRemoteName` value set in a non-template config file 4. The default value of `origin` Signed-off-by: Sean Barag Thanks-to: Junio C Hamano Thanks-to: Johannes Schindelin --- Documentation/config.txt | 2 ++ Documentation/config/clone.txt | 5 ++++ Documentation/git-clone.txt | 5 ++-- builtin/clone.c | 42 +++++++++++++++++++--------------- t/t5606-clone-options.sh | 29 +++++++++++++++++------ 5 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 Documentation/config/clone.txt diff --git a/Documentation/config.txt b/Documentation/config.txt index 3042d80978..354874facf 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -334,6 +334,8 @@ include::config/checkout.txt[] include::config/clean.txt[] +include::config/clone.txt[] + include::config/color.txt[] include::config/column.txt[] diff --git a/Documentation/config/clone.txt b/Documentation/config/clone.txt new file mode 100644 index 0000000000..20755d413a --- /dev/null +++ b/Documentation/config/clone.txt @@ -0,0 +1,5 @@ +clone.defaultRemoteName:: + The name of the remote to create when cloning a repository. Defaults to + `origin`, and can be overridden by passing the `--origin` command-line + option to linkgit:git-clone[1]. + diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index c898310099..f04bf6e6ba 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -183,8 +183,9 @@ objects from the source repository into a pack in the cloned repository. -o :: --origin :: - Instead of using the remote name `origin` to keep track - of the upstream repository, use ``. + Instead of using the remote name `origin` to keep track of the upstream + repository, use ``. Overrides `clone.defaultRemoteName` from the + config. -b :: --branch :: diff --git a/builtin/clone.c b/builtin/clone.c index 1cd62d0001..aeb41f15f3 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -53,6 +53,7 @@ static int option_shallow_submodules; static int deepen; static char *option_template, *option_depth, *option_since; static char *option_origin = NULL; +static char *remote_name = "origin"; static char *option_branch = NULL; static struct string_list option_not = STRING_LIST_INIT_NODUP; static const char *real_git_dir; @@ -721,7 +722,7 @@ static void update_head(const struct ref *our, const struct ref *remote, if (!option_bare) { update_ref(msg, "HEAD", &our->old_oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR); - install_branch_config(0, head, option_origin, our->name); + install_branch_config(0, head, remote_name, our->name); } } else if (our) { struct commit *c = lookup_commit_reference(the_repository, @@ -853,16 +854,18 @@ static int checkout(int submodule_progress) static int git_clone_config(const char *k, const char *v, void *cb) { + if (!strcmp(k, "clone.defaultremotename") && !option_origin) + remote_name = xstrdup(v); return git_default_config(k, v, cb); } static int write_one_config(const char *key, const char *value, void *data) { /* - * give git_config_default a chance to write config values back to the environment, since + * give git_clone_config a chance to write config values back to the environment, since * git_config_set_multivar_gently only deals with config-file writes */ - int apply_failed = git_default_config(key, value, data); + int apply_failed = git_clone_config(key, value, data); if (apply_failed) return apply_failed; @@ -918,12 +921,12 @@ static void write_refspec_config(const char *src_ref_prefix, } /* Configure the remote */ if (value.len) { - strbuf_addf(&key, "remote.%s.fetch", option_origin); + strbuf_addf(&key, "remote.%s.fetch", remote_name); git_config_set_multivar(key.buf, value.buf, "^$", 0); strbuf_reset(&key); if (option_mirror) { - strbuf_addf(&key, "remote.%s.mirror", option_origin); + strbuf_addf(&key, "remote.%s.mirror", remote_name); git_config_set(key.buf, "true"); strbuf_reset(&key); } @@ -1009,13 +1012,16 @@ int cmd_clone(int argc, const char **argv, const char *prefix) option_no_checkout = 1; } - if (!option_origin) - option_origin = "origin"; + if (option_origin) + remote_name = option_origin; - strbuf_addf(&resolved_refspec, "refs/heads/test:refs/remotes/%s/test", option_origin); + strbuf_addf(&resolved_refspec, "refs/heads/test:refs/remotes/%s/test", remote_name); if (!valid_fetch_refspec(resolved_refspec.buf)) - /* TRANSLATORS: %s will be the user-provided --origin / -o option */ - die(_("'%s' is not a valid origin name"), option_origin); + /* + * TRANSLATORS: %s will be the user-provided --origin / -o option, or the value + * of clone.defaultremotename from the config. + */ + die(_("'%s' is not a valid origin name"), remote_name); strbuf_release(&resolved_refspec); repo_name = argv[0]; @@ -1167,15 +1173,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix) git_config_set("core.bare", "true"); } else { - strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin); + strbuf_addf(&branch_top, "refs/remotes/%s/", remote_name); } - strbuf_addf(&key, "remote.%s.url", option_origin); + strbuf_addf(&key, "remote.%s.url", remote_name); git_config_set(key.buf, repo); strbuf_reset(&key); if (option_no_tags) { - strbuf_addf(&key, "remote.%s.tagOpt", option_origin); + strbuf_addf(&key, "remote.%s.tagOpt", remote_name); git_config_set(key.buf, "--no-tags"); strbuf_reset(&key); } @@ -1186,7 +1192,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (option_sparse_checkout && git_sparse_checkout_init(dir)) return 1; - remote = remote_get(option_origin); + remote = remote_get(remote_name); strbuf_addf(&default_refspec, "+%s*:%s*", src_ref_prefix, branch_top.buf); @@ -1299,7 +1305,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (!our_head_points_at) die(_("Remote branch %s not found in upstream %s"), - option_branch, option_origin); + option_branch, remote_name); } else our_head_points_at = remote_head_points_at; @@ -1307,7 +1313,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) else { if (option_branch) die(_("Remote branch %s not found in upstream %s"), - option_branch, option_origin); + option_branch, remote_name); warning(_("You appear to have cloned an empty repository.")); mapped_refs = NULL; @@ -1319,7 +1325,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) const char *branch = git_default_branch_name(); char *ref = xstrfmt("refs/heads/%s", branch); - install_branch_config(0, branch, option_origin, ref); + install_branch_config(0, branch, remote_name, ref); free(ref); } } @@ -1328,7 +1334,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) remote_head_points_at, &branch_top); if (filter_options.choice) - partial_clone_register(option_origin, &filter_options); + partial_clone_register(remote_name, &filter_options); if (is_local) clone_local(path, git_dir); diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index c865f96def..017c24a454 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -43,13 +43,6 @@ test_expect_success 'disallows --bare with --separate-git-dir' ' ' -test_expect_success 'uses "origin" for default remote name' ' - - git clone parent clone-default-origin && - (cd clone-default-origin && git rev-parse --verify refs/remotes/origin/master) - -' - test_expect_success 'prefers --template config over normal config' ' template="$TRASH_DIRECTORY/template-with-config" && @@ -71,6 +64,28 @@ test_expect_success 'prefers -c config over --template config' ' ' +test_expect_success 'uses "origin" for default remote name' ' + + git clone parent clone-default-origin && + (cd clone-default-origin && git rev-parse --verify refs/remotes/origin/master) + +' + +test_expect_success 'prefers config "clone.defaultRemoteName" over default' ' + + test_config_global clone.defaultRemoteName from_config && + git clone parent clone-config-origin && + (cd clone-config-origin && git rev-parse --verify refs/remotes/from_config/master) + +' + +test_expect_success 'prefers --origin over -c config' ' + + git clone -c clone.defaultRemoteName=inline --origin from_option parent clone-o-and-inline-config && + (cd clone-o-and-inline-config && git rev-parse --verify refs/remotes/from_option/master) + +' + test_expect_success 'redirected clone does not show progress' ' git clone "file://$(pwd)/parent" clone-redirected >out 2>err &&