From patchwork Thu Oct 1 03:46:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11810857 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 5DF3C13B2 for ; Thu, 1 Oct 2020 03:46:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37DD121D43 for ; Thu, 1 Oct 2020 03:46:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uEoj9XDR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730338AbgJADqV (ORCPT ); Wed, 30 Sep 2020 23:46:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbgJADqV (ORCPT ); Wed, 30 Sep 2020 23:46:21 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC4C6C061755 for ; Wed, 30 Sep 2020 20:46:20 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id m6so3967285wrn.0 for ; Wed, 30 Sep 2020 20:46:20 -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=kMKDnHn06oMedf8Zi981Xaj1FxFvUg58m4Kj+4amaPs=; b=uEoj9XDRW+iND1FTgyOHHfORtGOgYtGFAg8s+pslFn+J4+Xxm3FsVVyeQhHD3w3xpv Id6viCmAuImLcSaY0oHM127UzinKMWcbH0HDMM/JC77S6r72La2xDGlSUZTOuF3FCI1O cVJgioOgYBNXGtKQYwCoenfOAJMD5NohzTqbar0lkHgmZGf8iHIorrnH+X1yPSw+SvbN 1BiGTV2HDZvlV3vsj26rVRYdHoBeHXmeaOoKYebIJOpExbXBsyctGxP8KHyjdvjk0E+z OBx8XsBx74h3CE5mtiwdv0zr56n2NQmPjzuWO/xw7HfrgIe5lODdUWnHHi7uopOUcssi cz2g== 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=kMKDnHn06oMedf8Zi981Xaj1FxFvUg58m4Kj+4amaPs=; b=UcSVCwNPA2uehCOMFDHrWN2xhcrcfRhOSMVlDTatZNEyyVkLV5WnCB6ynHPJdl6Ioy zNY8DRA7H5Fbk2OpQDeF2LTBbWlU8cX8EFQiGg7NzE88x3nYHKZk6p2ZLeIHup4UhoHo Nssuw3JRvBZuJ1zRjEA6CbqO3M4R9NOWOs9IhV94Ks8UcfxM+1naEEuMREwgwfcaCmDp fZvmqL3b3sljcokujheX8eKnJe4gOQzVPNqr10ABbfpM4hzo+UMgRhgJkEmvvZeUlA6r kYsQankTJagK242AYjzHHO3ZwYqToQ2TMCe+zLkBt2bG2vi26o+XBfHedgBdxwIDfO8m ZLzA== X-Gm-Message-State: AOAM530jSglF5mW/GVCSHv4zvFDXopvqzCTa5PSmo6KtmSP7m9YPaGjH 0CmoEdeVnUO7nMVcsREmI/ri5PC0wsQ= X-Google-Smtp-Source: ABdhPJx7Q8LOjp5Ms6bD8I44hHo6UivH3x99NnQ0a3DqhQJwvggCMhlkeOI35e5wGNY9TPKM6rw1XA== X-Received: by 2002:a5d:55c8:: with SMTP id i8mr6362271wrw.331.1601523979388; Wed, 30 Sep 2020 20:46:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j10sm6391872wrn.2.2020.09.30.20.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 20:46:18 -0700 (PDT) Message-Id: <4195dec00c846e2a1ebcd32d0cb5d0ed2626328d.1601523977.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Thu, 01 Oct 2020 03:46:10 +0000 Subject: [PATCH v3 1/7] 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 , Derrick Stolee , Jeff King , Eric Sunshine , Taylor Blau , Sean Barag , Andrei Rybak , Sean Barag , Sean Barag 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. Helped-by: Jeff King Helped-by: Derrick Stolee Signed-off-by: Sean Barag --- t/t5606-clone-options.sh | 46 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index e69427f881..0422b24258 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -15,7 +15,51 @@ test_expect_success 'setup' ' test_expect_success 'clone -o' ' git clone -o foo parent clone-o && - (cd clone-o && git rev-parse --verify refs/remotes/foo/master) + git -C clone-o rev-parse --verify refs/remotes/foo/master + +' + +test_expect_success 'disallows --bare with --origin' ' + + test_must_fail git clone -o foo --bare parent clone-bare-o 2>err && + test_debug "cat err" && + test_i18ngrep -e "--bare and --origin foo options are incompatible" err + +' + +test_expect_success 'disallows --bare with --separate-git-dir' ' + + test_must_fail git clone --bare --separate-git-dir dot-git-destiation parent clone-bare-sgd 2>err && + test_debug "cat err" && + test_i18ngrep -e "--bare and --separate-git-dir are incompatible" err + +' + +test_expect_success 'uses "origin" for default remote name' ' + + git clone parent clone-default-origin && + git -C clone-default-origin 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 && + test "$(git -C clone-template-config 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 && + test "$(git -C clone-template-inline-config config --local foo.bar)" = "inline" ' From patchwork Thu Oct 1 03:46:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11810861 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 1FA7D174A for ; Thu, 1 Oct 2020 03:46:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0461221D43 for ; Thu, 1 Oct 2020 03:46:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pRIoIZ+M" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730573AbgJADq0 (ORCPT ); Wed, 30 Sep 2020 23:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbgJADqW (ORCPT ); Wed, 30 Sep 2020 23:46:22 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D825C061755 for ; Wed, 30 Sep 2020 20:46:21 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id k10so3956990wru.6 for ; Wed, 30 Sep 2020 20:46:21 -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=wFtXGfoZReg53g6R+Ofk7FNuP4sOHiZPekqNtKfDthw=; b=pRIoIZ+MyEPXqxitM1ME6HESo3tMFqx66asjcyeLdmVekequpuY+pA2exY6cauCxQn J0iEWVOPLs/kHFjwcWmXH6jbwU4AjrgBoMZ6xUlMnCLay+yfY+/RGERBRAoYG5hY7n/g yVdUJNj9bGIyUMdclKL0c53a80ZrmCGYaWKQ6vCEtIDtRjfsMjlMPGsrP8f983qEpSEA ppYBKFIbCNei8XDAtm3mQ3jYvD9i5OsPx4JH6t60XaQipFvg5aRE/t7uwXDPpPBBaSaC nWdypQsJR0gjz7fcgmIpUB3/NOH1L9/MHiea72vUm9hSmIzM7VgUCp7WWR3Heb8F9Lxq l7Ag== 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=wFtXGfoZReg53g6R+Ofk7FNuP4sOHiZPekqNtKfDthw=; b=bq+v9YfUzEwClp7c6VyhsLRoKfPI1qxJgjp8LIMf1oEjMLJ8YXdEIoWVY3LIL1P4hH amfuX1PkHP9ZUJ2nnayMdgeok8AlYTjRDR/loUu6oi3gC1Fp5iWSQQtSBxk4yqRLvuRU cJYd+yEzQQS7R70lE3Cy77JA4qy+3Ib/APUjyAzaGaL9eTmSryUbFkeJ3LemnDqTbb0x z2hMpBvZPnMVnEKfzxaPLGKuGG4zTa+PmZtcUNBCwQGI5MuZ8T2lfn5ckjCU41qi8GTN PjBb78YHciwjucpbpZ5hksFDSZ7LpAtiufcnGYjR1kxUeIYvK/wKegG7mepHm2f1KtQU ktcg== X-Gm-Message-State: AOAM530akCmhDxepNpm7QOVDP9HGaOrGai62Zd8LlEcc9PBQmPJGSPg5 UswcfogeHu/DfKDCYOuFH7t/moGU8YY= X-Google-Smtp-Source: ABdhPJzr7z1htu3jm3bFrQavu47FKkwntGjJhh0aKxangDq3LVQPBk6wNP9YFzfb29S+5KLJuxBsow== X-Received: by 2002:adf:c64e:: with SMTP id u14mr6175032wrg.373.1601523980174; Wed, 30 Sep 2020 20:46:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h4sm7585827wrm.54.2020.09.30.20.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 20:46:19 -0700 (PDT) Message-Id: <1abcf417d91128e09632f6c74cc14de3dce29623.1601523977.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Thu, 01 Oct 2020 03:46:11 +0000 Subject: [PATCH v3 2/7] clone: use more conventional config/option layering Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , Jeff King , Eric Sunshine , Taylor Blau , Sean Barag , Andrei Rybak , Sean Barag , Sean Barag Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Sean Barag Parsing command-line options before reading from config required careful handling to ensure CLI options were treated with higher priority. Read config first to let parsed CLI naively overwrite matching config values. Helped-by: Junio C Hamano Helped-by: Johannes Schindelin Signed-off-by: Sean Barag --- builtin/clone.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/builtin/clone.c b/builtin/clone.c index 391aa41075..a76dacd988 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -851,8 +851,22 @@ 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_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_clone_config(key, value, data); + if (apply_failed) + return apply_failed; + return git_config_set_multivar_gently(key, value ? value : "true", CONFIG_REGEX_NONE, 0); @@ -963,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); @@ -1124,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 Thu Oct 1 03:46:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11810865 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 6CAF913B2 for ; Thu, 1 Oct 2020 03:46:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52CA821D43 for ; Thu, 1 Oct 2020 03:46:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j9Qs8Pu5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730505AbgJADqZ (ORCPT ); Wed, 30 Sep 2020 23:46:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730385AbgJADqY (ORCPT ); Wed, 30 Sep 2020 23:46:24 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DEFAC0613D0 for ; Wed, 30 Sep 2020 20:46:22 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id c18so3937613wrm.9 for ; Wed, 30 Sep 2020 20:46:22 -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=t+pghuU5Gv83eMVih7dQHTihGijXyL5XBxWL7n3ryDI=; b=j9Qs8Pu5V0VZy3UKvd3eb3DUcvKitp0o9Tv6sXCNU9mmc2QcvI9knkXb1mYuECVwB5 T8hzLbIFJpSEzu6EVe59PpNY1YV/Sle7nGbMFis4rZwvks5VtLouDh7aMW8Lq74GXYQ9 nPviC3a1xjVewCQzwwhIAmZUGDCdV3RrfwChz1EJHhxVcZ0G4QhQt/ofEDv30DE2PkU3 NTgMbsoA4dHx2DJVwNGS3yapZoR6Le51JLkKYDVU5y/byBuVQ0n8txiccbc5IjCnkH9K 3GMvKjT37wyuPA5X2sPg7e/wCJZoWOekqkYK0Xk/qYBR/R2okCiSKNBNXWKP0nRVvFn2 al/Q== 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=t+pghuU5Gv83eMVih7dQHTihGijXyL5XBxWL7n3ryDI=; b=niVnI6EwDgKjDCRBobuYLv04bBv8tg/pxvpyTA0ZEsxEmKlTeg/bLIggUmNwb6yHKP 1/7dOiKFkfluAt9k2BV0pP5gq69cgJGnz/ygJ3ChDA8H14thppqYVyzqSmpy/VKILoQ2 UM+/6cW4qmhGHriJlomYuszvMPQUYcBC+odfbsBp/egQyJQ+e2gQWQ9wL9cVfzkYnXVX wG+NmjfMpNa82JZlTrnbmxR59vkUgGrzUK2jRH4sKaLlWv2NImr2M17z+oHrSUoRWZpH 60ukzAhmXCVtQ/YtUfb7es5K1y5U7PQULvO/t4IpFOEgwKLU3rUGXAH6dka2b6lm9klP Fruw== X-Gm-Message-State: AOAM5319hXdserEatcsw14QPE1sPhghWJo3hRseubqv/5KZbsx6o3Nx1 avEXNLt6uSZHPVMGwXLGvSSbpKU5ql4= X-Google-Smtp-Source: ABdhPJw2H/aGG3kgg4Q9Br149q7ROwLz+dcrp77cOELzhfsVEdpJiCoiZR0m38pkFosDKsWMeOKc7g== X-Received: by 2002:adf:e7ce:: with SMTP id e14mr6110309wrn.43.1601523980979; Wed, 30 Sep 2020 20:46:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f23sm5389961wmf.6.2020.09.30.20.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 20:46:20 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Thu, 01 Oct 2020 03:46:12 +0000 Subject: [PATCH v3 3/7] remote: add tests for add and rename with invalid names Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , Jeff King , Eric Sunshine , Taylor Blau , Sean Barag , Andrei Rybak , Sean Barag , Sean Barag Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Sean Barag In preparation for a future patch that moves `builtin/remote.c`'s remote-name validation, ensure `git remote add` and `git remote rename` report errors when the new name isn't valid. Signed-off-by: Sean Barag --- t/t5505-remote.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 8d62edd98b..1156f52069 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -179,6 +179,13 @@ test_expect_success 'rename errors out early when deleting non-existent branch' ) ' +test_expect_success 'rename errors out early when when new name is invalid' ' + test_config remote.foo.vcs bar && + echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect && + test_must_fail git remote rename foo invalid...name 2>actual && + test_i18ncmp expect actual +' + test_expect_success 'add existing foreign_vcs remote' ' test_config remote.foo.vcs bar && echo "fatal: remote foo already exists." >expect && @@ -194,6 +201,12 @@ test_expect_success 'add existing foreign_vcs remote' ' test_i18ncmp expect actual ' +test_expect_success 'add invalid foreign_vcs remote' ' + echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect && + test_must_fail git remote add invalid...name bar 2>actual && + test_i18ncmp expect actual +' + cat >test/expect < X-Patchwork-Id: 11810867 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 4874913B2 for ; Thu, 1 Oct 2020 03:46:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C04821D43 for ; Thu, 1 Oct 2020 03:46:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CkSIpulA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730481AbgJADqZ (ORCPT ); Wed, 30 Sep 2020 23:46:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730378AbgJADqX (ORCPT ); Wed, 30 Sep 2020 23:46:23 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DB05C0613D1 for ; Wed, 30 Sep 2020 20:46:23 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id x14so3949796wrl.12 for ; Wed, 30 Sep 2020 20:46:23 -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=if/tLdO5VC7d820oFC6cy+yeCQhnDLeKBPiaXw+xkE4=; b=CkSIpulAxYpNvODpCtBFRy+JKFPJetRN6h8+2i0ZBQoyP2FLysoRl4Ji9H//NNPRlS kl01fxZ96A54B8hKiFEO5LTlsfQUmV9ddv1V5NmKvLGcdcqk6V/nwkLMaAEKTPt2VFcU GfLr4ZeRFm3aKKKdYYx/ncKURCdgkD4dvlAPIFjem4e87N4jQJZBxUGm4XAGG7GUiak3 3C3cYNtL9Bg63ll8d99J2HafRwDkc+Q5czylva85mtVgzHa59tXpu+E30zJzOL/fGoCT gzLJ3l/C7BZwhSeTcmPNe9VhjHOa7sc8Qd0QwZaH/i2opjniTU53IO4JegqkBjD/QZvx k0Bg== 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=if/tLdO5VC7d820oFC6cy+yeCQhnDLeKBPiaXw+xkE4=; b=K6Ms92gK2xbDY/h6VlLanzGDOWqkv7rGkuGcFKMkJxh8K6lwAWg8NS9uGDA3svaFSY mmHIoEPqejz0x+ZsoynHqj3EGrqRTj5s/Mr32RQvo66syOVqBGC24GaTNgApRD0beDzV X0cdBg1Mrod+70fa58gn5viJptrZE2dmYGNan/UBSQQPXHv1EQgo73ZE2EHgIolQ5k89 j3kn9lWYsSGGbNtcXDxUg1VzM5zmMCwQR7Qguh8SLNxpguYDkK8YllESeEHplsP59YjM f1OX38yppvbSBWIPtgA4T2EgbR/UnIBIEywzfyeyrdOm2Cqc8Tq/Jkkk0cZ8543lYUmv Z5VA== X-Gm-Message-State: AOAM533HW+W3NAObSR5uPPnU/TuvJY6RfaNsWLSiWpO4i9BTgRIGaIHN zU/ieUTYngsBDDgjsXxioi0W2WjaEoE= X-Google-Smtp-Source: ABdhPJyjU3JD7OtC0OUTi5WbztOKHGMfyMWHNpKzu36hCrQ/cblVQ1ISBPMZ1JGNPmKtu5bcE9J0mQ== X-Received: by 2002:a5d:6691:: with SMTP id l17mr6506044wru.10.1601523981758; Wed, 30 Sep 2020 20:46:21 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q20sm6076473wmj.5.2020.09.30.20.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 20:46:21 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Thu, 01 Oct 2020 03:46:13 +0000 Subject: [PATCH v3 4/7] refs: consolidate remote name validation Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , Jeff King , Eric Sunshine , Taylor Blau , Sean Barag , Andrei Rybak , Sean Barag , Sean Barag Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Sean Barag In preparation for a future patch, extract from remote.c a function that validates possible remote names so that its rules can be used consistently in other places. Helped-by: Derrick Stolee Signed-off-by: Sean Barag --- builtin/remote.c | 7 ++----- refspec.c | 10 ++++++++++ refspec.h | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 64b4b551eb..63f2b46c3d 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -194,8 +194,7 @@ static int add(int argc, const char **argv) if (remote_is_configured(remote, 1)) die(_("remote %s already exists."), name); - strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name); - if (!valid_fetch_refspec(buf2.buf)) + if (!valid_remote_name(name)) die(_("'%s' is not a valid remote name"), name); strbuf_addf(&buf, "remote.%s.url", name); @@ -696,11 +695,9 @@ static int mv(int argc, const char **argv) if (remote_is_configured(newremote, 1)) die(_("remote %s already exists."), rename.new_name); - strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new_name); - if (!valid_fetch_refspec(buf.buf)) + if (!valid_remote_name(rename.new_name)) die(_("'%s' is not a valid remote name"), rename.new_name); - strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s", rename.old_name); strbuf_addf(&buf2, "remote.%s", rename.new_name); if (git_config_rename_section(buf.buf, buf2.buf) < 1) diff --git a/refspec.c b/refspec.c index 8d0affc34a..3056ffdfb8 100644 --- a/refspec.c +++ b/refspec.c @@ -215,6 +215,16 @@ int valid_fetch_refspec(const char *fetch_refspec_str) return ret; } +int valid_remote_name(const char *name) +{ + int result; + struct strbuf refspec = STRBUF_INIT; + strbuf_addf(&refspec, "refs/heads/test:refs/remotes/%s/test", name); + result = valid_fetch_refspec(refspec.buf); + strbuf_release(&refspec); + return result; +} + void refspec_ref_prefixes(const struct refspec *rs, struct strvec *ref_prefixes) { diff --git a/refspec.h b/refspec.h index 7569248d11..bbb25968a8 100644 --- a/refspec.h +++ b/refspec.h @@ -62,6 +62,7 @@ void refspec_appendn(struct refspec *rs, const char **refspecs, int nr); void refspec_clear(struct refspec *rs); int valid_fetch_refspec(const char *refspec); +int valid_remote_name(const char *name); struct strvec; /* From patchwork Thu Oct 1 03:46:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11810859 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 EE535139F for ; Thu, 1 Oct 2020 03:46:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D23CF21D7D for ; Thu, 1 Oct 2020 03:46:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Kr4Jwqet" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730537AbgJADqZ (ORCPT ); Wed, 30 Sep 2020 23:46:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730415AbgJADqY (ORCPT ); Wed, 30 Sep 2020 23:46:24 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C5CAC0613D2 for ; Wed, 30 Sep 2020 20:46:24 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id q9so1445943wmj.2 for ; Wed, 30 Sep 2020 20:46:23 -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=vQqBZ6n4yoJvFdWDcAg0rtHyyez4I2x9VidEL47I2n4=; b=Kr4JwqetAlYtgVWFanZqv9EpNUc97EhDNzjVXhKAHCkOlto23JJKZF8ygTOhf+8NQ7 aH/hGZB0BxGK8Axu/KyzwuGotAVAJHBYUFted64liC1FYBHYugadi9+U5ypy0IjDKvUV SBsr5hRRdRfCE0xnIzq9RaAYubSSIMKQqpw1UEaaeor0bxjVEWqNaw0vpFMtEkdu5Yqc uGpUIwhr5iC/3XmX0sfIQitbjEBjOcDNRHB4IVsimSjpDjzMo6kL/Sf/8TSmO+lfQ66F rvoHTXB/1VHqFPsGrqvO1MJCr85TcEHKaL5iNGsJf14jLSybuCuynPTK7bf6/h2kbVcf ownA== 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=vQqBZ6n4yoJvFdWDcAg0rtHyyez4I2x9VidEL47I2n4=; b=ZctP1VYdzNJ3/0+QyeI+228K2Pj6KrSugliHNmnhQckbft++Ymd616ANLQZ6+H/6SY P+EFuVkKNtC1Xl8wQUVG7aK8pKTd1Qi7NMTb0YAiMczYUSsL8gdrXuWqsAjr/Dm7DnJT ZuEgg1ZWLTyahfePcvzYBBJAmhQZcJ31ZhmUvtplROi1GrcoyLrMQnBnntOSm2qZMeJw MZyWDjkN+gJxsS2EIfZBXmGTSkdIyNxaWol7aix6cpfXU2YF10++0x32tP4MM8fo6njV +ZK6jOIMoi6pzCef6HFz/y3O6bSZ5f/erLTGnZpPCBuij7XRfVZMHot7Zf0FYlvSDkWH 7Fbg== X-Gm-Message-State: AOAM533a2Il0vQipeUwgF4BZn+KAhDNKKlz+sg5JvD2GA8SbbGXPX0Zd E5ZeZjC8fqsFj3SqC+9R6Hm+VsDV6H8= X-Google-Smtp-Source: ABdhPJzx07zChtSLHvKBf00c0/MHyp+pEOyMG6s9qeaAf/OIABYF4zq5dfMjF7ApHeap50u03OzPYw== X-Received: by 2002:a05:600c:216:: with SMTP id 22mr5790426wmi.149.1601523982627; Wed, 30 Sep 2020 20:46:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h76sm6949272wme.10.2020.09.30.20.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 20:46:22 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Thu, 01 Oct 2020 03:46:14 +0000 Subject: [PATCH v3 5/7] clone: validate --origin option before use Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , Jeff King , Eric Sunshine , Taylor Blau , Sean Barag , Andrei Rybak , Sean Barag , Sean Barag 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. This behavior dates back to since 8434c2f1 (Build in clone, 2008-04-27). Reintroduce validation for the provided `--origin` option, but notably _don't_ include a multi-level check (e.g. "foo/bar") that was present in the original `git-clone.sh`. `git remote` allows multi-level remote names since at least 46220ca100 (remote.c: Fix overtight refspec validation, 2008-03-20), so that appears to be the desired behavior. Helped-by: Junio C Hamano Helped-by: Derrick Stolee Helped-by: Jeff King Signed-off-by: Sean Barag --- builtin/clone.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/clone.c b/builtin/clone.c index a76dacd988..bd67ff7b01 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1011,6 +1011,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (!option_origin) option_origin = "origin"; + if (!valid_remote_name(option_origin)) + die(_("'%s' is not a valid remote name"), option_origin); + repo_name = argv[0]; path = get_repo_path(repo_name, &is_bundle); From patchwork Thu Oct 1 03:46:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11810869 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 A5972139F for ; Thu, 1 Oct 2020 03:46:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83B0421D46 for ; Thu, 1 Oct 2020 03:46:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BKVXuYxa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730642AbgJADqa (ORCPT ); Wed, 30 Sep 2020 23:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730378AbgJADqZ (ORCPT ); Wed, 30 Sep 2020 23:46:25 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB8EFC0613D3 for ; Wed, 30 Sep 2020 20:46:24 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id v12so1470751wmh.3 for ; Wed, 30 Sep 2020 20:46:24 -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=XNltrLCGQ+ZX0AivDc2S4gRxxcleGtS86Y1VRlaQhdA=; b=BKVXuYxaBuWSz2XmEbapuhp5TxGm3MjU71hUFkyw2++ve5fVRuMgB4tpPKHTmIQy0D c4v9A6Y/Oz388TlLdWhKiUtrq0jV1PBofcUzGyx2ziqJYEgu69bq3r+tht393lIvZE+q euuIvHsHWlEx3nAtO5c6Hj7AIoJviQugogWN+sUVkKjkf9H8AJc8Td/ErHj1DKcdOa5g C6zQ1+CSYiZd48MNaXCD64bwOoqeerlxa2p/M1oy/fv2u6z0Gknifa7wGoLthxxxptLL N+bVPvku58JQrLsFNbteW1XVXCEqnCVOHv8r4UM+fK6S8yGtBqPoNNziBZso4+oZhfSV Jhjg== 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=XNltrLCGQ+ZX0AivDc2S4gRxxcleGtS86Y1VRlaQhdA=; b=N/EBzPLtHRpwFLSYwLsneNPYcIxZZA9L7fhngfmd7rPseCWEojuD1HZ2z4Sma0Zhrt E3sXYWEORCiRT6JYSuPpJHw3MS7G3ZFNQYFS+1wdcgmS8zOh7cQOXjZ9LWkR7f2L3ech 1tXOXel7nD7BBSj4xYs2vp1gJKRdiCFYs/qCS1QPRY59xjaD658ejBiNDya4iivTQTMb xSt1ZnhEmZtwcSiXNXY683NyyOO1Fwyecs2eRZOjPeCpK+2TfLOqzU0iFs/Z89L+CeFQ UbPdrAFdbTpL00IkfTPkCmKZ+llI7BecR/lXWmJjRFmaLzSTkj5zMRFG03Em9iHa8sY5 9PHw== X-Gm-Message-State: AOAM5339QapTHwHIygicHfczbQbxJZ/mIGBDo1mN5PVqTy8G+qhoyQHh XsUuwsnhVZ38BCEkPxQs6efqLpEI8TM= X-Google-Smtp-Source: ABdhPJzTA+Xi9b8dOldgoEgRI0OdeWlruKPncbVxd1QMBQk4qO7qbA5R0Po/zyg5XLPDUBVnLdeLig== X-Received: by 2002:a7b:c08c:: with SMTP id r12mr495990wmh.184.1601523983453; Wed, 30 Sep 2020 20:46:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u66sm6086065wme.12.2020.09.30.20.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 20:46:23 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Thu, 01 Oct 2020 03:46:15 +0000 Subject: [PATCH v3 6/7] clone: read new remote name from remote_name instead of option_origin Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , Jeff King , Eric Sunshine , Taylor Blau , Sean Barag , Andrei Rybak , Sean Barag , Sean Barag Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Sean Barag In a future patch, the name of the remote created by `git clone` may come from multiple sources. To avoid confusion, convert most uses of option_origin to remote_name, leaving option_origin to exclusively represent the -o/--origin option. Helped-by: Derrick Stolee Signed-off-by: Sean Barag --- builtin/clone.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index bd67ff7b01..6bcdfa4cd6 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, @@ -919,12 +920,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); } @@ -1008,11 +1009,11 @@ 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; - if (!valid_remote_name(option_origin)) - die(_("'%s' is not a valid remote name"), option_origin); + if (!valid_remote_name(remote_name)) + die(_("'%s' is not a valid remote name"), remote_name); repo_name = argv[0]; @@ -1163,15 +1164,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); } @@ -1182,7 +1183,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); refspec_appendf(&remote->fetch, "+%s*:%s*", src_ref_prefix, branch_top.buf); @@ -1294,7 +1295,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; @@ -1302,7 +1303,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; @@ -1314,7 +1315,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); } } @@ -1323,7 +1324,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); From patchwork Thu Oct 1 03:46:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11810863 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 48A5A17CF for ; Thu, 1 Oct 2020 03:46:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C20121D43 for ; Thu, 1 Oct 2020 03:46:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Eelj0oiK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730599AbgJADq1 (ORCPT ); Wed, 30 Sep 2020 23:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730555AbgJADq0 (ORCPT ); Wed, 30 Sep 2020 23:46:26 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0CFEC061755 for ; Wed, 30 Sep 2020 20:46:25 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id l15so1288404wmh.1 for ; Wed, 30 Sep 2020 20:46:25 -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=aKfttKZqWWeMvcMBTaMWxfS3Jrs++sz9EJ06YfrFm4E=; b=Eelj0oiKzgWDmII2cEIY2f7WBMjsjqj01ZeQmA11SjE+CV+ocvpzzMqguYsuodF51k SInZ3a5Ei+CE5FVG1xI3GmIOmpwDAztZz3nmKiGfKFM9ej2Y58/RMuXZwwWUc6QgC28M yz37LHl4R3/+OiX1qjX/fEZjtipl3YiEbzjNq0WHKoVWg8bh3uuzAAjsPi8s+XUzi+/J pgDJl7smruMTOjX0QCboeW/0DKBi51LTvWFSP3Y9H3ZwUchxEql7W+HvuC+pR4bET6QJ h7vZLHHumq/RT1TLooXeV/RHFMeZAshOCfEPp6RoM7acRlpi4WcGF/EHc4SuPtF+TfcZ qBhQ== 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=aKfttKZqWWeMvcMBTaMWxfS3Jrs++sz9EJ06YfrFm4E=; b=GTflyWtDlsYEdUw0waBmFvuLv5ryxK3fo9YzSKwQ9H43FYkD2ATKO4MaPGSpdp811n ykGvKhuP6+0k1ULRlz9cVteBQjn4/rQab65SMr9x77LFdSlvJUoVDzouj4X9pcVrEeNh l8r4VPOLG3PvGROMnbY79Owy93PuRKM7Dgqw2Y38A0cMIsQ6bNKuuOC5fKb8BxEaA+zU vvsn2tl7E2wfRv9jFiWciVZpo7uFivwhnkthsNxaxP3XN4c7S0RYuAZzgB2rpeCAAm4x EFJKK3pZH97wsKsDVAbXan2oBhIKViOFXkpqi+m4pzC70kEF76EpNYLYS/A9KgJbYB1g ZY5g== X-Gm-Message-State: AOAM533CptF/BgcW/rEgYb5hJMr7UeUl6itkoZiTwNG54l5k4/yLFI7e tJmpXr0IjW43+vfi4d74sT755k57pLk= X-Google-Smtp-Source: ABdhPJwSMer0b9efgoUKRQYLmPfBmZNMu0mcEzhIG4eL+QxacxpGarDRho+SIquXBswk0j4ysVwoDA== X-Received: by 2002:a1c:6a08:: with SMTP id f8mr6272270wmc.151.1601523984298; Wed, 30 Sep 2020 20:46:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t16sm1127332wmi.18.2020.09.30.20.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 20:46:23 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Thu, 01 Oct 2020 03:46:16 +0000 Subject: [PATCH v3 7/7] clone: allow configurable default for `-o`/`--origin` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , Jeff King , Eric Sunshine , Taylor Blau , Sean Barag , Andrei Rybak , Sean Barag , Sean Barag 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. Add support for a new `clone.defaultRemoteName` config, with the newly-created remote name resolved in 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 4. A `clone.defaultRemoteName` value set in a non-template config file 5. The default value of `origin` Helped-by: Junio C Hamano Helped-by: Johannes Schindelin Helped-by: Derrick Stolee Helped-by: Andrei Rybak Signed-off-by: Sean Barag --- Documentation/config.txt | 2 ++ Documentation/config/clone.txt | 5 +++++ Documentation/git-clone.txt | 5 +++-- builtin/clone.c | 26 +++++++++++++++++++------- t/t5606-clone-options.sh | 22 ++++++++++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 Documentation/config/clone.txt diff --git a/Documentation/config.txt b/Documentation/config.txt index bf706b950e..025ca4df11 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 097e6a86c5..876aedcd47 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 6bcdfa4cd6..a0841923cf 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -53,7 +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 *remote_name = NULL; static char *option_branch = NULL; static struct string_list option_not = STRING_LIST_INIT_NODUP; static const char *real_git_dir; @@ -854,6 +854,10 @@ static int checkout(int submodule_progress) static int git_clone_config(const char *k, const char *v, void *cb) { + if (!strcmp(k, "clone.defaultremotename")) { + free(remote_name); + remote_name = xstrdup(v); + } return git_default_config(k, v, cb); } @@ -1009,12 +1013,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) option_no_checkout = 1; } - if (option_origin) - remote_name = option_origin; - - if (!valid_remote_name(remote_name)) - die(_("'%s' is not a valid remote name"), remote_name); - repo_name = argv[0]; path = get_repo_path(repo_name, &is_bundle); @@ -1157,6 +1155,19 @@ int cmd_clone(int argc, const char **argv, const char *prefix) */ git_config(git_clone_config, NULL); + /* + * apply the remote name provided by --origin only after this second + * call to git_config, to ensure it overrides all config-based values. + */ + if (option_origin != NULL) + remote_name = xstrdup(option_origin); + + if (remote_name == NULL) + remote_name = xstrdup("origin"); + + if (!valid_remote_name(remote_name)) + die(_("'%s' is not a valid remote name"), remote_name); + if (option_bare) { if (option_mirror) src_ref_prefix = "refs/"; @@ -1356,6 +1367,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) junk_mode = JUNK_LEAVE_REPO; err = checkout(submodule_progress); + free(remote_name); strbuf_release(&reflog_msg); strbuf_release(&branch_top); strbuf_release(&key); diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index 0422b24258..5e201e7d85 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -19,6 +19,13 @@ test_expect_success 'clone -o' ' ' +test_expect_success 'rejects invalid -o/--origin' ' + + test_must_fail git clone -o "bad...name" parent clone-bad-name 2>err && + test_i18ngrep "'\''bad...name'\'' is not a valid remote name" err + +' + test_expect_success 'disallows --bare with --origin' ' test_must_fail git clone -o foo --bare parent clone-bare-o 2>err && @@ -63,6 +70,21 @@ test_expect_success 'prefers -c config over --template config' ' ' +test_expect_success 'prefers config "clone.defaultRemoteName" over default' ' + + test_config_global clone.defaultRemoteName from_config && + git clone parent clone-config-origin && + git -C clone-config-origin 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 && + git -C clone-o-and-inline-config 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 &&