From patchwork Tue Sep 29 03:36:49 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: 11804935 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 41DD692C for ; Tue, 29 Sep 2020 03:37:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 270D4208D5 for ; Tue, 29 Sep 2020 03:37:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jLsPp5z/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727395AbgI2Dg7 (ORCPT ); Mon, 28 Sep 2020 23:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbgI2Dg7 (ORCPT ); Mon, 28 Sep 2020 23:36:59 -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 0E4D3C0613D0 for ; Mon, 28 Sep 2020 20:36:59 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id g4so3660226wrs.5 for ; Mon, 28 Sep 2020 20:36:58 -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=jLsPp5z/QVw2IDKSNDncIjl1U5YKniJ1srPZdCcGHZdw5Tl7MACfyzBfdzM6mgbcm9 DYuJmmtnFhrMbIcKD0J3bueZRJfowTlLN6JzFUegv1Z1EqzO1QHSXsrDjrz8cHMzTaV5 VNLiEbMY4q8WhZP62LCZpaiEea0W6b9HkATA9y6lG4qTg5QGUnR1DTADgGMbrFDni9qA tkJQKqtkhmeOy3OwoUTRn5ohnSxDTmDKqmBltAop3N3NV8hSUbmjEy7LeIYWj6kJuugg VkTkgY3bsfWGSj5RbIIbnHlczLjYwbdZCeX5Nlr6vcsMCPrP+80Is2XK0WbsjuwNfq08 9O5Q== 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=ZMKFVkS62muk4fmzr1FXXJGBY1AWHPiC41PSkUPJLSl+GfPnnh+tTK4OvRevXy2Hgi 6hGnFqDhTf9aLT7SI5kye6f0G7VQUlHnFPGftcUSQsF49Hyane6TZ7xCqW7YU6vFzJIM iEKtuu76GCCHWWP334tnFps8DvU/BQaHDXRFTmNY8xj/Fzyd3ANpRrCqOfw3Br49HbQO y7VmDVGNwJDkpstsXuVIrDoC6WBTOp42uySbPtnJUlf+JGAXzoYyjWKdZ1+xFMJ5IDaP 3qgFLKKKz1OZVweDWWmTSrGIb+XrI0Pz2yKMjZsVD9GAe8lozV0b7XaVLF7VDbd8c/fM 40wQ== X-Gm-Message-State: AOAM533jE/26VEkSYKtVt38N2HGzGMrUVGMrlC1zpAZ0U06RefPv8shz 3cpm+iaaVK+S3cZK/ZsXzH7S3FFLK1I= X-Google-Smtp-Source: ABdhPJwwokRu5WIm8Jh6aQJmoScYaxEMwSw739kcZ10xgwWuZlMj03wXQpdxZLrlRJvr+bf23V3Rzw== X-Received: by 2002:adf:f58b:: with SMTP id f11mr1607742wro.250.1601350617462; Mon, 28 Sep 2020 20:36:57 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t17sm4033798wrx.82.2020.09.28.20.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 20:36:57 -0700 (PDT) Message-Id: <29ab418b1b8028c566b1008a0673ad0f6c6d112f.1601350615.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Tue, 29 Sep 2020 03:36:49 +0000 Subject: [PATCH v2 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 Tue Sep 29 03:36:50 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: 11804937 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 5DE49112C for ; Tue, 29 Sep 2020 03:37:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3EB4C20BED for ; Tue, 29 Sep 2020 03:37:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t+YMXe+R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727407AbgI2DhB (ORCPT ); Mon, 28 Sep 2020 23:37:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbgI2DhA (ORCPT ); Mon, 28 Sep 2020 23:37:00 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2E91C061755 for ; Mon, 28 Sep 2020 20:36:59 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id z4so3674427wrr.4 for ; Mon, 28 Sep 2020 20:36:59 -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=uu/wCSr6KcnM5nnbEG8y3u2NoqHZnzZ5apgvN3yTBbw=; b=t+YMXe+R7+BOcsdaezWISpsJ3ey3DqWI8i5WRyYVF2ffvE/4tO1pxrupyhmzKOLAZt nKx+DwdGycrcAKpwGmR9dkKFLAmaSZ5wQVREQIARuLoCwQ6maHWprNKHgWGLr2h5+eHd UqR84EVORS/DDzsfKv4PP5sQPZ5q1c8Di8DMNXEB4NsUVdcqq7w/vSGbCh1zIKe4boQQ LKaZDJXU90KZyZtJQdMWTayJgY0DldOrNF5jY6fI1ok2GW88A/rs0aMM6ApzJhjCX0gr RuHrrfDvFaADV8P6ahgELagyvvTAnyMGUhwOhQwCrOVYslD5o4ALXPQFZM9v+dujVq28 /ybQ== 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=uu/wCSr6KcnM5nnbEG8y3u2NoqHZnzZ5apgvN3yTBbw=; b=CFEQaCG2gYnnh8kuJ2Ln7ovtFAOfYeZhNa99VEZeJ/Qqkvv+n/3z4i0Ci1ArBV7RTt fa1B0LTtyBp5wyAR9+yNiCbKHM0MaGRn/todkkN1+Qv6Cce11V1LchH16IHUxeTStfQF ZF1cfgYIoe62DrYP+imOU0LJ5DgJ7I84R6aDwb0dIS6IItfYEQdcpR7osLkiJf2rigYM yQhlL9RIv9Zf+NUDpt5m28lgLQ5kz1Au70ZhyrhSCCGqfzFOfupftAaak2enPz7fKYYn gtamxRvior8X87KyZ9wEXrLnOZuSjAP7J7RuAL0cyXDrnPoGDDsZvKhEA4ly7AlZ92jA 81Yw== X-Gm-Message-State: AOAM530tBKhSPTMMi9iT9m5JViAQ5B+oYFGC5T9ycxGfSTHwpI5nqSwq IYtky/BTgKCDT0enYz4YxgIcWxDmwL8= X-Google-Smtp-Source: ABdhPJy+Tuof2fos/G1fl2zQUhLZIWg01sUcLKR7t8EmV94+mR1rlUsYUvyeJH6vVmm0TccWF3wnVg== X-Received: by 2002:adf:dfc3:: with SMTP id q3mr1552658wrn.238.1601350618259; Mon, 28 Sep 2020 20:36:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a81sm3769083wmf.32.2020.09.28.20.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 20:36:57 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Tue, 29 Sep 2020 03:36:50 +0000 Subject: [PATCH v2 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 fbfd6568cd..93ccd05b5d 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 Tue Sep 29 03:36:51 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: 11804941 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 A16E7112C for ; Tue, 29 Sep 2020 03:37:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 862B520BED for ; Tue, 29 Sep 2020 03:37:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OP5N8iSb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727421AbgI2DhH (ORCPT ); Mon, 28 Sep 2020 23:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727403AbgI2DhB (ORCPT ); Mon, 28 Sep 2020 23:37:01 -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 7AE85C061755 for ; Mon, 28 Sep 2020 20:37:00 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id a9so3289231wmm.2 for ; Mon, 28 Sep 2020 20:37:00 -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=OP5N8iSbM0BdYIBn7ijNG1En+YdQjfOubTtRK2KOCQ5J7Sma2Ub3wmA5wnDr2npgIx fvxUwfwl4IYZ68akse2hBUIzU+hGVD8JBaUPtJt++Da9BUVU2j7rk5M8rQy4PwhgF/Ll P5vSGFh5LbqiJbQusmSE9xScFJXtLQ1OE3uez6QBJczHmg/M1G0+WW0VHbduzDa5w0fQ PRCEx9CUP5/9G03Eh/+rh8ubwML4cgSw0z6qBQzlTkAXUNFmTD6hIXjZNnTmhAD4d862 +cXwOmX++n1QCT7HtcTD+LLHkGgikxMaVclBqyRWTMntMJQUwCRiuihaBlcbaQxdjRh1 7/jg== 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=lpYa8SESF/+KyCE94W/++8rCWb0BQvUFzDHX8BFRFzEGFie7XqKILFJ5CSZidZyEfL 3oqThbKYIlXC2a1HaQ2JyXfkJT2sjmyXh4HuraylH/f0L8wTgOokthJxBZIppLridrfB t0UvbClb7aqqr1n8NGV5rLA5cvN827fvqwUEsjSbGXlh4zI9is7p2fpFWSRbw1RnWdeL VawrvHBAIu4enMel6cBUx2ydC1HJsHBu6VUHPaL0kXo8PHzWF0/SFD9vZjba+69ghxB5 4kFShYK20UPIuFY97m/ZGmt6qUxKyDK3ZSq2gwe8yuMD10LmQRkd/u6z2jd9/8oAjotF 7I5g== X-Gm-Message-State: AOAM530ovqkgp9eFQqSudic8q2x02HVqx783rstTuWTRunygQDtXPhbd uQWt0gon/0tHLIK9Vssk1BBnHe0RRO4= X-Google-Smtp-Source: ABdhPJwTBQocC2oIfpI9tDrJrHhJo8doWxqw/EV2EdTCbh5Ol/uaOTQ/oQULTEXVF48tphyWDsy1LQ== X-Received: by 2002:a05:600c:4108:: with SMTP id j8mr2196846wmi.116.1601350619036; Mon, 28 Sep 2020 20:36:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a11sm3419555wmm.18.2020.09.28.20.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 20:36:58 -0700 (PDT) Message-Id: <85be780b8eff988f01461caccabd61a0ebfd8578.1601350615.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Tue, 29 Sep 2020 03:36:51 +0000 Subject: [PATCH v2 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: 11804947 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 9F13E92C for ; Tue, 29 Sep 2020 03:37:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A84420BED for ; Tue, 29 Sep 2020 03:37:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SwtR8dtx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727437AbgI2DhJ (ORCPT ); Mon, 28 Sep 2020 23:37:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbgI2DhB (ORCPT ); Mon, 28 Sep 2020 23:37:01 -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 3A4D1C0613D0 for ; Mon, 28 Sep 2020 20:37:01 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id k10so3658774wru.6 for ; Mon, 28 Sep 2020 20:37:01 -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=SwtR8dtxWFiFlo+/XAF4umRJ+xgDlpjCs7znH2aXBeecnjiOARQp03Bkw1/y1bpAk3 3QQiHapJEGLVtF6sRXWyvs/YGPjV4YU436MNlefKV0t0tOHnSs2hSutIQaIiufaEGsbm be1VdsRKazNVVAH18AvMiCS5Lfo0RpKIeBOzf3CjYlbxne2Lth+3u+DHr0fDnp6nQfdd 3pfxZ9CU1nQJ+wi0ZWVy5m5CpSmpRdZ2tEVNTJCQGqfaPD1MZVYMzmIrwqPHZOsL1SYg aFdPr4lNqAk1Mp+T+zrUkPYsZtmxDIYnw8Sxc3jt6xEVQWL/63qvehltvG36DYL2x2Uw MM0A== 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=PDvFxiJnwFBHFdMT6LLruiasfjJM/snFZbM7JUAN1QYotWaPOJd+UDuEKoQFKGnhV/ XxT8o7wZX0ix/mlxqeAabiOLK2mBAdvVCBpCGgS3hhOdSXKfiQ5b60SUOhbuQO+8bnEX 2jHC1pd+BsShOZhss7YR2t4kP2l68x2MoMVHSC7rLOqdbhTlO/o6j74xnWtI4/u/uY4d eZrahavSTigqM809Zs9JtM6+3FKjACtW6C0NKLeWpH0/eoB0Q5YOzKLTVJDGTzpUh6DX VLKhjgpFzkJU4yCQ+PG7T8jnEXAqeubh/piisbZcJI9TtgqCqyPfnCljMOIxORYu3bYG dj2Q== X-Gm-Message-State: AOAM531JDDCcRS8bLARrV4cG4sNGx9NE+DawKEFPDMdu3imbYMYWptSV KtOlFWyg64MW8TPlXdD2aZ3YOH/VTIA= X-Google-Smtp-Source: ABdhPJwoYzEC8sIK5yPHxAiZgVB+Hr1C+ucnKgq5GIOtWjoIkpkkWLMGR0W3PEUp2HPOJlBuF6JAjw== X-Received: by 2002:a5d:458a:: with SMTP id p10mr1559196wrq.282.1601350619808; Mon, 28 Sep 2020 20:36:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s26sm3412207wmh.44.2020.09.28.20.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 20:36:59 -0700 (PDT) Message-Id: <42dc18601ab09d1f9b45f0a37e7eda726d14599d.1601350615.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Tue, 29 Sep 2020 03:36:52 +0000 Subject: [PATCH v2 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 Tue Sep 29 03:36:53 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: 11804945 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 1929A6CB for ; Tue, 29 Sep 2020 03:37:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDD0F20BED for ; Tue, 29 Sep 2020 03:37:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xy4snppJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727432AbgI2DhI (ORCPT ); Mon, 28 Sep 2020 23:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727408AbgI2DhC (ORCPT ); Mon, 28 Sep 2020 23:37:02 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26A50C0613D1 for ; Mon, 28 Sep 2020 20:37:02 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id e17so3146234wme.0 for ; Mon, 28 Sep 2020 20:37:02 -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=SEpnHZvLycK4QZFA8t9RNM7Hm1dYHbneTQ8+7VkoepA=; b=Xy4snppJLMOTrqkevoZcqb03HN8OlJo2IqylRfJkAYaD2Cc0UeoCJU7CR4gT3cZKAm YYXN2iJaxtusMxxNjjAa0DhRr+wEmZtjMoHqgTI6VfsjqD2Kbnf3yXvMj6+RxzlLAb1I HzEKNTtU7cJxLLiBchKut0rBeCRu1r72D3AXyRogoM7SNWT0+KJgEYpUxqHU7mbuHY/9 6v95tZBhCXex/j8Gzy33NEDarKytOZkncO9IYKXdnHesrHi25B5TBLZMsFNfEF3ikHVR P1xaPDxn+o+OrJGgYN0JgOArfcJcKWGE5l0YHcF9ct5SR2Uu5AzO9L7i03xuiKYWcZf+ iLSA== 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=SEpnHZvLycK4QZFA8t9RNM7Hm1dYHbneTQ8+7VkoepA=; b=NS28LrFdk68HXunUUEwYtuYOZsgnp1JoG97ajgo6yOMN2Zv2BRGbP4yMOtC26AzcbC DaTZRUADIVIH+PCEQIczS4WBcIo/By8ORtxIEjLXdXkqJfkRoK6cmNyGDiPOL6IH7sdh Prtfl4J0wkfu9N87h0kLDxyBB5RAohTbaH6F98YEz35fgdKrGuS7iUQjNxVQTFKqziYg Rxfoha8Dn+gg5DcZVVdXESfcLeWBZCz6NLD2kG4vrvjBwbUEqVGF9eYaQmCxsz+7aU9T myMruemdBxqdK8EER/jDAPRQOoTTVdjRHZGGg26Vn1bIFuYcoi/muGumrc4IV8+CJdja 5XDg== X-Gm-Message-State: AOAM533F2TcVgkLDtNQetD651qKp5086HXTiyBI5Y/t3+gLLEcIS7ILK teNA9onJbtkEQXcSthBlOKk6wGLxZ4M= X-Google-Smtp-Source: ABdhPJwWLAnzDtHdt2DMu8ltrIoNRbScM6cw2KnQD6V2xWMae+sqc6ptsn/o1krvDqow86S2nTcOZA== X-Received: by 2002:a7b:cd8b:: with SMTP id y11mr2160188wmj.172.1601350620730; Mon, 28 Sep 2020 20:37:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k22sm4198902wrd.29.2020.09.28.20.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 20:37:00 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Tue, 29 Sep 2020 03:36:53 +0000 Subject: [PATCH v2 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 93ccd05b5d..673f7b68c3 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(remote_name)) + die(_("'%s' is not a valid remote name"), remote_name); + repo_name = argv[0]; path = get_repo_path(repo_name, &is_bundle); From patchwork Tue Sep 29 03:36:54 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: 11804943 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 51F666CB for ; Tue, 29 Sep 2020 03:37:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CD3F208D5 for ; Tue, 29 Sep 2020 03:37:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cWfFKHRr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727423AbgI2DhH (ORCPT ); Mon, 28 Sep 2020 23:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727410AbgI2DhD (ORCPT ); Mon, 28 Sep 2020 23:37:03 -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 00893C0613D3 for ; Mon, 28 Sep 2020 20:37:03 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id z1so3674181wrt.3 for ; Mon, 28 Sep 2020 20:37:02 -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=mzDa/dPyZvcONscHHtJ1SdY8o9RJAneA4hRG9HZS0ss=; b=cWfFKHRrmeN+r261cuD12hvqYFRZrFe/FtyHM4SudgfqGBZdunalIe+3Hv7js712wC azBiQAfhwgd/fkfQU1ZCyIzm7uMa8BXfA+bnxuLXHmLzDks/nazqccGkXW2YOl7b2ARj LamnjEZcls8Qm/H6NfpWgAcjlWlCtxeavJSPc44NqXbPGpsabb6kp88tvYaemJMraUhf Xs7p/R6doIS3JnQQbRMqh6qpJqoDjUZB/2Semd9wRXBJTMwZFIvaQqG9wFPzxtNh8nAs u9plLKfvli07AZg+v/bwMbEpS6E/tEuOCnrg83m9et/w11Zy3GxlWhhTMCX4/k+zXPN+ ofzQ== 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=mzDa/dPyZvcONscHHtJ1SdY8o9RJAneA4hRG9HZS0ss=; b=P1X50S6VJRtpC5YasKpNofGJjlTHomsoTSRFwA0UX9JU/wMMeszOwcWkS9GZOSgdV7 4PPeYAP+rb2BoDIPWFro6m1Jvdz9OoockRD+zI/KUvQURxEBk+02jEnY4dZhxTlcXsx4 ZxWOp/hU1Ttg88pgaCJ7bFUxAgj/VS+/7WqH6at3ozt6cMVTxsk58schE7RhMLLxb7Lh ob4S8KZrU3g5avazRxO44eoJSJFGjlrTXNvaVjnyXti1PBWpDQIxqcmbE3g3sz/RpN0Z dre5Ci3/cQpg2556ec0TqIU4etYAt/9IiW7sCZ0DI5ufj1MgjjGkLdmmuMygJMl1nlz5 Wo/g== X-Gm-Message-State: AOAM5306970Hm+r3Vcv8GIOaZtjRidDyvk7K1oCBpEtQ8sWrIdqQloY+ 8aBXp+6ENuoxNn8m784tbTSKuYbvRvM= X-Google-Smtp-Source: ABdhPJwUwsX1kK93AuJL7pso8mMtASBcoDPsavmNX5WOm1WeDpmlg5l6pBB5O+YUJXoyGqRieGbGyw== X-Received: by 2002:a5d:4c52:: with SMTP id n18mr1542812wrt.267.1601350621474; Mon, 28 Sep 2020 20:37:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i33sm4249233wri.79.2020.09.28.20.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 20:37:01 -0700 (PDT) Message-Id: <99f4d765b475ca7d73dec2dd1367fe2cb0f358d8.1601350615.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Tue, 29 Sep 2020 03:36:54 +0000 Subject: [PATCH v2 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 | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 673f7b68c3..7fdd00cd95 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,8 +1009,8 @@ 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(remote_name)) die(_("'%s' is not a valid remote name"), remote_name); @@ -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 Tue Sep 29 03:36:55 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: 11804949 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 866C892C for ; Tue, 29 Sep 2020 03:37:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65FCA20BED for ; Tue, 29 Sep 2020 03:37:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kM8QiwLI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727418AbgI2DhG (ORCPT ); Mon, 28 Sep 2020 23:37:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727413AbgI2DhE (ORCPT ); Mon, 28 Sep 2020 23:37:04 -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 E7FCCC0613D4 for ; Mon, 28 Sep 2020 20:37:03 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id q9so3149973wmj.2 for ; Mon, 28 Sep 2020 20:37:03 -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=j4ZGlSZnIOAnCAxmKzXa0rnPh2Rvq/GMG+MUDOpOZ10=; b=kM8QiwLI1DABMBYKX2Ene3b9fZvd0r870vuZq19qN9AYm8fTkqsgPsat5qwtM5XSlw dgyUPmLty96L+I9HSFj2o4onZz/LoNH2ASZJeErtg3txYxVcVURRx/GlQZLaPIBQtzfL goeotCVIwnmi/mYT+ox1tEjqsMzTbPbFl0//3lfOxEhVkBAllBJaQHlYEeSSOZGKYF+S zrXhWSzPEDFHMdMHKDfU8ii4pR/yY2U45VVaTs4pbOZ2J0kX2S2HYa4U1n0SYq6fS8tT RD3OgdKlN//NK7uLL9+xBf8HMx2JAi0in7iosVH0xC9XREOJEXbzXrEq/4bNmhHnlwEx CDuw== 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=j4ZGlSZnIOAnCAxmKzXa0rnPh2Rvq/GMG+MUDOpOZ10=; b=bQPidyCONHHdZrZR65EObGyrj5gpHbjTZX/40AszRZR+CEhH8TxhimbMumZOFCoReX DwPvMKhCT52/0nweQrfhT67pbL2lbW4xY5NBkSXAXJzq2PQMUTHxkyZiz49D4PxZ0Rbw T+RusPCbUHp80Ud3lEA0IgWu5daR4w5RG7HK5RYQyu0p1qSS2B/vYfKZP/i/HVag5wab pzSY5RarRUIajXHYW3A603+WrB921vrc5PCiE41Kevd5WS2qKNcpFXl71T3dj/xFZY4h Ws+TgXnvs5tuBv4PckvIxbYnq6M9+m6hIIKdYP1IOTirOko6Ce66fjidUaijUwaUboTi TgpQ== X-Gm-Message-State: AOAM53295ywwQItPPzHpTxhTwg+BJCFeRZechhdP0iGyN5BLnatf5x+o frDwImhZz3f/1sHM1QWFMWeehTGJqYk= X-Google-Smtp-Source: ABdhPJzv2TFUYrSfmAtSuVjiwCrJinr0Y7AuYbuex1YvnYn2P55D9d2xQXE5LLJ+sjd74cQ6z5emDQ== X-Received: by 2002:a1c:5a86:: with SMTP id o128mr2005174wmb.129.1601350622362; Mon, 28 Sep 2020 20:37:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m10sm3535376wmi.9.2020.09.28.20.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 20:37:01 -0700 (PDT) Message-Id: <737f91c6244220eec196c327fcea9a6548c45310.1601350615.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Sean Barag via GitGitGadget" Date: Tue, 29 Sep 2020 03:36:55 +0000 Subject: [PATCH v2 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 | 27 +++++++++++++++++++-------- t/t5606-clone-options.sh | 22 ++++++++++++++++++++++ 5 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 Documentation/config/clone.txt diff --git a/Documentation/config.txt b/Documentation/config.txt index f93b6837e4..8c58c53ae7 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 7fdd00cd95..4c821de242 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -53,7 +53,8 @@ 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 *default_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 +855,11 @@ static int checkout(int submodule_progress) static int git_clone_config(const char *k, const char *v, void *cb) { + if (!strcmp(k, "clone.defaultremotename")) { + if (remote_name != default_remote_name) + free(remote_name); + remote_name = xstrdup(v); + } return git_default_config(k, v, cb); } @@ -976,6 +982,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) int submodule_progress; struct strvec ref_prefixes = STRVEC_INIT; + remote_name = default_remote_name; packet_trace_identity("clone"); @@ -1009,12 +1016,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); @@ -1153,10 +1154,20 @@ int cmd_clone(int argc, const char **argv, const char *prefix) /* * re-read config after init_db and write_config to pick up any config - * injected by --template and --config, respectively + * injected by --template and --config, respectively. */ 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) + remote_name = option_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/"; 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 &&