]>
Commit | Line | Data |
---|---|---|
78751302 DC |
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 && | |
7474b8b4 BC |
20 | mkdir untracked && |
21 | echo untracked >untracked/untracked && | |
78751302 DC |
22 | git stash --include-untracked && |
23 | git diff-files --quiet && | |
24 | git diff-index --cached --quiet HEAD | |
25 | ' | |
26 | ||
27 | cat > expect <<EOF | |
4fd73124 | 28 | ?? actual |
78751302 | 29 | ?? expect |
78751302 DC |
30 | EOF |
31 | ||
32 | test_expect_success 'stash save --include-untracked cleaned the untracked files' ' | |
c995ef49 | 33 | git status --porcelain >actual && |
4fd73124 | 34 | test_cmp expect actual |
78751302 DC |
35 | ' |
36 | ||
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 @@ | |
44 | +1 | |
7474b8b4 BC |
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 | |
78751302 DC |
52 | EOF |
53 | cat > expect.lstree <<EOF | |
54 | file2 | |
7474b8b4 | 55 | untracked |
78751302 DC |
56 | EOF |
57 | ||
58 | test_expect_success 'stash save --include-untracked stashed the untracked files' ' | |
59 | test "!" -f file2 && | |
7474b8b4 BC |
60 | test ! -e untracked && |
61 | git diff HEAD stash^3 -- file2 untracked >actual && | |
4fd73124 BC |
62 | test_cmp expect.diff actual && |
63 | git ls-tree --name-only stash^3: >actual && | |
64 | test_cmp expect.lstree actual | |
78751302 DC |
65 | ' |
66 | test_expect_success 'stash save --patch --include-untracked fails' ' | |
67 | test_must_fail git stash --patch --include-untracked | |
68 | ' | |
69 | ||
70 | test_expect_success 'stash save --patch --all fails' ' | |
71 | test_must_fail git stash --patch --all | |
72 | ' | |
73 | ||
74 | git clean --force --quiet | |
75 | ||
76 | cat > expect <<EOF | |
77 | M file | |
4fd73124 | 78 | ?? actual |
78751302 DC |
79 | ?? expect |
80 | ?? file2 | |
7474b8b4 | 81 | ?? untracked/ |
78751302 DC |
82 | EOF |
83 | ||
84 | test_expect_success 'stash pop after save --include-untracked leaves files untracked again' ' | |
85 | git stash pop && | |
c995ef49 | 86 | git status --porcelain >actual && |
7474b8b4 BC |
87 | test_cmp expect actual && |
88 | test "1" = "`cat file2`" && | |
89 | test untracked = "`cat untracked/untracked`" | |
78751302 DC |
90 | ' |
91 | ||
7474b8b4 | 92 | git clean --force --quiet -d |
78751302 DC |
93 | |
94 | test_expect_success 'stash save -u dirty index' ' | |
95 | echo 4 > file3 && | |
96 | git add file3 && | |
97 | test_tick && | |
98 | git stash -u | |
99 | ' | |
100 | ||
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 @@ | |
108 | +4 | |
109 | EOF | |
110 | ||
111 | test_expect_success 'stash save --include-untracked dirty index got stashed' ' | |
112 | git stash pop --index && | |
4fd73124 BC |
113 | git diff --cached >actual && |
114 | test_cmp expect actual | |
78751302 DC |
115 | ' |
116 | ||
117 | git reset > /dev/null | |
118 | ||
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 | |
123 | ' | |
124 | ||
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 | |
130 | ' | |
131 | ||
132 | rm -f expect | |
133 | ||
134 | test_expect_success 'stash save --include-untracked removed files got stashed' ' | |
135 | git stash pop && | |
136 | test ! -f file | |
137 | ' | |
138 | ||
139 | cat > .gitignore <<EOF | |
140 | .gitignore | |
141 | ignored | |
7474b8b4 | 142 | ignored.d/ |
78751302 DC |
143 | EOF |
144 | ||
145 | test_expect_success 'stash save --include-untracked respects .gitignore' ' | |
146 | echo ignored > ignored && | |
7474b8b4 BC |
147 | mkdir ignored.d && |
148 | echo ignored >ignored.d/untracked && | |
78751302 DC |
149 | git stash -u && |
150 | test -s ignored && | |
7474b8b4 | 151 | test -s ignored.d/untracked && |
78751302 DC |
152 | test -s .gitignore |
153 | ' | |
154 | ||
155 | test_expect_success 'stash save -u can stash with only untracked files different' ' | |
156 | echo 4 > file4 && | |
c995ef49 | 157 | git stash -u && |
78751302 DC |
158 | test "!" -f file4 |
159 | ' | |
160 | ||
161 | test_expect_success 'stash save --all does not respect .gitignore' ' | |
162 | git stash -a && | |
163 | test "!" -f ignored && | |
7474b8b4 | 164 | test "!" -e ignored.d && |
78751302 DC |
165 | test "!" -f .gitignore |
166 | ' | |
167 | ||
168 | test_expect_success 'stash save --all is stash poppable' ' | |
169 | git stash pop && | |
170 | test -s ignored && | |
7474b8b4 | 171 | test -s ignored.d/untracked && |
78751302 DC |
172 | test -s .gitignore |
173 | ' | |
174 | ||
175 | test_done |