| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='setup: validation of .git file/directory types |
| 4 | |
| 5 | Verify that setup_git_directory() correctly handles: |
| 6 | 1. Valid .git directories (including symlinks to them). |
| 7 | 2. Invalid .git files (FIFOs, sockets) by erroring out. |
| 8 | 3. Invalid .git files (garbage) by erroring out. |
| 9 | ' |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | |
| 13 | test_expect_success 'setup: create parent git repository' ' |
| 14 | git init parent && |
| 15 | test_commit -C parent "root-commit" |
| 16 | ' |
| 17 | |
| 18 | test_expect_success SYMLINKS 'setup: .git as a symlink to a directory is valid' ' |
| 19 | test_when_finished "rm -rf parent/link-to-dir" && |
| 20 | mkdir -p parent/link-to-dir && |
| 21 | ( |
| 22 | cd parent/link-to-dir && |
| 23 | git init real-repo && |
| 24 | ln -s real-repo/.git .git && |
| 25 | git rev-parse --git-dir >actual && |
| 26 | echo .git >expect && |
| 27 | test_cmp expect actual |
| 28 | ) |
| 29 | ' |
| 30 | |
| 31 | test_expect_success PIPE 'setup: .git as a FIFO (named pipe) is rejected' ' |
| 32 | test_when_finished "rm -rf parent/fifo-trap" && |
| 33 | mkdir -p parent/fifo-trap && |
| 34 | ( |
| 35 | cd parent/fifo-trap && |
| 36 | mkfifo .git && |
| 37 | test_must_fail git rev-parse --git-dir 2>stderr && |
| 38 | test_grep "not a regular file" stderr |
| 39 | ) |
| 40 | ' |
| 41 | |
| 42 | test_expect_success SYMLINKS,PIPE 'setup: .git as a symlink to a FIFO is rejected' ' |
| 43 | test_when_finished "rm -rf parent/symlink-fifo-trap" && |
| 44 | mkdir -p parent/symlink-fifo-trap && |
| 45 | ( |
| 46 | cd parent/symlink-fifo-trap && |
| 47 | mkfifo target-fifo && |
| 48 | ln -s target-fifo .git && |
| 49 | test_must_fail git rev-parse --git-dir 2>stderr && |
| 50 | test_grep "not a regular file" stderr |
| 51 | ) |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'setup: .git with garbage content is rejected' ' |
| 55 | test_when_finished "rm -rf parent/garbage-trap" && |
| 56 | mkdir -p parent/garbage-trap && |
| 57 | ( |
| 58 | cd parent/garbage-trap && |
| 59 | echo "garbage" >.git && |
| 60 | test_must_fail git rev-parse --git-dir 2>stderr && |
| 61 | test_grep "invalid gitfile format" stderr |
| 62 | ) |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'setup: .git as an empty directory is ignored' ' |
| 66 | test_when_finished "rm -rf parent/empty-dir" && |
| 67 | mkdir -p parent/empty-dir && |
| 68 | ( |
| 69 | cd parent/empty-dir && |
| 70 | git rev-parse --git-dir >expect && |
| 71 | mkdir .git && |
| 72 | git rev-parse --git-dir >actual && |
| 73 | test_cmp expect actual |
| 74 | ) |
| 75 | ' |
| 76 | |
| 77 | test_done |