t1060: test mergesetup configuration and broken --git-common-dir
[topgit/pro.git] / t / t1060-tg-mergesetup.sh
blob3f7f469e58835f497ceeecf968798aa784bc7481
1 #!/bin/sh
3 test_description='test tg merge setup behavior
5 All non-read-only tg commands set up the merge configuration as well
6 as the pre-commit hook and repository attributes. This is called
7 the "mergesetup".
9 Make sure it works properly in a top-level as well as subdirectory.
10 It probably should not work in a bare repo but it does so test that too.
12 The Git 2.5+ worktree stuff also throughs a wrench into things.
15 TEST_NO_CREATE_REPO=1
17 . ./test-lib.sh
19 if vcmp "$git_version" '>=' "2.5"; then
20 test_set_prereq GIT_2_5
23 if vcmp "$git_version" '>=' "2.9"; then
24 test_set_prereq GIT_2_9
27 test_plan 10
29 test_expect_success 'test setup' '
30 git init --bare --quiet --template="$EMPTY_DIRECTORY" bare.git &&
31 test_create_repo r1 &&
32 test_create_repo r2 &&
33 mkdir r2/subdir &&
34 test_create_repo r3 &&
35 (cd r3 && test_commit initial) &&
36 test_create_repo r4 &&
37 mkdir r4/subdir &&
38 (cd r4 && test_commit initial)
41 test_expect_success GIT_2_5 'test setup worktrees' '
42 git -C r3 worktree add "$PWD/w3" >/dev/null 2>&1 &&
43 git -C r4 worktree add "$PWD/w4" >/dev/null 2>&1 &&
44 mkdir w4/subdir
47 test_expect_success GIT_2_9 'test setup hookspath' '
48 test_create_repo hooksrepo &&
49 mkdir hookspath &&
50 git -C hooksrepo config core.hooksPath "$PWD/hookspath"
53 test_expect_failure GIT_2_5 'rev-parse --git-common-dir is broken!' '
54 gcd="$(cd r2/subdir && git rev-parse --git-common-dir)" &&
55 test -n "$gcd" &&
56 test -d "$gcd" &&
57 test "$(cd "$gcd" && pwd -P)" = "$(cd r2/.git && pwd -P)"
60 mergesetup_is_ok() {
61 test -n "$(git -C "$1" config --get merge.ours.name)" &&
62 test -n "$(git -C "$1" config --get merge.ours.driver)" &&
63 test -s "$1/info/attributes" &&
64 test -s "${2:-$1/hooks}/pre-commit" &&
65 test -f "${2:-$1/hooks}/pre-commit" &&
66 test -x "${2:-$1/hooks}/pre-commit" &&
67 grep -q .topmsg "$1/info/attributes" &&
68 grep -q .topdeps "$1/info/attributes" &&
69 grep -q -- --hooks-path "${2:-$1/hooks}/pre-commit"
72 do_mergesetup() {
73 test_might_fail tg -C "$1" update no-such-branch-name >/dev/null 2>&1
76 test_expect_success 'mergesetup bare' '
77 test_must_fail mergesetup_is_ok bare.git &&
78 do_mergesetup bare.git &&
79 mergesetup_is_ok bare.git
82 test_expect_success 'mergesetup normal top level' '
83 test_must_fail mergesetup_is_ok r1/.git &&
84 do_mergesetup r1 &&
85 mergesetup_is_ok r1/.git
88 test_expect_success 'mergesetup normal subdir' '
89 test_must_fail mergesetup_is_ok r2/.git &&
90 do_mergesetup r2/subdir &&
91 mergesetup_is_ok r2/.git
94 test_expect_success GIT_2_5 'mergesetup worktree top level' '
95 test_must_fail mergesetup_is_ok r3/.git &&
96 do_mergesetup w3 &&
97 mergesetup_is_ok r3/.git
100 test_expect_success GIT_2_5 'mergesetup worktree subdir' '
101 test_must_fail mergesetup_is_ok r4/.git &&
102 do_mergesetup w4/subdir &&
103 mergesetup_is_ok r4/.git
106 test_expect_success GIT_2_9 'mergesetup hookspath' '
107 test_must_fail mergesetup_is_ok hooksrepo/.git hookspath &&
108 do_mergesetup hooksrepo &&
109 mergesetup_is_ok hooksrepo/.git hookspath
112 test_done