3 test_description
='interpreting exotic branch name arguments
5 Branch name arguments are usually names which are taken to be inside of
6 refs/heads/, but we interpret some magic syntax like @{-1}, @{upstream}, etc.
7 This script aims to check the behavior of those corner cases.
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15 git log
-1 --format=%s
"$1" >actual
&&
17 test_cmp expect actual
21 test_must_fail git rev-parse
--verify "$1"
24 test_expect_success
'set up repo' '
27 git remote add origin foo.git
30 test_expect_success
'update branch via @{-1}' '
31 git branch previous one &&
33 git checkout previous &&
36 git branch -f @{-1} two &&
37 expect_branch previous two
40 test_expect_success
'update branch via local @{upstream}' '
41 git branch local one &&
42 git branch --set-upstream-to=local &&
44 git branch -f @{upstream} two &&
45 expect_branch local two
48 test_expect_success
'disallow updating branch via remote @{upstream}' '
49 git update-ref refs/remotes/origin/remote one &&
50 git branch --set-upstream-to=origin/remote &&
52 test_must_fail git branch -f @{upstream} two
55 test_expect_success
'create branch with pseudo-qualified name' '
56 git branch refs/heads/qualified two &&
57 expect_branch refs/heads/refs/heads/qualified two
60 test_expect_success
'delete branch via @{-1}' '
61 git branch previous-del &&
63 git checkout previous-del &&
66 git branch -D @{-1} &&
67 expect_deleted previous-del
70 test_expect_success
'delete branch via local @{upstream}' '
71 git branch local-del &&
72 git branch --set-upstream-to=local-del &&
74 git branch -D @{upstream} &&
75 expect_deleted local-del
78 test_expect_success
'delete branch via remote @{upstream}' '
79 git update-ref refs/remotes/origin/remote-del two &&
80 git branch --set-upstream-to=origin/remote-del &&
82 git branch -r -D @{upstream} &&
83 expect_deleted origin/remote-del
86 # Note that we create two oddly named local branches here. We want to make
87 # sure that we do not accidentally delete either of them, even if
88 # shorten_unambiguous_ref() tweaks the name to avoid ambiguity.
89 test_expect_success
'delete @{upstream} expansion matches -r option' '
90 git update-ref refs/remotes/origin/remote-del two &&
91 git branch --set-upstream-to=origin/remote-del &&
92 git update-ref refs/heads/origin/remote-del two &&
93 git update-ref refs/heads/remotes/origin/remote-del two &&
95 test_must_fail git branch -D @{upstream} &&
96 expect_branch refs/heads/origin/remote-del two &&
97 expect_branch refs/heads/remotes/origin/remote-del two
100 test_expect_success
'disallow deleting remote branch via @{-1}' '
101 git update-ref refs/remotes/origin/previous one &&
103 git checkout -b origin/previous two &&
106 test_must_fail git branch -r -D @{-1} &&
107 expect_branch refs/remotes/origin/previous one &&
108 expect_branch refs/heads/origin/previous two
111 # The thing we are testing here is that "@" is the real branch refs/heads/@,
112 # and not refs/heads/HEAD. These tests should not imply that refs/heads/@ is a
113 # sane thing, but it _is_ technically allowed for now. If we disallow it, these
114 # can be switched to test_must_fail.
115 test_expect_success
'create branch named "@"' '
116 git branch -f @ one &&
117 expect_branch refs/heads/@ one
120 test_expect_success
'delete branch named "@"' '
121 git update-ref refs/heads/@ two &&
123 expect_deleted refs/heads/@
126 test_expect_success
'checkout does not treat remote @{upstream} as a branch' '
127 git update-ref refs/remotes/origin/checkout one &&
128 git branch --set-upstream-to=origin/checkout &&
129 git update-ref refs/heads/origin/checkout two &&
130 git update-ref refs/heads/remotes/origin/checkout two &&
132 git checkout @{upstream} &&
133 expect_branch HEAD one
136 test_expect_success
'edit-description via @{-1}' '
137 git checkout -b desc-branch &&
138 git checkout -b non-desc-branch &&
139 write_script editor <<-\EOF &&
140 echo "Branch description" >"$1"
142 EDITOR=./editor git branch --edit-description @{-1} &&
143 test_must_fail git config branch.non-desc-branch.description &&
144 git config branch.desc-branch.description >actual &&
145 printf "Branch description\n\n" >expect &&
146 test_cmp expect actual
149 test_expect_success
'modify branch upstream via "@{-1}" and "@{-1}@{upstream}"' '
150 git checkout -b upstream-branch &&
151 git checkout -b upstream-other -t upstream-branch &&
152 git branch --set-upstream-to upstream-other @{-1} &&
153 git config branch.upstream-branch.merge >actual &&
154 echo "refs/heads/upstream-other" >expect &&
155 test_cmp expect actual &&
156 git branch --unset-upstream @{-1}@{upstream} &&
157 test_must_fail git config branch.upstream-other.merge