Merge branch 'es/doc-gitsubmodules-markup'
[git/raj.git] / t / t3204-branch-name-interpretation.sh
blob698d9cc4f3d65754552b8ccdd46b0cb64aea09c5
1 #!/bin/sh
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 . ./test-lib.sh
11 expect_branch() {
12 git log -1 --format=%s "$1" >actual &&
13 echo "$2" >expect &&
14 test_cmp expect actual
17 expect_deleted() {
18 test_must_fail git rev-parse --verify "$1"
21 test_expect_success 'set up repo' '
22 test_commit one &&
23 test_commit two &&
24 git remote add origin foo.git
27 test_expect_success 'update branch via @{-1}' '
28 git branch previous one &&
30 git checkout previous &&
31 git checkout master &&
33 git branch -f @{-1} two &&
34 expect_branch previous two
37 test_expect_success 'update branch via local @{upstream}' '
38 git branch local one &&
39 git branch --set-upstream-to=local &&
41 git branch -f @{upstream} two &&
42 expect_branch local two
45 test_expect_success 'disallow updating branch via remote @{upstream}' '
46 git update-ref refs/remotes/origin/remote one &&
47 git branch --set-upstream-to=origin/remote &&
49 test_must_fail git branch -f @{upstream} two
52 test_expect_success 'create branch with pseudo-qualified name' '
53 git branch refs/heads/qualified two &&
54 expect_branch refs/heads/refs/heads/qualified two
57 test_expect_success 'delete branch via @{-1}' '
58 git branch previous-del &&
60 git checkout previous-del &&
61 git checkout master &&
63 git branch -D @{-1} &&
64 expect_deleted previous-del
67 test_expect_success 'delete branch via local @{upstream}' '
68 git branch local-del &&
69 git branch --set-upstream-to=local-del &&
71 git branch -D @{upstream} &&
72 expect_deleted local-del
75 test_expect_success 'delete branch via remote @{upstream}' '
76 git update-ref refs/remotes/origin/remote-del two &&
77 git branch --set-upstream-to=origin/remote-del &&
79 git branch -r -D @{upstream} &&
80 expect_deleted origin/remote-del
83 # Note that we create two oddly named local branches here. We want to make
84 # sure that we do not accidentally delete either of them, even if
85 # shorten_unambiguous_ref() tweaks the name to avoid ambiguity.
86 test_expect_success 'delete @{upstream} expansion matches -r option' '
87 git update-ref refs/remotes/origin/remote-del two &&
88 git branch --set-upstream-to=origin/remote-del &&
89 git update-ref refs/heads/origin/remote-del two &&
90 git update-ref refs/heads/remotes/origin/remote-del two &&
92 test_must_fail git branch -D @{upstream} &&
93 expect_branch refs/heads/origin/remote-del two &&
94 expect_branch refs/heads/remotes/origin/remote-del two
97 test_expect_success 'disallow deleting remote branch via @{-1}' '
98 git update-ref refs/remotes/origin/previous one &&
100 git checkout -b origin/previous two &&
101 git checkout master &&
103 test_must_fail git branch -r -D @{-1} &&
104 expect_branch refs/remotes/origin/previous one &&
105 expect_branch refs/heads/origin/previous two
108 # The thing we are testing here is that "@" is the real branch refs/heads/@,
109 # and not refs/heads/HEAD. These tests should not imply that refs/heads/@ is a
110 # sane thing, but it _is_ technically allowed for now. If we disallow it, these
111 # can be switched to test_must_fail.
112 test_expect_success 'create branch named "@"' '
113 git branch -f @ one &&
114 expect_branch refs/heads/@ one
117 test_expect_success 'delete branch named "@"' '
118 git update-ref refs/heads/@ two &&
119 git branch -D @ &&
120 expect_deleted refs/heads/@
123 test_expect_success 'checkout does not treat remote @{upstream} as a branch' '
124 git update-ref refs/remotes/origin/checkout one &&
125 git branch --set-upstream-to=origin/checkout &&
126 git update-ref refs/heads/origin/checkout two &&
127 git update-ref refs/heads/remotes/origin/checkout two &&
129 git checkout @{upstream} &&
130 expect_branch HEAD one
133 test_done