summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2022-01-10 11:52:54 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2022-01-10 11:52:54 -0800
commit0669bdf4ebc095a2b26654292e1ff38245ccf88a (patch)
treee1cbee05b782fabade7aefc3767ffdbf28f75dfd /t
parentMerge branch 'ab/usage-die-message' (diff)
parentconfig: require lowercase for branch.*.autosetupmerge (diff)
downloadtgif-0669bdf4ebc095a2b26654292e1ff38245ccf88a.tar.xz
Merge branch 'js/branch-track-inherit'
"git -c branch.autosetupmerge=inherit branch new old" makes "new" to have the same upstream as the "old" branch, instead of marking "old" itself as its upstream. * js/branch-track-inherit: config: require lowercase for branch.*.autosetupmerge branch: add flags and config to inherit tracking branch: accept multiple upstream branches for tracking
Diffstat (limited to 't')
-rwxr-xr-xt/t2017-checkout-orphan.sh11
-rwxr-xr-xt/t2027-checkout-track.sh23
-rwxr-xr-xt/t2060-switch.sh28
-rwxr-xr-xt/t3200-branch.sh39
-rwxr-xr-xt/t7201-co.sh17
5 files changed, 114 insertions, 4 deletions
diff --git a/t/t2017-checkout-orphan.sh b/t/t2017-checkout-orphan.sh
index f3371e2646..947d1587ac 100755
--- a/t/t2017-checkout-orphan.sh
+++ b/t/t2017-checkout-orphan.sh
@@ -63,8 +63,17 @@ test_expect_success '--orphan ignores branch.autosetupmerge' '
git checkout main &&
git config branch.autosetupmerge always &&
git checkout --orphan gamma &&
- test -z "$(git config branch.gamma.merge)" &&
+ test_cmp_config "" --default "" branch.gamma.merge &&
test refs/heads/gamma = "$(git symbolic-ref HEAD)" &&
+ test_must_fail git rev-parse --verify HEAD^ &&
+ git checkout main &&
+ git config branch.autosetupmerge inherit &&
+ git checkout --orphan eta &&
+ test_cmp_config "" --default "" branch.eta.merge &&
+ test_cmp_config "" --default "" branch.eta.remote &&
+ echo refs/heads/eta >expected &&
+ git symbolic-ref HEAD >actual &&
+ test_cmp expected actual &&
test_must_fail git rev-parse --verify HEAD^
'
diff --git a/t/t2027-checkout-track.sh b/t/t2027-checkout-track.sh
index 4453741b96..dca35aa3e3 100755
--- a/t/t2027-checkout-track.sh
+++ b/t/t2027-checkout-track.sh
@@ -24,4 +24,27 @@ test_expect_success 'checkout --track -b rejects an extra path argument' '
test_i18ngrep "cannot be used with updating paths" err
'
+test_expect_success 'checkout --track -b overrides autoSetupMerge=inherit' '
+ # Set up tracking config on main
+ test_config branch.main.remote origin &&
+ test_config branch.main.merge refs/heads/some-branch &&
+ test_config branch.autoSetupMerge inherit &&
+ # With --track=inherit, we copy the tracking config from main
+ git checkout --track=inherit -b b1 main &&
+ test_cmp_config origin branch.b1.remote &&
+ test_cmp_config refs/heads/some-branch branch.b1.merge &&
+ # With branch.autoSetupMerge=inherit, we do the same
+ git checkout -b b2 main &&
+ test_cmp_config origin branch.b2.remote &&
+ test_cmp_config refs/heads/some-branch branch.b2.merge &&
+ # But --track overrides this
+ git checkout --track -b b3 main &&
+ test_cmp_config . branch.b3.remote &&
+ test_cmp_config refs/heads/main branch.b3.merge &&
+ # And --track=direct does as well
+ git checkout --track=direct -b b4 main &&
+ test_cmp_config . branch.b4.remote &&
+ test_cmp_config refs/heads/main branch.b4.merge
+'
+
test_done
diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh
index 9bc6a3aa5c..ebb961be29 100755
--- a/t/t2060-switch.sh
+++ b/t/t2060-switch.sh
@@ -107,4 +107,32 @@ test_expect_success 'not switching when something is in progress' '
test_must_fail git switch -d @^
'
+test_expect_success 'tracking info copied with autoSetupMerge=inherit' '
+ # default config does not copy tracking info
+ git switch -c foo-no-inherit foo &&
+ test_cmp_config "" --default "" branch.foo-no-inherit.remote &&
+ test_cmp_config "" --default "" branch.foo-no-inherit.merge &&
+ # with --track=inherit, we copy tracking info from foo
+ git switch --track=inherit -c foo2 foo &&
+ test_cmp_config origin branch.foo2.remote &&
+ test_cmp_config refs/heads/foo branch.foo2.merge &&
+ # with autoSetupMerge=inherit, we do the same
+ test_config branch.autoSetupMerge inherit &&
+ git switch -c foo3 foo &&
+ test_cmp_config origin branch.foo3.remote &&
+ test_cmp_config refs/heads/foo branch.foo3.merge &&
+ # with --track, we override autoSetupMerge
+ git switch --track -c foo4 foo &&
+ test_cmp_config . branch.foo4.remote &&
+ test_cmp_config refs/heads/foo branch.foo4.merge &&
+ # and --track=direct does as well
+ git switch --track=direct -c foo5 foo &&
+ test_cmp_config . branch.foo5.remote &&
+ test_cmp_config refs/heads/foo branch.foo5.merge &&
+ # no tracking info to inherit from main
+ git switch -c main2 main &&
+ test_cmp_config "" --default "" branch.main2.remote &&
+ test_cmp_config "" --default "" branch.main2.merge
+'
+
test_done
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 8a619d785e..1bc3795847 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -979,15 +979,15 @@ test_expect_success 'disabled option --set-upstream fails' '
test_must_fail git branch --set-upstream origin/main
'
-test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
+test_expect_success '--set-upstream-to notices an error to set branch as own upstream' "
git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
cat >expect <<-\EOF &&
- warning: not setting branch my13 as its own upstream
+ warning: not setting branch 'my13' as its own upstream
EOF
test_expect_code 1 git config branch.my13.remote &&
test_expect_code 1 git config branch.my13.merge &&
test_cmp expect actual
-'
+"
# Keep this test last, as it changes the current branch
cat >expect <<EOF
@@ -1461,4 +1461,37 @@ test_expect_success 'invalid sort parameter in configuration' '
)
'
+test_expect_success 'tracking info copied with --track=inherit' '
+ git branch --track=inherit foo2 my1 &&
+ test_cmp_config local branch.foo2.remote &&
+ test_cmp_config refs/heads/main branch.foo2.merge
+'
+
+test_expect_success 'tracking info copied with autoSetupMerge=inherit' '
+ test_unconfig branch.autoSetupMerge &&
+ # default config does not copy tracking info
+ git branch foo-no-inherit my1 &&
+ test_cmp_config "" --default "" branch.foo-no-inherit.remote &&
+ test_cmp_config "" --default "" branch.foo-no-inherit.merge &&
+ # with autoSetupMerge=inherit, we copy tracking info from my1
+ test_config branch.autoSetupMerge inherit &&
+ git branch foo3 my1 &&
+ test_cmp_config local branch.foo3.remote &&
+ test_cmp_config refs/heads/main branch.foo3.merge &&
+ # no tracking info to inherit from main
+ git branch main2 main &&
+ test_cmp_config "" --default "" branch.main2.remote &&
+ test_cmp_config "" --default "" branch.main2.merge
+'
+
+test_expect_success '--track overrides branch.autoSetupMerge' '
+ test_config branch.autoSetupMerge inherit &&
+ git branch --track=direct foo4 my1 &&
+ test_cmp_config . branch.foo4.remote &&
+ test_cmp_config refs/heads/my1 branch.foo4.merge &&
+ git branch --no-track foo5 my1 &&
+ test_cmp_config "" --default "" branch.foo5.remote &&
+ test_cmp_config "" --default "" branch.foo5.merge
+'
+
test_done
diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index b7ba1c3268..61ad47b0c1 100755
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
@@ -658,4 +658,21 @@ test_expect_success 'custom merge driver with checkout -m' '
test_cmp expect arm
'
+test_expect_success 'tracking info copied with autoSetupMerge=inherit' '
+ git reset --hard main &&
+ # default config does not copy tracking info
+ git checkout -b foo-no-inherit koala/bear &&
+ test_cmp_config "" --default "" branch.foo-no-inherit.remote &&
+ test_cmp_config "" --default "" branch.foo-no-inherit.merge &&
+ # with autoSetupMerge=inherit, we copy tracking info from koala/bear
+ test_config branch.autoSetupMerge inherit &&
+ git checkout -b foo koala/bear &&
+ test_cmp_config origin branch.foo.remote &&
+ test_cmp_config refs/heads/koala/bear branch.foo.merge &&
+ # no tracking info to inherit from main
+ git checkout -b main2 main &&
+ test_cmp_config "" --default "" branch.main2.remote &&
+ test_cmp_config "" --default "" branch.main2.merge
+'
+
test_done