Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 6 | test_description='git ls-files --others --exclude |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 7 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 8 | This test runs git ls-files --others and tests --exclude patterns. |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 9 | ' |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | |
| 13 | rm -fr one three |
| 14 | for dir in . one one/two three |
| 15 | do |
| 16 | mkdir -p $dir && |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 17 | for i in 1 2 3 4 5 6 7 8 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 18 | do |
| 19 | >$dir/a.$i |
| 20 | done |
| 21 | done |
| 22 | |
| 23 | cat >expect <<EOF |
| 24 | a.2 |
| 25 | a.4 |
| 26 | a.5 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 27 | a.8 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 28 | one/a.3 |
| 29 | one/a.4 |
| 30 | one/a.5 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 31 | one/a.7 |
| 32 | one/two/a.2 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 33 | one/two/a.3 |
| 34 | one/two/a.5 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 35 | one/two/a.7 |
| 36 | one/two/a.8 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 37 | three/a.2 |
| 38 | three/a.3 |
| 39 | three/a.4 |
| 40 | three/a.5 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 41 | three/a.8 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 42 | EOF |
| 43 | |
| 44 | echo '.gitignore |
| 45 | output |
| 46 | expect |
| 47 | .gitignore |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 48 | *.7 |
| 49 | !*.8' >.git/ignore |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 50 | |
| 51 | echo '*.1 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 52 | /*.3 |
| 53 | !*.6' >.gitignore |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 54 | echo '*.2 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 55 | two/*.4 |
| 56 | !*.7 |
| 57 | *.8' >one/.gitignore |
| 58 | echo '!*.2 |
| 59 | !*.8' >one/two/.gitignore |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 60 | |
| 61 | test_expect_success \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 62 | 'git ls-files --others with various exclude options.' \ |
| 63 | 'git ls-files --others \ |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 64 | --exclude=\*.6 \ |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 65 | --exclude-per-directory=.gitignore \ |
| 66 | --exclude-from=.git/ignore \ |
| 67 | >output && |
Johannes Schindelin | 5bd7450 | 2007-02-25 23:36:53 +0100 | [diff] [blame] | 68 | git diff expect output' |
Pavel Roskin | da7bc9b | 2005-08-10 22:15:02 -0400 | [diff] [blame] | 69 | |
Alex Riesen | d317e43 | 2005-11-02 14:05:45 +0100 | [diff] [blame] | 70 | # Test \r\n (MSDOS-like systems) |
Alex Riesen | 0dbc4e8 | 2006-02-12 19:05:34 +0100 | [diff] [blame] | 71 | printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore |
Alex Riesen | d317e43 | 2005-11-02 14:05:45 +0100 | [diff] [blame] | 72 | |
| 73 | test_expect_success \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 74 | 'git ls-files --others with \r\n line endings.' \ |
| 75 | 'git ls-files --others \ |
Alex Riesen | d317e43 | 2005-11-02 14:05:45 +0100 | [diff] [blame] | 76 | --exclude=\*.6 \ |
| 77 | --exclude-per-directory=.gitignore \ |
| 78 | --exclude-from=.git/ignore \ |
| 79 | >output && |
Johannes Schindelin | 5bd7450 | 2007-02-25 23:36:53 +0100 | [diff] [blame] | 80 | git diff expect output' |
Alex Riesen | d317e43 | 2005-11-02 14:05:45 +0100 | [diff] [blame] | 81 | |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 82 | cat > excludes-file << EOF |
| 83 | *.[1-8] |
| 84 | e* |
| 85 | EOF |
| 86 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 87 | git config core.excludesFile excludes-file |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 88 | |
Johannes Schindelin | 637efc3 | 2007-11-15 06:27:57 +0000 | [diff] [blame] | 89 | git status | grep "^# " > output |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 90 | |
| 91 | cat > expect << EOF |
| 92 | # .gitignore |
| 93 | # a.6 |
| 94 | # one/ |
| 95 | # output |
| 96 | # three/ |
| 97 | EOF |
| 98 | |
| 99 | test_expect_success 'git-status honours core.excludesfile' \ |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 100 | 'test_cmp expect output' |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 101 | |
Junio C Hamano | d6b8fc3 | 2008-01-31 01:17:48 -0800 | [diff] [blame] | 102 | test_expect_success 'trailing slash in exclude allows directory match(1)' ' |
| 103 | |
| 104 | git ls-files --others --exclude=one/ >output && |
| 105 | if grep "^one/" output |
| 106 | then |
| 107 | echo Ooops |
| 108 | false |
| 109 | else |
| 110 | : happy |
| 111 | fi |
| 112 | |
| 113 | ' |
| 114 | |
| 115 | test_expect_success 'trailing slash in exclude allows directory match (2)' ' |
| 116 | |
| 117 | git ls-files --others --exclude=one/two/ >output && |
| 118 | if grep "^one/two/" output |
| 119 | then |
| 120 | echo Ooops |
| 121 | false |
| 122 | else |
| 123 | : happy |
| 124 | fi |
| 125 | |
| 126 | ' |
| 127 | |
| 128 | test_expect_success 'trailing slash in exclude forces directory match (1)' ' |
| 129 | |
| 130 | >two |
| 131 | git ls-files --others --exclude=two/ >output && |
| 132 | grep "^two" output |
| 133 | |
| 134 | ' |
| 135 | |
| 136 | test_expect_success 'trailing slash in exclude forces directory match (2)' ' |
| 137 | |
| 138 | git ls-files --others --exclude=one/a.1/ >output && |
| 139 | grep "^one/a.1" output |
| 140 | |
| 141 | ' |
| 142 | |
Pavel Roskin | da7bc9b | 2005-08-10 22:15:02 -0400 | [diff] [blame] | 143 | test_done |