David Kastrup | 30c5cd3 | 2007-08-13 07:38:11 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='check problems with relative GIT_DIR |
| 4 | |
| 5 | This test creates a working tree state with a file and subdir: |
| 6 | |
| 7 | top (committed several times) |
| 8 | subdir (a subdirectory) |
| 9 | |
| 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.' |
| 14 | |
| 15 | . ./test-lib.sh |
| 16 | |
| 17 | COMMIT_FILE="$(pwd)/output" |
| 18 | export COMMIT_FILE |
| 19 | |
| 20 | test_expect_success 'Setting up post-commit hook' ' |
| 21 | mkdir -p .git/hooks && |
| 22 | echo >.git/hooks/post-commit "#!/bin/sh |
| 23 | touch \"\${COMMIT_FILE}\" |
| 24 | echo Post commit hook was called." && |
| 25 | chmod +x .git/hooks/post-commit' |
| 26 | |
| 27 | test_expect_success 'post-commit hook used ordinarily' ' |
| 28 | echo initial >top && |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 29 | git add top |
| 30 | git commit -m initial && |
David Kastrup | 30c5cd3 | 2007-08-13 07:38:11 +0200 | [diff] [blame] | 31 | test -r "${COMMIT_FILE}" |
| 32 | ' |
| 33 | |
| 34 | rm -rf "${COMMIT_FILE}" |
| 35 | mkdir subdir |
| 36 | mv .git subdir |
| 37 | |
| 38 | test_expect_success 'post-commit-hook created and used from top dir' ' |
| 39 | echo changed >top && |
| 40 | git --git-dir subdir/.git add top && |
| 41 | git --git-dir subdir/.git commit -m topcommit && |
| 42 | test -r "${COMMIT_FILE}" |
| 43 | ' |
| 44 | |
| 45 | rm -rf "${COMMIT_FILE}" |
| 46 | |
| 47 | test_expect_success 'post-commit-hook from sub dir' ' |
| 48 | echo changed again >top |
| 49 | cd subdir && |
| 50 | git --git-dir .git --work-tree .. add ../top && |
| 51 | git --git-dir .git --work-tree .. commit -m subcommit && |
| 52 | test -r "${COMMIT_FILE}" |
| 53 | ' |
| 54 | |
| 55 | test_done |