t: remove "tg-" from test file names
[topgit/pro.git] / t / t1040-remote-options.sh
blob50faa7a603681b9074a3eb5fe7d76aaf9def6c59
1 #!/bin/sh
3 test_description='tg -r and -u do the right thing
5 These are a bit tricky to test, but the `tg info` command will show a
6 "Remote Mate:" line if a matching remote is present so we check for that.
8 We do also check use of topgit.remote directly here as well and whether
9 it is set properly by `tg remote`.
12 TEST_NO_CREATE_REPO=1
14 . ./test-lib.sh
16 GIT_CEILING_DIRECTORIES="$PWD" && export GIT_CEILING_DIRECTORIES
18 test_plan 8
20 test_expect_success 'test setup' '
21 test_create_repo mt-remote &&
22 test_create_repo remote &&
23 test_create_repo noremote &&
24 (cd remote && test_commit initial && >.topmsg && >.topdeps && git add -A && test_commit second) &&
25 (cd noremote && test_commit initial && >.topmsg && >.topdeps && git add -A && test_commit second) &&
26 git -C remote update-ref refs/heads/t/branch master &&
27 git -C remote update-ref refs/heads/{top-bases}/t/branch initial &&
28 git -C remote update-ref refs/remotes/origin/t/branch master &&
29 git -C remote update-ref refs/remotes/origin/{top-bases}/t/branch initial &&
30 git -C noremote update-ref refs/heads/t/branch master &&
31 git -C noremote update-ref refs/heads/{top-bases}/t/branch initial &&
32 git -C remote rev-parse --verify t/branch >/dev/null &&
33 git -C remote rev-parse --verify {top-bases}/t/branch >/dev/null &&
34 git -C remote rev-parse --verify remotes/origin/t/branch >/dev/null &&
35 git -C remote rev-parse --verify remotes/origin/{top-bases}/t/branch >/dev/null &&
36 git -C noremote rev-parse --verify t/branch >/dev/null &&
37 git -C noremote rev-parse --verify {top-bases}/t/branch >/dev/null &&
38 git -C mt-remote config remote.upstream.url . &&
39 git -C mt-remote config remote.downstream.url . &&
40 test "$(cd mt-remote && git config remote.upstream.url)" = "." &&
41 test "$(cd mt-remote && git config remote.downstream.url)" = "."
44 # remote_info <dir> [<options>]
45 remote_info() {
46 ri="$(tg -C "$@" info t/branch | grep "^Remote Mate:")" || :
47 ri="${ri#Remote Mate: }"
48 ri="${ri%/t/branch}"
49 [ -z "$ri" ] || echo "$ri"
52 test_expect_success 'no remote if no remotes' '
53 test "$(remote_info noremote)" = "" &&
54 test "$(remote_info noremote -r origin)" = "" &&
55 test "$(remote_info noremote -r nosuch)" = "" &&
56 test "$(remote_info noremote -c topgit.remote=origin)" = "" &&
57 test "$(remote_info noremote -c topgit.remote=nosuch)" = ""
60 test_expect_success 'no remote without topgit.remote' '
61 test "$(remote_info remote)" = "" &&
62 test "$(remote_info remote -r origin -u)" = "" &&
63 test "$(remote_info remote -u -c topgit.remote=origin)" = ""
66 test_expect_success 'remote mate with topgit.remote' '
67 test "$(remote_info remote -r bad -r origin)" = "origin" &&
68 test "$(remote_info remote -c topgit.remote=nosuch -c topgit.remote=origin)" = "origin" &&
69 test "$(remote_info remote -r origin -c topgit.remote=nosuch -c topgit.remote=other)" = "origin"
72 test_expect_success 'using -u overrides configed topgit.remote' '
73 git -C remote config topgit.remote origin &&
74 test "$(cd remote && git config topgit.remote)" = "origin" &&
75 test "$(remote_info remote)" = "origin" &&
76 test "$(remote_info remote -u)" = ""
79 test_expect_success 'tg remote non-populating does not set topgit.remote' '
80 tg -C mt-remote remote upstream &&
81 test "$(git -C mt-remote config --get topgit.remote)" = "" &&
82 tg -C mt-remote remote downstream &&
83 test "$(git -C mt-remote config --get topgit.remote)" = ""
86 test_expect_success 'tg remote --populate sets and changes topgit.remote' '
87 tg -C mt-remote remote --populate upstream &&
88 test "$(git -C mt-remote config --get topgit.remote)" = "upstream" &&
89 tg -C mt-remote remote --populate downstream &&
90 test "$(git -C mt-remote config --get topgit.remote)" = "downstream"
93 test_expect_success 'tg remote --populate with bad remote leaves topgit.remote unchanged' '
94 test_must_fail tg -C mt-remote remote --populate nosuch >/dev/null 2>&1 &&
95 test "$(git -C mt-remote config --get topgit.remote)" = "downstream"
98 test_done