tg.sh: handle help -h
[topgit/pro.git] / t / t1020-top-bases-sniff-out.sh
blob01a3904cf9b97128c33b9f58db5eee8a83860aad
1 #!/bin/sh
3 test_description='tg --top-bases gets the right answer
5 We also use this to test the functionality of the tg -c option.
8 TEST_NO_CREATE_REPO=1
10 . ./test-lib.sh
12 if vcmp "$tg_version" '>=' '0.19.20'; then
13 deftopbases='refs/heads/{top-bases}'
14 else
15 deftopbases='refs/top-bases'
18 test_plan 18
20 test_expect_success 'no repo refs bases default' '
21 test_must_fail tg status >/dev/null 2>&1 &&
22 test "$(tg --top-bases)" = "$deftopbases"
25 test_expect_success 'no repo hard-coded refs bases' '
26 test_must_fail tg status >/dev/null 2>&1 &&
27 test_must_fail tg -c topgit.top-bases=bad --top-bases &&
28 test "$(tg -c topgit.top-bases=refs --top-bases)" = "refs/top-bases" &&
29 test "$(tg -c topgit.top-bases=heads -c topgit.top-bases=refs --top-bases)" = "refs/top-bases"
32 test_expect_success 'test setup' '
33 test_create_repo noset-mt &&
34 test_create_repo noset-refs &&
35 test_create_repo noset-heads &&
36 test_create_repo noset-both &&
37 test_create_repo refs &&
38 test_create_repo heads &&
39 git -C refs config topgit.top-bases refs &&
40 git -C heads config topgit.top-bases heads &&
41 test "$(cd refs && git config topgit.top-bases)" = "refs" &&
42 test "$(cd heads && git config topgit.top-bases)" = "heads" &&
43 test "$(cd noset-mt && git config --get topgit.top-bases)" = "" &&
44 test "$(cd noset-refs && git config --get topgit.top-bases)" = "" &&
45 test "$(cd noset-heads && git config --get topgit.top-bases)" = "" &&
46 test "$(cd noset-both && git config --get topgit.top-bases)" = "" &&
47 (cd noset-refs && test_commit initial) &&
48 (cd noset-heads && test_commit initial) &&
49 (cd noset-both && test_commit initial) &&
50 git -C noset-refs update-ref refs/heads/t/branch master &&
51 git -C noset-refs update-ref refs/top-bases/t/branch master &&
52 git -C noset-heads update-ref refs/heads/t/branch master &&
53 git -C noset-heads update-ref refs/heads/{top-bases}/t/branch master &&
54 git -C noset-both update-ref refs/heads/t/branch master &&
55 git -C noset-both update-ref refs/top-bases/t/branch master &&
56 git -C noset-both update-ref refs/heads/{top-bases}/t/branch master &&
57 git -C noset-refs rev-parse --verify t/branch >/dev/null &&
58 git -C noset-refs rev-parse --verify top-bases/t/branch >/dev/null &&
59 git -C noset-heads rev-parse --verify t/branch >/dev/null &&
60 git -C noset-heads rev-parse --verify {top-bases}/t/branch >/dev/null &&
61 git -C noset-both rev-parse --verify t/branch >/dev/null &&
62 git -C noset-both rev-parse --verify top-bases/t/branch >/dev/null &&
63 git -C noset-both rev-parse --verify {top-bases}/t/branch >/dev/null
66 test_expect_success 'hard-coded refs bases' '
67 test "$(tg -C refs --top-bases)" = "refs/top-bases" &&
68 test "$(tg -C noset-mt -c topgit.top-bases=refs --top-bases)" = "refs/top-bases" &&
69 test "$(tg -C noset-mt -c topgit.top-bases=heads -c topgit.top-bases=refs --top-bases)" = "refs/top-bases"
72 test_expect_success 'hard-coded heads bases' '
73 test "$(tg -C heads --top-bases)" = "refs/heads/{top-bases}" &&
74 test "$(tg -C noset-mt -c topgit.top-bases=heads --top-bases)" = "refs/heads/{top-bases}" &&
75 test "$(tg -C noset-mt -c topgit.top-bases=refs -c topgit.top-bases=heads --top-bases)" = "refs/heads/{top-bases}"
78 test_expect_success 'both is confusing and override' '
79 test_must_fail tg -C noset-both --top-bases >/dev/null 2>&1 &&
80 test "$(tg -C noset-both -c topgit.top-bases=refs --top-bases)" = "refs/top-bases" &&
81 test "$(tg -C noset-both -c topgit.top-bases=heads --top-bases)" = "refs/heads/{top-bases}"
84 test_expect_success 'auto detect refs and override' '
85 test "$(tg -C noset-refs --top-bases)" = "refs/top-bases" &&
86 test "$(tg -C noset-refs -c topgit.top-bases=heads --top-bases)" = "refs/heads/{top-bases}"
89 test_expect_success 'auto detect heads and override' '
90 test "$(tg -C noset-heads --top-bases)" = "refs/heads/{top-bases}" &&
91 test "$(tg -C noset-heads -c topgit.top-bases=refs --top-bases)" = "refs/top-bases"
94 test_expect_success 'default is refs until 0.20.0' '
95 test "$(tg -C noset-mt --top-bases)" = "$deftopbases"
98 sane_unset tg_test_bases
100 test_expect_success '--top-bases -r fails with no remote' '
101 test_must_fail tg -C noset-mt --top-bases -r &&
102 test_must_fail tg -C noset-refs --top-bases -r &&
103 test_must_fail tg -C noset-heads --top-bases -r &&
104 test_must_fail tg -C noset-both --top-bases -r
107 test_expect_success '--top-bases -r succeeds with no remote refs' '
108 tg -C noset-mt --top-bases -r origin &&
109 result="$(tg -C noset-refs --top-bases -r origin)" &&
110 test z"$result" = z"refs/remotes/origin/top-bases" &&
111 result="$(tg -C noset-heads --top-bases -r origin)" &&
112 test z"$result" = z"refs/remotes/origin/{top-bases}"
115 test_expect_success '--top-bases -r fails with schizo local bases' '
116 test_must_fail tg -C noset-both --top-bases -r origin
119 test_expect_success 'setup remote branches' '
120 tg_test_bases=refs &&
121 tg_test_create_branch -C noset-mt rmtrefs:brefs :: &&
122 tg_test_create_branch -C noset-mt rmtboth:brefs :: &&
123 tg_test_create_branch -C noset-refs rmtrefs:brefs :: &&
124 tg_test_create_branch -C noset-refs rmtboth:brefs :: &&
125 tg_test_create_branch -C noset-heads rmtrefs:brefs :: &&
126 tg_test_create_branch -C noset-heads rmtboth:brefs :: &&
127 tg_test_create_branch -C noset-both rmtrefs:brefs :: &&
128 tg_test_create_branch -C noset-both rmtboth:brefs :: &&
129 tg_test_bases=heads &&
130 tg_test_create_branch -C noset-mt rmtheads:bheads :: &&
131 tg_test_create_branch -C noset-mt rmtboth:bheads :: &&
132 tg_test_create_branch -C noset-refs rmtheads:bheads :: &&
133 tg_test_create_branch -C noset-refs rmtboth:bheads :: &&
134 tg_test_create_branch -C noset-heads rmtheads:bheads :: &&
135 tg_test_create_branch -C noset-heads rmtboth:bheads :: &&
136 tg_test_create_branch -C noset-both rmtheads:bheads :: &&
137 tg_test_create_branch -C noset-both rmtboth:bheads :: &&
138 unset tg_test_bases
141 test_expect_success '--top-bases -r fails with schizo local bases' '
142 test_must_fail tg -C noset-both --top-bases -r origin
145 test_expect_success '--top-bases -r fails with schizo remote bases' '
146 test_must_fail tg -C noset-mt --top-bases -r rmtboth
149 test_expect_success '--top-bases -r favors local bases location' '
150 result="$(tg -C noset-refs -r rmtrefs --top-bases -r)" &&
151 test z"$result" = z"refs/remotes/rmtrefs/top-bases" &&
152 result="$(tg -C noset-refs -c topgit.remote=rmtheads --top-bases -r)" &&
153 test z"$result" = z"refs/remotes/rmtheads/top-bases" &&
154 result="$(tg -C noset-heads -c topgit.remote=rmtrefs --top-bases -r)" &&
155 test z"$result" = z"refs/remotes/rmtrefs/{top-bases}" &&
156 result="$(tg -C noset-heads -r rmtheads --top-bases -r)" &&
157 test z"$result" = z"refs/remotes/rmtheads/{top-bases}"
160 test_expect_success '--top-bases -r autodetects remote bases location' '
161 result="$(tg -C noset-mt --top-bases -r rmtrefs)" &&
162 test z"$result" = z"refs/remotes/rmtrefs/top-bases" &&
163 result="$(tg -C noset-mt --top-bases -r rmtheads)" &&
164 test z"$result" = z"refs/remotes/rmtheads/{top-bases}"
167 test_expect_success '--top-bases -r topgit.top-bases override trumps all' '
168 for repo in noset-mt noset-refs noset-heads noset-both; do
169 for rmt in rmtrefs rmtheads rmtboth; do
170 result="$(tg -c topgit.top-bases=refs -C "$repo" --top-bases -r "$rmt")" &&
171 test z"$result" = z"refs/remotes/$rmt/top-bases" &&
172 result="$(tg -c topgit.top-bases=heads -C "$repo" --top-bases -r "$rmt")" &&
173 test z"$result" = z"refs/remotes/$rmt/{top-bases}" || return
174 done
175 done
178 test_done