README_DOCS.rst: update tg prev and tg next usage summary
[topgit/pro.git] / t / t1020-top-bases-sniff-out.sh
blobffdba14a5467fe1c71fdbf62381e7eab8057b9bd
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 test_plan 18
14 test_expect_success 'no repo refs bases default' '
15 test_must_fail tg status >/dev/null 2>&1 &&
16 test "$(tg --top-bases)" = "refs/top-bases"
19 test_expect_success 'no repo hard-coded refs bases' '
20 test_must_fail tg status >/dev/null 2>&1 &&
21 test_must_fail tg -c topgit.top-bases=bad --top-bases &&
22 test "$(tg -c topgit.top-bases=refs --top-bases)" = "refs/top-bases" &&
23 test "$(tg -c topgit.top-bases=heads -c topgit.top-bases=refs --top-bases)" = "refs/top-bases"
26 test_expect_success 'test setup' '
27 test_create_repo noset-mt &&
28 test_create_repo noset-refs &&
29 test_create_repo noset-heads &&
30 test_create_repo noset-both &&
31 test_create_repo refs &&
32 test_create_repo heads &&
33 git -C refs config topgit.top-bases refs &&
34 git -C heads config topgit.top-bases heads &&
35 test "$(cd refs && git config topgit.top-bases)" = "refs" &&
36 test "$(cd heads && git config topgit.top-bases)" = "heads" &&
37 test "$(cd noset-mt && git config --get topgit.top-bases)" = "" &&
38 test "$(cd noset-refs && git config --get topgit.top-bases)" = "" &&
39 test "$(cd noset-heads && git config --get topgit.top-bases)" = "" &&
40 test "$(cd noset-both && git config --get topgit.top-bases)" = "" &&
41 (cd noset-refs && test_commit initial) &&
42 (cd noset-heads && test_commit initial) &&
43 (cd noset-both && test_commit initial) &&
44 git -C noset-refs update-ref refs/heads/t/branch master &&
45 git -C noset-refs update-ref refs/top-bases/t/branch master &&
46 git -C noset-heads update-ref refs/heads/t/branch master &&
47 git -C noset-heads update-ref refs/heads/{top-bases}/t/branch master &&
48 git -C noset-both update-ref refs/heads/t/branch master &&
49 git -C noset-both update-ref refs/top-bases/t/branch master &&
50 git -C noset-both update-ref refs/heads/{top-bases}/t/branch master &&
51 git -C noset-refs rev-parse --verify t/branch >/dev/null &&
52 git -C noset-refs rev-parse --verify top-bases/t/branch >/dev/null &&
53 git -C noset-heads rev-parse --verify t/branch >/dev/null &&
54 git -C noset-heads rev-parse --verify {top-bases}/t/branch >/dev/null &&
55 git -C noset-both rev-parse --verify t/branch >/dev/null &&
56 git -C noset-both rev-parse --verify top-bases/t/branch >/dev/null &&
57 git -C noset-both rev-parse --verify {top-bases}/t/branch >/dev/null
60 test_expect_success 'hard-coded refs bases' '
61 test "$(tg -C refs --top-bases)" = "refs/top-bases" &&
62 test "$(tg -C noset-mt -c topgit.top-bases=refs --top-bases)" = "refs/top-bases" &&
63 test "$(tg -C noset-mt -c topgit.top-bases=heads -c topgit.top-bases=refs --top-bases)" = "refs/top-bases"
66 test_expect_success 'hard-coded heads bases' '
67 test "$(tg -C heads --top-bases)" = "refs/heads/{top-bases}" &&
68 test "$(tg -C noset-mt -c topgit.top-bases=heads --top-bases)" = "refs/heads/{top-bases}" &&
69 test "$(tg -C noset-mt -c topgit.top-bases=refs -c topgit.top-bases=heads --top-bases)" = "refs/heads/{top-bases}"
72 test_expect_success 'both is confusing and override' '
73 test_must_fail tg -C noset-both --top-bases >/dev/null 2>&1 &&
74 test "$(tg -C noset-both -c topgit.top-bases=refs --top-bases)" = "refs/top-bases" &&
75 test "$(tg -C noset-both -c topgit.top-bases=heads --top-bases)" = "refs/heads/{top-bases}"
78 test_expect_success 'auto detect refs and override' '
79 test "$(tg -C noset-refs --top-bases)" = "refs/top-bases" &&
80 test "$(tg -C noset-refs -c topgit.top-bases=heads --top-bases)" = "refs/heads/{top-bases}"
83 test_expect_success 'auto detect heads and override' '
84 test "$(tg -C noset-heads --top-bases)" = "refs/heads/{top-bases}" &&
85 test "$(tg -C noset-heads -c topgit.top-bases=refs --top-bases)" = "refs/top-bases"
88 test_expect_success 'default is refs until 0.20.0' '
89 test "$(tg -C noset-mt --top-bases)" = "refs/top-bases"
92 sane_unset tg_test_bases
94 test_expect_success '--top-bases -r fails with no remote' '
95 test_must_fail tg -C noset-mt --top-bases -r &&
96 test_must_fail tg -C noset-refs --top-bases -r &&
97 test_must_fail tg -C noset-heads --top-bases -r &&
98 test_must_fail tg -C noset-both --top-bases -r
101 test_expect_success '--top-bases -r succeeds with no remote refs' '
102 tg -C noset-mt --top-bases -r origin &&
103 result="$(tg -C noset-refs --top-bases -r origin)" &&
104 test z"$result" = z"refs/remotes/origin/top-bases" &&
105 result="$(tg -C noset-heads --top-bases -r origin)" &&
106 test z"$result" = z"refs/remotes/origin/{top-bases}"
109 test_expect_success '--top-bases -r fails with schizo local bases' '
110 test_must_fail tg -C noset-both --top-bases -r origin
113 test_expect_success 'setup remote branches' '
114 tg_test_bases=refs &&
115 tg_test_create_branch -C noset-mt rmtrefs:brefs :: &&
116 tg_test_create_branch -C noset-mt rmtboth:brefs :: &&
117 tg_test_create_branch -C noset-refs rmtrefs:brefs :: &&
118 tg_test_create_branch -C noset-refs rmtboth:brefs :: &&
119 tg_test_create_branch -C noset-heads rmtrefs:brefs :: &&
120 tg_test_create_branch -C noset-heads rmtboth:brefs :: &&
121 tg_test_create_branch -C noset-both rmtrefs:brefs :: &&
122 tg_test_create_branch -C noset-both rmtboth:brefs :: &&
123 tg_test_bases=heads &&
124 tg_test_create_branch -C noset-mt rmtheads:bheads :: &&
125 tg_test_create_branch -C noset-mt rmtboth:bheads :: &&
126 tg_test_create_branch -C noset-refs rmtheads:bheads :: &&
127 tg_test_create_branch -C noset-refs rmtboth:bheads :: &&
128 tg_test_create_branch -C noset-heads rmtheads:bheads :: &&
129 tg_test_create_branch -C noset-heads rmtboth:bheads :: &&
130 tg_test_create_branch -C noset-both rmtheads:bheads :: &&
131 tg_test_create_branch -C noset-both rmtboth:bheads :: &&
132 unset tg_test_bases
135 test_expect_success '--top-bases -r fails with schizo local bases' '
136 test_must_fail tg -C noset-both --top-bases -r origin
139 test_expect_success '--top-bases -r fails with schizo remote bases' '
140 test_must_fail tg -C noset-mt --top-bases -r rmtboth
143 test_expect_success '--top-bases -r favors local bases location' '
144 result="$(tg -C noset-refs -r rmtrefs --top-bases -r)" &&
145 test z"$result" = z"refs/remotes/rmtrefs/top-bases" &&
146 result="$(tg -C noset-refs -c topgit.remote=rmtheads --top-bases -r)" &&
147 test z"$result" = z"refs/remotes/rmtheads/top-bases" &&
148 result="$(tg -C noset-heads -c topgit.remote=rmtrefs --top-bases -r)" &&
149 test z"$result" = z"refs/remotes/rmtrefs/{top-bases}" &&
150 result="$(tg -C noset-heads -r rmtheads --top-bases -r)" &&
151 test z"$result" = z"refs/remotes/rmtheads/{top-bases}"
154 test_expect_success '--top-bases -r autodetects remote bases location' '
155 result="$(tg -C noset-mt --top-bases -r rmtrefs)" &&
156 test z"$result" = z"refs/remotes/rmtrefs/top-bases" &&
157 result="$(tg -C noset-mt --top-bases -r rmtheads)" &&
158 test z"$result" = z"refs/remotes/rmtheads/{top-bases}"
161 test_expect_success '--top-bases -r topgit.top-bases override trumps all' '
162 for repo in noset-mt noset-refs noset-heads noset-both; do
163 for rmt in rmtrefs rmtheads rmtboth; do
164 result="$(tg -c topgit.top-bases=refs -C "$repo" --top-bases -r "$rmt")" &&
165 test z"$result" = z"refs/remotes/$rmt/top-bases" &&
166 result="$(tg -c topgit.top-bases=heads -C "$repo" --top-bases -r "$rmt")" &&
167 test z"$result" = z"refs/remotes/$rmt/{top-bases}" || return
168 done
169 done
172 test_done