David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2011 David Caldwell |
| 4 | # |
| 5 | |
| 6 | test_description='Test git stash --include-untracked' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'stash save --include-untracked some dirty working directory' ' |
| 11 | echo 1 > file && |
| 12 | git add file && |
| 13 | test_tick && |
| 14 | git commit -m initial && |
| 15 | echo 2 > file && |
| 16 | git add file && |
| 17 | echo 3 > file && |
| 18 | test_tick && |
| 19 | echo 1 > file2 && |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 20 | echo 1 > HEAD && |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 21 | mkdir untracked && |
| 22 | echo untracked >untracked/untracked && |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 23 | git stash --include-untracked && |
| 24 | git diff-files --quiet && |
| 25 | git diff-index --cached --quiet HEAD |
| 26 | ' |
| 27 | |
| 28 | cat > expect <<EOF |
Brandon Casey | 4fd7312 | 2011-08-26 19:59:24 -0500 | [diff] [blame] | 29 | ?? actual |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 30 | ?? expect |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 31 | EOF |
| 32 | |
| 33 | test_expect_success 'stash save --include-untracked cleaned the untracked files' ' |
Brandon Casey | c995ef4 | 2011-08-26 19:59:26 -0500 | [diff] [blame] | 34 | git status --porcelain >actual && |
Brandon Casey | 4fd7312 | 2011-08-26 19:59:24 -0500 | [diff] [blame] | 35 | test_cmp expect actual |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 36 | ' |
| 37 | |
brian m. carlson | f1aae03 | 2018-05-21 02:01:33 +0000 | [diff] [blame] | 38 | tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin)) |
| 39 | untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin)) |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 40 | cat > expect.diff <<EOF |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 41 | diff --git a/HEAD b/HEAD |
| 42 | new file mode 100644 |
brian m. carlson | f1aae03 | 2018-05-21 02:01:33 +0000 | [diff] [blame] | 43 | index 0000000..$tracked |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 44 | --- /dev/null |
| 45 | +++ b/HEAD |
| 46 | @@ -0,0 +1 @@ |
| 47 | +1 |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 48 | diff --git a/file2 b/file2 |
| 49 | new file mode 100644 |
brian m. carlson | f1aae03 | 2018-05-21 02:01:33 +0000 | [diff] [blame] | 50 | index 0000000..$tracked |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 51 | --- /dev/null |
| 52 | +++ b/file2 |
| 53 | @@ -0,0 +1 @@ |
| 54 | +1 |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 55 | diff --git a/untracked/untracked b/untracked/untracked |
| 56 | new file mode 100644 |
brian m. carlson | f1aae03 | 2018-05-21 02:01:33 +0000 | [diff] [blame] | 57 | index 0000000..$untracked |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 58 | --- /dev/null |
| 59 | +++ b/untracked/untracked |
| 60 | @@ -0,0 +1 @@ |
| 61 | +untracked |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 62 | EOF |
| 63 | cat > expect.lstree <<EOF |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 64 | HEAD |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 65 | file2 |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 66 | untracked |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 67 | EOF |
| 68 | |
| 69 | test_expect_success 'stash save --include-untracked stashed the untracked files' ' |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 70 | test_path_is_missing file2 && |
| 71 | test_path_is_missing untracked && |
| 72 | test_path_is_missing HEAD && |
| 73 | git diff HEAD stash^3 -- HEAD file2 untracked >actual && |
Brandon Casey | 4fd7312 | 2011-08-26 19:59:24 -0500 | [diff] [blame] | 74 | test_cmp expect.diff actual && |
| 75 | git ls-tree --name-only stash^3: >actual && |
| 76 | test_cmp expect.lstree actual |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 77 | ' |
| 78 | test_expect_success 'stash save --patch --include-untracked fails' ' |
| 79 | test_must_fail git stash --patch --include-untracked |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'stash save --patch --all fails' ' |
| 83 | test_must_fail git stash --patch --all |
| 84 | ' |
| 85 | |
| 86 | git clean --force --quiet |
| 87 | |
| 88 | cat > expect <<EOF |
| 89 | M file |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 90 | ?? HEAD |
Brandon Casey | 4fd7312 | 2011-08-26 19:59:24 -0500 | [diff] [blame] | 91 | ?? actual |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 92 | ?? expect |
| 93 | ?? file2 |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 94 | ?? untracked/ |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 95 | EOF |
| 96 | |
| 97 | test_expect_success 'stash pop after save --include-untracked leaves files untracked again' ' |
| 98 | git stash pop && |
Brandon Casey | c995ef4 | 2011-08-26 19:59:26 -0500 | [diff] [blame] | 99 | git status --porcelain >actual && |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 100 | test_cmp expect actual && |
Elia Pinto | cba1262 | 2014-04-30 09:22:54 -0700 | [diff] [blame] | 101 | test "1" = "$(cat file2)" && |
| 102 | test untracked = "$(cat untracked/untracked)" |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 103 | ' |
| 104 | |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 105 | git clean --force --quiet -d |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 106 | |
| 107 | test_expect_success 'stash save -u dirty index' ' |
| 108 | echo 4 > file3 && |
| 109 | git add file3 && |
| 110 | test_tick && |
| 111 | git stash -u |
| 112 | ' |
| 113 | |
brian m. carlson | f1aae03 | 2018-05-21 02:01:33 +0000 | [diff] [blame] | 114 | blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin)) |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 115 | cat > expect <<EOF |
| 116 | diff --git a/file3 b/file3 |
| 117 | new file mode 100644 |
brian m. carlson | f1aae03 | 2018-05-21 02:01:33 +0000 | [diff] [blame] | 118 | index 0000000..$blob |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 119 | --- /dev/null |
| 120 | +++ b/file3 |
| 121 | @@ -0,0 +1 @@ |
| 122 | +4 |
| 123 | EOF |
| 124 | |
| 125 | test_expect_success 'stash save --include-untracked dirty index got stashed' ' |
| 126 | git stash pop --index && |
Brandon Casey | 4fd7312 | 2011-08-26 19:59:24 -0500 | [diff] [blame] | 127 | git diff --cached >actual && |
| 128 | test_cmp expect actual |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 129 | ' |
| 130 | |
| 131 | git reset > /dev/null |
| 132 | |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 133 | # Must direct output somewhere where it won't be considered an untracked file |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 134 | test_expect_success 'stash save --include-untracked -q is quiet' ' |
| 135 | echo 1 > file5 && |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 136 | git stash save --include-untracked --quiet > .git/stash-output.out 2>&1 && |
| 137 | test_line_count = 0 .git/stash-output.out && |
| 138 | rm -f .git/stash-output.out |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 139 | ' |
| 140 | |
| 141 | test_expect_success 'stash save --include-untracked removed files' ' |
| 142 | rm -f file && |
| 143 | git stash save --include-untracked && |
| 144 | echo 1 > expect && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 145 | test_cmp expect file |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 146 | ' |
| 147 | |
| 148 | rm -f expect |
| 149 | |
| 150 | test_expect_success 'stash save --include-untracked removed files got stashed' ' |
| 151 | git stash pop && |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 152 | test_path_is_missing file |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 153 | ' |
| 154 | |
| 155 | cat > .gitignore <<EOF |
| 156 | .gitignore |
| 157 | ignored |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 158 | ignored.d/ |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 159 | EOF |
| 160 | |
| 161 | test_expect_success 'stash save --include-untracked respects .gitignore' ' |
| 162 | echo ignored > ignored && |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 163 | mkdir ignored.d && |
| 164 | echo ignored >ignored.d/untracked && |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 165 | git stash -u && |
| 166 | test -s ignored && |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 167 | test -s ignored.d/untracked && |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 168 | test -s .gitignore |
| 169 | ' |
| 170 | |
| 171 | test_expect_success 'stash save -u can stash with only untracked files different' ' |
| 172 | echo 4 > file4 && |
Brandon Casey | c995ef4 | 2011-08-26 19:59:26 -0500 | [diff] [blame] | 173 | git stash -u && |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 174 | test_path_is_missing file4 |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 175 | ' |
| 176 | |
| 177 | test_expect_success 'stash save --all does not respect .gitignore' ' |
| 178 | git stash -a && |
Jonathon Mah | 44df2e2 | 2011-12-30 16:14:01 -0800 | [diff] [blame] | 179 | test_path_is_missing ignored && |
| 180 | test_path_is_missing ignored.d && |
| 181 | test_path_is_missing .gitignore |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 182 | ' |
| 183 | |
| 184 | test_expect_success 'stash save --all is stash poppable' ' |
| 185 | git stash pop && |
| 186 | test -s ignored && |
Brandon Casey | 7474b8b | 2011-08-26 19:59:27 -0500 | [diff] [blame] | 187 | test -s ignored.d/untracked && |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 188 | test -s .gitignore |
| 189 | ' |
| 190 | |
Thomas Gummerer | df6bba0 | 2017-02-28 20:33:38 +0000 | [diff] [blame] | 191 | test_expect_success 'stash push --include-untracked with pathspec' ' |
| 192 | >foo && |
| 193 | >bar && |
| 194 | git stash push --include-untracked -- foo && |
| 195 | test_path_is_file bar && |
| 196 | test_path_is_missing foo && |
| 197 | git stash pop && |
| 198 | test_path_is_file bar && |
| 199 | test_path_is_file foo |
| 200 | ' |
| 201 | |
| 202 | test_expect_success 'stash push with $IFS character' ' |
| 203 | >"foo bar" && |
| 204 | >foo && |
| 205 | >bar && |
| 206 | git add foo* && |
| 207 | git stash push --include-untracked -- "foo b*" && |
| 208 | test_path_is_missing "foo bar" && |
| 209 | test_path_is_file foo && |
| 210 | test_path_is_file bar && |
| 211 | git stash pop && |
| 212 | test_path_is_file "foo bar" && |
| 213 | test_path_is_file foo && |
| 214 | test_path_is_file bar |
| 215 | ' |
| 216 | |
Nicolas Morey-Chaisemartin | bbffd87 | 2017-08-11 19:14:43 +0200 | [diff] [blame] | 217 | cat > .gitignore <<EOF |
| 218 | ignored |
| 219 | ignored.d/* |
| 220 | EOF |
| 221 | |
| 222 | test_expect_success 'stash previously ignored file' ' |
| 223 | git reset HEAD && |
| 224 | git add .gitignore && |
| 225 | git commit -m "Add .gitignore" && |
| 226 | >ignored.d/foo && |
| 227 | echo "!ignored.d/foo" >> .gitignore && |
| 228 | git stash save --include-untracked && |
| 229 | test_path_is_missing ignored.d/foo && |
| 230 | git stash pop && |
| 231 | test_path_is_file ignored.d/foo |
| 232 | ' |
| 233 | |
Thomas Gummerer | 833622a | 2018-03-19 23:21:55 +0000 | [diff] [blame] | 234 | test_expect_success 'stash -u -- <untracked> doesnt print error' ' |
| 235 | >untracked && |
| 236 | git stash push -u -- untracked 2>actual && |
| 237 | test_path_is_missing untracked && |
| 238 | test_line_count = 0 actual |
| 239 | ' |
| 240 | |
| 241 | test_expect_success 'stash -u -- <untracked> leaves rest of working tree in place' ' |
| 242 | >tracked && |
| 243 | git add tracked && |
| 244 | >untracked && |
| 245 | git stash push -u -- untracked && |
| 246 | test_path_is_missing untracked && |
| 247 | test_path_is_file tracked |
| 248 | ' |
| 249 | |
| 250 | test_expect_success 'stash -u -- <tracked> <untracked> clears changes in both' ' |
| 251 | >tracked && |
| 252 | git add tracked && |
| 253 | >untracked && |
| 254 | git stash push -u -- tracked untracked && |
| 255 | test_path_is_missing tracked && |
| 256 | test_path_is_missing untracked |
| 257 | ' |
| 258 | |
| 259 | test_expect_success 'stash --all -- <ignored> stashes ignored file' ' |
| 260 | >ignored.d/bar && |
| 261 | git stash push --all -- ignored.d/bar && |
| 262 | test_path_is_missing ignored.d/bar |
| 263 | ' |
| 264 | |
| 265 | test_expect_success 'stash --all -- <tracked> <ignored> clears changes in both' ' |
| 266 | >tracked && |
| 267 | git add tracked && |
| 268 | >ignored.d/bar && |
| 269 | git stash push --all -- tracked ignored.d/bar && |
| 270 | test_path_is_missing tracked && |
| 271 | test_path_is_missing ignored.d/bar |
| 272 | ' |
| 273 | |
| 274 | test_expect_success 'stash -u -- <ignored> leaves ignored file alone' ' |
| 275 | >ignored.d/bar && |
| 276 | git stash push -u -- ignored.d/bar && |
| 277 | test_path_is_file ignored.d/bar |
| 278 | ' |
| 279 | |
Thomas Gummerer | d319bb1 | 2018-03-19 23:21:56 +0000 | [diff] [blame] | 280 | test_expect_success 'stash -u -- <non-existant> shows no changes when there are none' ' |
| 281 | git stash push -u -- non-existant >actual && |
| 282 | echo "No local changes to save" >expect && |
| 283 | test_i18ncmp expect actual |
| 284 | ' |
| 285 | |
David Caldwell | 7875130 | 2011-06-24 17:56:06 -0700 | [diff] [blame] | 286 | test_done |