Merge branch 'ds/add-rm-with-sparse-index'
[git/debian.git] / t / t2050-git-dir-relative.sh
blob1f193cde965303a8f2362e824e0a86e99f746548
1 #!/bin/sh
3 test_description='check problems with relative GIT_DIR
5 This test creates a working tree state with a file and subdir:
7 top (committed several times)
8 subdir (a subdirectory)
10 It creates a commit-hook and tests it, then moves .git
11 into the subdir while keeping the worktree location,
12 and tries commits from the top and the subdir, checking
13 that the commit-hook still gets called.'
15 TEST_PASSES_SANITIZE_LEAK=true
16 . ./test-lib.sh
18 COMMIT_FILE="$(pwd)/output"
19 export COMMIT_FILE
21 test_expect_success 'Setting up post-commit hook' '
22 mkdir -p .git/hooks &&
23 echo >.git/hooks/post-commit "#!/bin/sh
24 touch \"\${COMMIT_FILE}\"
25 echo Post commit hook was called." &&
26 chmod +x .git/hooks/post-commit'
28 test_expect_success 'post-commit hook used ordinarily' '
29 echo initial >top &&
30 git add top &&
31 git commit -m initial &&
32 test -r "${COMMIT_FILE}"
35 rm -rf "${COMMIT_FILE}"
36 mkdir subdir
37 mv .git subdir
39 test_expect_success 'post-commit-hook created and used from top dir' '
40 echo changed >top &&
41 git --git-dir subdir/.git add top &&
42 git --git-dir subdir/.git commit -m topcommit &&
43 test -r "${COMMIT_FILE}"
46 rm -rf "${COMMIT_FILE}"
48 test_expect_success 'post-commit-hook from sub dir' '
49 echo changed again >top &&
50 cd subdir &&
51 git --git-dir .git --work-tree .. add ../top &&
52 git --git-dir .git --work-tree .. commit -m subcommit &&
53 test -r "${COMMIT_FILE}"
56 test_done