git-cherry-pick.txt: clarify the use of revision range notation
[git/mingw.git] / t / t3905-stash-include-untracked.sh
blobef44fb22601b03be78d8d5f5eaa858ca240ec4da
1 #!/bin/sh
3 # Copyright (c) 2011 David Caldwell
6 test_description='Test git stash --include-untracked'
8 . ./test-lib.sh
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 &&
20 mkdir untracked &&
21 echo untracked >untracked/untracked &&
22 git stash --include-untracked &&
23 git diff-files --quiet &&
24 git diff-index --cached --quiet HEAD
27 cat > expect <<EOF
28 ?? actual
29 ?? expect
30 EOF
32 test_expect_success 'stash save --include-untracked cleaned the untracked files' '
33 git status --porcelain >actual &&
34 test_cmp expect actual
37 cat > expect.diff <<EOF
38 diff --git a/file2 b/file2
39 new file mode 100644
40 index 0000000..d00491f
41 --- /dev/null
42 +++ b/file2
43 @@ -0,0 +1 @@
45 diff --git a/untracked/untracked b/untracked/untracked
46 new file mode 100644
47 index 0000000..5a72eb2
48 --- /dev/null
49 +++ b/untracked/untracked
50 @@ -0,0 +1 @@
51 +untracked
52 EOF
53 cat > expect.lstree <<EOF
54 file2
55 untracked
56 EOF
58 test_expect_success 'stash save --include-untracked stashed the untracked files' '
59 test "!" -f file2 &&
60 test ! -e untracked &&
61 git diff HEAD stash^3 -- file2 untracked >actual &&
62 test_cmp expect.diff actual &&
63 git ls-tree --name-only stash^3: >actual &&
64 test_cmp expect.lstree actual
66 test_expect_success 'stash save --patch --include-untracked fails' '
67 test_must_fail git stash --patch --include-untracked
70 test_expect_success 'stash save --patch --all fails' '
71 test_must_fail git stash --patch --all
74 git clean --force --quiet
76 cat > expect <<EOF
77 M file
78 ?? actual
79 ?? expect
80 ?? file2
81 ?? untracked/
82 EOF
84 test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
85 git stash pop &&
86 git status --porcelain >actual &&
87 test_cmp expect actual &&
88 test "1" = "`cat file2`" &&
89 test untracked = "`cat untracked/untracked`"
92 git clean --force --quiet -d
94 test_expect_success 'stash save -u dirty index' '
95 echo 4 > file3 &&
96 git add file3 &&
97 test_tick &&
98 git stash -u
101 cat > expect <<EOF
102 diff --git a/file3 b/file3
103 new file mode 100644
104 index 0000000..b8626c4
105 --- /dev/null
106 +++ b/file3
107 @@ -0,0 +1 @@
111 test_expect_success 'stash save --include-untracked dirty index got stashed' '
112 git stash pop --index &&
113 git diff --cached >actual &&
114 test_cmp expect actual
117 git reset > /dev/null
119 test_expect_success 'stash save --include-untracked -q is quiet' '
120 echo 1 > file5 &&
121 git stash save --include-untracked --quiet > output.out 2>&1 &&
122 test ! -s output.out
125 test_expect_success 'stash save --include-untracked removed files' '
126 rm -f file &&
127 git stash save --include-untracked &&
128 echo 1 > expect &&
129 test_cmp file expect
132 rm -f expect
134 test_expect_success 'stash save --include-untracked removed files got stashed' '
135 git stash pop &&
136 test ! -f file
139 cat > .gitignore <<EOF
140 .gitignore
141 ignored
142 ignored.d/
145 test_expect_success 'stash save --include-untracked respects .gitignore' '
146 echo ignored > ignored &&
147 mkdir ignored.d &&
148 echo ignored >ignored.d/untracked &&
149 git stash -u &&
150 test -s ignored &&
151 test -s ignored.d/untracked &&
152 test -s .gitignore
155 test_expect_success 'stash save -u can stash with only untracked files different' '
156 echo 4 > file4 &&
157 git stash -u &&
158 test "!" -f file4
161 test_expect_success 'stash save --all does not respect .gitignore' '
162 git stash -a &&
163 test "!" -f ignored &&
164 test "!" -e ignored.d &&
165 test "!" -f .gitignore
168 test_expect_success 'stash save --all is stash poppable' '
169 git stash pop &&
170 test -s ignored &&
171 test -s ignored.d/untracked &&
172 test -s .gitignore
175 test_done