3 test_description
='tg contains multi-level
5 Test the behavior of tg contains when the branch
6 name and/or the remote name contains multiple
7 levels (i.e. separated with "/" components).
15 test_commit
"${1}initial" &&
16 test_commit
"${1}a" && {
17 br
="$(git symbolic-ref -q HEAD)" ||
18 br
="$(git rev-parse --verify -q HEAD)"; } &&
19 git checkout
--detach -f HEAD^
&&
20 test_commit
"${1}b" &&
21 mc
="$(git rev-parse --verify HEAD)" &&
22 git checkout
-f "${br#refs/heads/}" &&
23 git merge
-m "merge ${1}a and ${1}b" "$mc" &&
25 test_commit
"${1}after"
29 git checkout
--detach empty
&&
30 { git update-ref
-d "refs/heads/$1" >/dev
/null
2>&1 ||
:; } &&
31 git checkout
--orphan "$1"
34 test_expect_success
'setup' '
35 git config core.logallrefupdates false &&
36 git config advice.detachedHead false &&
37 git checkout --orphan empty &&
39 git commit --allow-empty -m empty &&
40 mtc="$(git rev-parse --verify HEAD)" &&
42 git checkout --orphan build &&
43 git update-ref -d refs/heads/empty &&
44 # first/second/third/fourth
46 make_commits "fstfpre" &&
47 tg_test_create_branch first/second/third/fourth :HEAD &&
48 git checkout -f first/second/third/fourth &&
49 make_commits "fstf" &&
50 git checkout -f -B build &&
51 make_commits "fstfpost" &&
54 make_commits "uapre" &&
55 tg_test_create_branch alpha:unu :HEAD &&
56 git update-ref HEAD refs/remotes/alpha/unu &&
57 make_commits "unu@alpha" &&
58 git update-ref refs/remotes/alpha/unu HEAD &&
59 make_commits "uapost" &&
62 make_commits "dtkapre" &&
63 tg_test_create_branch alpha:du/tri/kvar :HEAD &&
64 git update-ref HEAD refs/remotes/alpha/du/tri/kvar &&
65 make_commits "du_tri_kvar@alpha" &&
66 git update-ref refs/remotes/alpha/du/tri/kvar HEAD &&
67 make_commits "dtkapost" &&
68 # unu beta/gamma/delta
70 make_commits "ubgdpre" &&
71 tg_test_create_branch beta/gamma/delta:unu :HEAD &&
72 git update-ref HEAD refs/remotes/beta/gamma/delta/unu &&
73 make_commits "unu@beta_gamma_delta" &&
74 git update-ref refs/remotes/beta/gamma/delta/unu HEAD &&
75 make_commits "ubgdpost" &&
76 # du/tri/kvar beta/gamma/delta
78 make_commits "dtkbgdpre" &&
79 tg_test_create_branch beta/gamma/delta:du/tri/kvar :HEAD &&
80 git update-ref HEAD refs/remotes/beta/gamma/delta/du/tri/kvar &&
81 make_commits "du_tri_kvar@beta_gamma_delta" &&
82 git update-ref refs/remotes/beta/gamma/delta/du/tri/kvar HEAD &&
83 make_commits "dtkbgdpost" &&
84 git checkout -f empty &&
85 git update-ref -d refs/heads/build &&
87 git pack-refs --prune --all &&
88 refcnt=$(git for-each-ref | wc -l) &&
89 test "$refcnt" = 86 &&
90 topbases="$(tg --top-bases)" &&
91 topbases="${topbases#refs/}" &&
92 test -n "$topbases" &&
93 test_when_finished topbases="$topbases" &&
94 test_when_finished test_set_prereq SETUP
97 test_expect_success SETUP
'non-remote multi-level contains' '
98 h="$(git rev-parse --verify -q fstfb)" &&
99 tb="$(tg contains -v -r --ann $h)" &&
100 test "$tb" = "first/second/third/fourth [first/second/third/fourth]"
103 test_expect_success SETUP
'non-remote multi-level contains --no-strict' '
104 h="$(git rev-parse --verify -q fstfpreb)" &&
105 { tb="$(tg contains -v --strict -r --ann $h)" || :; } &&
107 tb="$(tg contains -v --no-strict -r --ann $h)" &&
108 test "$tb" = "first/second/third/fourth [first/second/third/fourth]"
111 test_expect_success SETUP
'remote single-level contains fails without -r' '
112 h="$(git rev-parse --verify -q unu@alpham)" &&
113 { tb="$(tg contains -v --strict --ann $h)" || :; } &&
115 { tb="$(tg contains -v --no-strict --ann $h)" || :; } &&
117 tb="$(tg contains -v --strict -r --ann $h)" &&
118 test "$tb" = "remotes/alpha/unu" &&
119 tb="$(tg contains -v --no-strict -r --ann $h)" &&
120 test "$tb" = "remotes/alpha/unu"
123 test_expect_success SETUP
'remote multi-level branch single-level remote' '
124 h="$(git rev-parse --verify -q du_tri_kvar@alphab)" &&
125 tb="$(tg contains -v --strict -r --ann $h)" &&
126 test "$tb" = "remotes/alpha/du/tri/kvar" &&
127 tb="$(tg contains -v --no-strict -r --ann $h)" &&
128 test "$tb" = "remotes/alpha/du/tri/kvar"
131 test_expect_success SETUP
'remote single-level branch multi-level remote' '
132 h="$(git rev-parse --verify -q unu@beta_gamma_deltaa)" &&
133 tb="$(tg contains -v --strict -r --ann $h)" &&
134 test "$tb" = "remotes/beta/gamma/delta/unu" &&
135 tb="$(tg contains -v --no-strict -r --ann $h)" &&
136 test "$tb" = "remotes/beta/gamma/delta/unu"
139 test_expect_success SETUP
'remote multi-level branch multi-level remote' '
140 h="$(git rev-parse --verify -q du_tri_kvar@beta_gamma_deltam)" &&
141 tb="$(tg contains -v --strict -r --ann $h)" &&
142 test "$tb" = "remotes/beta/gamma/delta/du/tri/kvar" &&
143 tb="$(tg contains -v --no-strict -r --ann $h)" &&
144 test "$tb" = "remotes/beta/gamma/delta/du/tri/kvar"