From patchwork Thu Feb 24 09:45:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Klerks X-Patchwork-Id: 12758263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E185C433EF for ; Thu, 24 Feb 2022 09:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230354AbiBXJqP (ORCPT ); Thu, 24 Feb 2022 04:46:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232954AbiBXJqN (ORCPT ); Thu, 24 Feb 2022 04:46:13 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AC2927DF33 for ; Thu, 24 Feb 2022 01:45:44 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id p4so767512wmg.1 for ; Thu, 24 Feb 2022 01:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=az2W3f24aofQMN06tQK0E2B1Jt/IJeHT7w5Vk9gWAWc=; b=b0QsW6RbBmdy2fnseFeWKJM87HitWjDxhZzRT2ydtfqSJX9tES3Xmg1sJNB1EiD/Uw sCh8TgNut+HJkH6h8mp/UfJhvQVesAreRqIdS3Xwpm9lJ10g00mSs1QhS4kx5ML+cMS0 5rqvIHQbp91M6eIQ0ixirOc1z3wRwDkcvBsXWRERj4hQGcaoGsaGeuzCKQvBaB7dgjlG ERo2eNQw49NnKNMCh6lVvQnrwDSryxvbWeGLF2b8qCiMtXZGzkiCXKoCZwwQkbYTDkhn u8hKpMXaYnerOpZ7zwxzc2f51wOXIgAJ0i/zs64Trwh27AyiLWLAxWTSYw0qqzAWD0Ev 86EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=az2W3f24aofQMN06tQK0E2B1Jt/IJeHT7w5Vk9gWAWc=; b=GbkUNrrtdS7gPsLbT4LW3VnN6nKGMG3YswOD8HQGk203DD54IuSrpn+NOxNVTT8E2L ym9odIyNsLkaZOK+/WlWnhIBjTnODhrFMSn8sn8UHT2U4XsJY6c+77VwLbbi2p1UiyO/ m4Epx+Sx/3yrse+gGvUPuuvvdUSvfVsTTpeHoeXgl8Ng6c4IAuyg1cf8sCFjF4Z0R3oD 06e7lSsQs5nnXDcKE3RMooofMX+Wu477tKDUY0kycu2uI9OGbCsqhqbcUHak8EGAehcs Pux2tGI5Zbf982Z/W7ky++8/TlMZeXPqjxayeZuEzES7U3/wmtEkq2hOoQk8EstqjOh8 RuCw== X-Gm-Message-State: AOAM533Jja6fyFVShSkYOAxJtFBpouv3msEyk03f9bZcOiyNHmgeOp2M zgq979Z3zOw4+IXADGWjgR4JZkqqfC4= X-Google-Smtp-Source: ABdhPJyttgV5zzhi+JYy8LFONpuBmZbJQ1R94Y5F+QrX/UTfIPjq2972dbbMhfGt52HdR28mm+uHAA== X-Received: by 2002:a05:600c:3009:b0:381:194a:8cb5 with SMTP id j9-20020a05600c300900b00381194a8cb5mr903718wmh.43.1645695942510; Thu, 24 Feb 2022 01:45:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id az7sm2296332wmb.14.2022.02.24.01.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 01:45:42 -0800 (PST) Message-Id: <89efc1e15646599753baeab38ba2399dcbe868f1.1645695940.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 24 Feb 2022 09:45:38 +0000 Subject: [PATCH 1/3] merge: new autosetupmerge option 'simple' for matching branches Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Tao Klerks , Tao Klerks Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Tao Klerks From: Tao Klerks The push.defaut option "simple" helps produce predictable/understandable behavior for beginners, where they don't accidentally push to the "wrong" branch in centralized workflows. If they create a local branch with a different name and then try to do a plain push, it will helpfully fail and explain why. However, such users can often find themselves confused by the behavior of git after they first branch, and before they push. At that stage, their upstream tracking branch is the original remote branch, and pull (for example) behaves very differently to how it later does when they create their own same-name remote branch. This commit introduces a new option to the branch.autosetupmerge setting, "simple", which is intended to be consistent with and complementary to the push.default "simple" option. It will set up automatic tracking for a new branch only if the remote ref is a branch and that remote branch name matches the new local branch name. It is a reduction in scope of the existing default option, "true". Signed-off-by: Tao Klerks --- branch.c | 9 +++++++++ branch.h | 1 + config.c | 3 +++ 3 files changed, 13 insertions(+) diff --git a/branch.c b/branch.c index 6b31df539a5..246bc82ce3c 100644 --- a/branch.c +++ b/branch.c @@ -256,6 +256,15 @@ static void setup_tracking(const char *new_ref, const char *orig_ref, die(_("not tracking: ambiguous information for ref %s"), orig_ref); + if (track == BRANCH_TRACK_SIMPLE) { + // only track if remote branch name matches + // (tracking.srcs must contain only one entry from find_tracked_branch with this config) + if (strncmp(tracking.srcs->items[0].string, "refs/heads/", 11)) + return; + if (strcmp(tracking.srcs->items[0].string + 11, new_ref)) + return; + } + if (tracking.srcs->nr < 1) string_list_append(tracking.srcs, orig_ref); if (install_branch_config_multiple_remotes(config_flags, new_ref, diff --git a/branch.h b/branch.h index 04df2aa5b51..560b6b96a8f 100644 --- a/branch.h +++ b/branch.h @@ -12,6 +12,7 @@ enum branch_track { BRANCH_TRACK_EXPLICIT, BRANCH_TRACK_OVERRIDE, BRANCH_TRACK_INHERIT, + BRANCH_TRACK_SIMPLE, }; extern enum branch_track git_branch_track; diff --git a/config.c b/config.c index e0c03d154c9..cc586ac816c 100644 --- a/config.c +++ b/config.c @@ -1673,6 +1673,9 @@ static int git_default_branch_config(const char *var, const char *value) } else if (value && !strcmp(value, "inherit")) { git_branch_track = BRANCH_TRACK_INHERIT; return 0; + } else if (value && !strcmp(value, "simple")) { + git_branch_track = BRANCH_TRACK_SIMPLE; + return 0; } git_branch_track = git_config_bool(var, value); return 0; From patchwork Thu Feb 24 09:45:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Klerks X-Patchwork-Id: 12758264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D47D5C433EF for ; Thu, 24 Feb 2022 09:45:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232954AbiBXJqS (ORCPT ); Thu, 24 Feb 2022 04:46:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbiBXJqO (ORCPT ); Thu, 24 Feb 2022 04:46:14 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6A4C27DF31 for ; Thu, 24 Feb 2022 01:45:44 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id d3so2069105wrf.1 for ; Thu, 24 Feb 2022 01:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=CHO3b+gzF10EA/23VddWYWYEc6YiXFZ678veEngIMvY=; b=cpGoBsUfNerTDlfuYVgYWKdzoLewwmloRRc91t/tendUpALjw9P4CFcFmMt97T9Iyv WtHwPhkGZQndKfCNF+3ZsHx5safKrm17DBOW0E6D6tJIdsZx6OCCbQXiLsJ2bIL/+594 mP238jU7v2V84Ugsfz9cq0GZqTHGS+RYiebiuxuKHC9vNT/8u+yIDA/aARwaJLhv2ErH KdD8txwTXhuAiU78yxaKEcbTDaf/293yX7UM4OlKqkDTdbzbY6nDg1HMNcZDa7HgkbpB RoVdssD0T0sROGw7w2E/Uphs0H6/M8KYYTPoa/bIyyeoYUWkvJ5b1wgveEOGuXs6b/da R9Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=CHO3b+gzF10EA/23VddWYWYEc6YiXFZ678veEngIMvY=; b=8A2JvnOO9v8tJUNjZnldJ3UVZ2xcyE7M6j9fk32Zs4rU/JD99dP3pXp0iYjbwfjo8S hNjp3ioZXML8gQ5UWCePtc9m24s3qhU+lfBnQJcgnpnAiMGq6P88NMQHDlw3CinPibsg OB8vEG3ScunOuRIWZI9pdxq4BWF4hmSuLQdhVasQJ558uCsfPP11j3hmFW1iB16E9K2K XP9MbYwxTKJ7u7ztbjRX71sYjPM5cZIeepEHXHvEAPM7vs1pzlK/g7VlleogT+js8jVE UTasf1qYP93D/TkoDCpAXJaRV42/nq4iBDQ9QD4klau92mYxQfc5hCHPvm2H49byPyDG ppfA== X-Gm-Message-State: AOAM5325pgb4M6QwAuHVqY5TVrrpQiGRe63dUEYi820zhkr97XBiwJrW bGeZvPWryk+Lg//UPgQhCO71jqaULj0= X-Google-Smtp-Source: ABdhPJxyHcvZraSmdlCNew8WMArXyzM28VdI6RFhFMfNM4+6X188aosDaVFm5y9gHvfSPm79CzNXeA== X-Received: by 2002:a5d:5265:0:b0:1ed:9df7:a09 with SMTP id l5-20020a5d5265000000b001ed9df70a09mr1530709wrc.614.1645695943389; Thu, 24 Feb 2022 01:45:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l5sm2172685wmq.7.2022.02.24.01.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 01:45:43 -0800 (PST) Message-Id: <3fa56f1d2a0dfbb41df2a38a6b0ea26333915eda.1645695940.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 24 Feb 2022 09:45:39 +0000 Subject: [PATCH 2/3] t3200: tests for new branch.autosetupmerge option "simple" Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Tao Klerks , Tao Klerks Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Tao Klerks From: Tao Klerks In the previous commit a new autosetupmerge option was introduced. Here the existing branch tests are extended with three new cases testing this option - the obvious matching-name and non-matching-name cases, and also a non-matching-ref-type case. The matching-name case needs to temporarily create an independent repo to fetch from, as the general strategy in these tests of using the local repo as the remote precludes locally branching with the same name as the "remote". Signed-off-by: Tao Klerks --- t/t3200-branch.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 7a0ff75ba86..15cc58f1e64 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -886,6 +886,41 @@ test_expect_success 'branch from tag w/--track causes failure' ' test_must_fail git branch --track my11 foobar ' +test_expect_success 'simple tracking works when remote branch name matches' ' + test_create_repo otherserver && + test_commit -C otherserver my_commit 1 && + git -C otherserver branch feature && + git config branch.autosetupmerge simple && + git config remote.otherserver.url otherserver && + git config remote.otherserver.fetch refs/heads/*:refs/remotes/otherserver/* && + git fetch otherserver && + git branch feature otherserver/feature && + rm -fr otherserver && + test $(git config branch.feature.remote) = otherserver && + test $(git config branch.feature.merge) = refs/heads/feature +' + +test_expect_success 'simple tracking skips when remote branch name does not match' ' + git config branch.autosetupmerge simple && + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/main || git fetch local) && + git branch my-other local/main && + test -z "$(git config branch.my-other.remote)" && + test -z "$(git config branch.my-other.merge)" +' + +test_expect_success 'simple tracking skips when remote ref is not a branch' ' + git config branch.autosetupmerge simple && + git tag mytag12 main && + git config remote.localtags.url . && + git config remote.localtags.fetch refs/tags/*:refs/remotes/localtags/* && + (git show-ref -q refs/remotes/localtags/mytag12 || git fetch localtags) && + git branch mytag12 localtags/mytag12 && + test -z "$(git config branch.mytag12.remote)" && + test -z "$(git config branch.mytag12.merge)" +' + test_expect_success '--set-upstream-to fails on multiple branches' ' echo "fatal: too many arguments to set new upstream" >expect && test_must_fail git branch --set-upstream-to main a b c 2>err && From patchwork Thu Feb 24 09:45:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Klerks X-Patchwork-Id: 12758265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC672C433EF for ; Thu, 24 Feb 2022 09:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232958AbiBXJqS (ORCPT ); Thu, 24 Feb 2022 04:46:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232956AbiBXJqP (ORCPT ); Thu, 24 Feb 2022 04:46:15 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A29D827DF33 for ; Thu, 24 Feb 2022 01:45:45 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id d17so2024469wrc.9 for ; Thu, 24 Feb 2022 01:45:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=3by/pYzrUDkwgiC3YbPUoswDWdfmTup0+7dz39uoq90=; b=j/aYRwAJ1IN1KYIjpiBcckJncUOuz5ofPLBUAlzBb4pSbtvxdDMuaRowwjFk9B+nix zmQbvTU39boqMYiSPiDU8B2Nw/uqgH3U4GykrTtQaqPXNPx9Pb9LFJWbWKYjI8zq//bD 7V0R4NwX9epSUfnib5QGEB+t6yFxKtDGkdD+BZx7shd35s0m3NEbvV0aMFcNa2RaO52S M8ze2UZnOLp4Wt94qMILXdaxFyjq2HMXKnpf1YnDDxp4KQ6/tNA7Go5geFyOIiPm9A63 u0/GSAsEfxpBAkn/TQdvFBrnHUIpf47YMWcaGOREMxDSIC3R3mVkZCItEh3nMykFC7KW 5sGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=3by/pYzrUDkwgiC3YbPUoswDWdfmTup0+7dz39uoq90=; b=SWbJOMot5xWfL031mIHRU+F3y5+Z541QgRBhi9DOQaHiZJRVjCbiHox6lULvQCBXNm 6KhCZWiLR4cZ6lb3mCX97l9qsv7It13PgUORs76k6CL9iny47yT4nYhHRDfK5heO8n4Y kN29VYZych2lSUXH3Q8bmRGIepvQYCKyeA8/W1X7WipW0FWhfvl+19kdOtCU/oyO1xDp LJUDQKD+2tAoOodvkzgHY0EueuUAMw5IkarGf7bDqzz0wD8kL/SRxBvQ1H5elhMtOs35 DH3p5q+z6MVMBKdhEJ5vPIy14Xu6RreIabOv2npwvXUcxaJ7XtlLWF+xPypd1t13yAq4 eQSA== X-Gm-Message-State: AOAM532yRiu2QGlk8w0evixGdeTfJqctpim15JuL8IgoXJDGEtXVTxFz se4pXDK7Vhf1/Q/Mr0wisGdbem7kLig= X-Google-Smtp-Source: ABdhPJyCoDndVplsVQTgHpWNUGY40Zwd4YHSvVVX+FDvtUDoWeDt+/z+YIjy3hJJe1/GnxEFE/br8g== X-Received: by 2002:a5d:598a:0:b0:1e6:29fa:bab1 with SMTP id n10-20020a5d598a000000b001e629fabab1mr1530569wri.671.1645695944071; Thu, 24 Feb 2022 01:45:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 24sm1921830wmf.48.2022.02.24.01.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 01:45:43 -0800 (PST) Message-Id: <39c14906e7b65843c2543682bb577c6a2253240a.1645695940.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 24 Feb 2022 09:45:40 +0000 Subject: [PATCH 3/3] branch documentation: new autosetupmerge option "simple" Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Tao Klerks , Tao Klerks Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Tao Klerks From: Tao Klerks Updating the branch and config documentation to reflect the new "simple" option to branch.autosetupmerge. Signed-off-by: Tao Klerks --- Documentation/config/branch.txt | 4 +++- Documentation/git-branch.txt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/config/branch.txt b/Documentation/config/branch.txt index 1e0c7af014b..7b4e5ca5b74 100644 --- a/Documentation/config/branch.txt +++ b/Documentation/config/branch.txt @@ -9,7 +9,9 @@ branch.autoSetupMerge:: automatic setup is done when the starting point is either a local branch or remote-tracking branch; `inherit` -- if the starting point has a tracking configuration, it is copied to the new - branch. This option defaults to true. + branch; `simple` -- automatic setup is done when the starting point is + a remote-tracking branch and the new branch has the same name as the + remote branch. This option defaults to true. branch.autoSetupRebase:: When a new branch is created with 'git branch', 'git switch' or 'git checkout' diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index c8b4f9ce3c7..f99d6a6b008 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -227,7 +227,9 @@ want `git switch`, `git checkout` and `git branch` to always behave as if `--no- were given. Set it to `always` if you want this behavior when the start-point is either a local or remote-tracking branch. Set it to `inherit` if you want to copy the tracking configuration from the -branch point. +branch point. Set it to `simple` if you want this behavior only when +the start-point is a remote branch and the new branch has the same name +as the remote branch. + See linkgit:git-pull[1] and linkgit:git-config[1] for additional discussion on how the `branch..remote` and `branch..merge` options are used.