@matheusbsbs / matheus-bagliano / commits / 30c5cd3124
Fork 0

Add a test for git-commit being confused by relative GIT_DIR

Signed-off-by: David Kastrup <dak@gnu.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Kastrup committed Aug 13, 2007 at 07:38 UTC 30c5cd312472574f6a8d8c82ba7c4af76d43ff7c
1 file changed +55
t/t2050-git-dir-relative.sh new
+55
@@ -0,0 +1,55 @@
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 &&
29 +git-add top
30 +git-commit -m initial &&
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