]>
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 && | |
44df2e29 | 20 | echo 1 > HEAD && |
7474b8b4 BC |
21 | mkdir untracked && |
22 | echo untracked >untracked/untracked && | |
78751302 DC |
23 | git stash --include-untracked && |
24 | git diff-files --quiet && | |
25 | git diff-index --cached --quiet HEAD | |
26 | ' | |
27 | ||
28 | cat > expect <<EOF | |
4fd73124 | 29 | ?? actual |
78751302 | 30 | ?? expect |
78751302 DC |
31 | EOF |
32 | ||
33 | test_expect_success 'stash save --include-untracked cleaned the untracked files' ' | |
c995ef49 | 34 | git status --porcelain >actual && |
4fd73124 | 35 | test_cmp expect actual |
78751302 DC |
36 | ' |
37 | ||
38 | cat > expect.diff <<EOF | |
44df2e29 JM |
39 | diff --git a/HEAD b/HEAD |
40 | new file mode 100644 | |
41 | index 0000000..d00491f | |
42 | --- /dev/null | |
43 | +++ b/HEAD | |
44 | @@ -0,0 +1 @@ | |
45 | +1 | |
78751302 DC |
46 | diff --git a/file2 b/file2 |
47 | new file mode 100644 | |
48 | index 0000000..d00491f | |
49 | --- /dev/null | |
50 | +++ b/file2 | |
51 | @@ -0,0 +1 @@ | |
52 | +1 | |
7474b8b4 BC |
53 | diff --git a/untracked/untracked b/untracked/untracked |
54 | new file mode 100644 | |
55 | index 0000000..5a72eb2 | |
56 | --- /dev/null | |
57 | +++ b/untracked/untracked | |
58 | @@ -0,0 +1 @@ | |
59 | +untracked | |
78751302 DC |
60 | EOF |
61 | cat > expect.lstree <<EOF | |
44df2e29 | 62 | HEAD |
78751302 | 63 | file2 |
7474b8b4 | 64 | untracked |
78751302 DC |
65 | EOF |
66 | ||
67 | test_expect_success 'stash save --include-untracked stashed the untracked files' ' | |
44df2e29 JM |
68 | test_path_is_missing file2 && |
69 | test_path_is_missing untracked && | |
70 | test_path_is_missing HEAD && | |
71 | git diff HEAD stash^3 -- HEAD file2 untracked >actual && | |
4fd73124 BC |
72 | test_cmp expect.diff actual && |
73 | git ls-tree --name-only stash^3: >actual && | |
74 | test_cmp expect.lstree actual | |
78751302 DC |
75 | ' |
76 | test_expect_success 'stash save --patch --include-untracked fails' ' | |
77 | test_must_fail git stash --patch --include-untracked | |
78 | ' | |
79 | ||
80 | test_expect_success 'stash save --patch --all fails' ' | |
81 | test_must_fail git stash --patch --all | |
82 | ' | |
83 | ||
84 | git clean --force --quiet | |
85 | ||
86 | cat > expect <<EOF | |
87 | M file | |
44df2e29 | 88 | ?? HEAD |
4fd73124 | 89 | ?? actual |
78751302 DC |
90 | ?? expect |
91 | ?? file2 | |
7474b8b4 | 92 | ?? untracked/ |
78751302 DC |
93 | EOF |
94 | ||
95 | test_expect_success 'stash pop after save --include-untracked leaves files untracked again' ' | |
96 | git stash pop && | |
c995ef49 | 97 | git status --porcelain >actual && |
7474b8b4 BC |
98 | test_cmp expect actual && |
99 | test "1" = "`cat file2`" && | |
100 | test untracked = "`cat untracked/untracked`" | |
78751302 DC |
101 | ' |
102 | ||
7474b8b4 | 103 | git clean --force --quiet -d |
78751302 DC |
104 | |
105 | test_expect_success 'stash save -u dirty index' ' | |
106 | echo 4 > file3 && | |
107 | git add file3 && | |
108 | test_tick && | |
109 | git stash -u | |
110 | ' | |
111 | ||
112 | cat > expect <<EOF | |
113 | diff --git a/file3 b/file3 | |
114 | new file mode 100644 | |
115 | index 0000000..b8626c4 | |
116 | --- /dev/null | |
117 | +++ b/file3 | |
118 | @@ -0,0 +1 @@ | |
119 | +4 | |
120 | EOF | |
121 | ||
122 | test_expect_success 'stash save --include-untracked dirty index got stashed' ' | |
123 | git stash pop --index && | |
4fd73124 BC |
124 | git diff --cached >actual && |
125 | test_cmp expect actual | |
78751302 DC |
126 | ' |
127 | ||
128 | git reset > /dev/null | |
129 | ||
44df2e29 | 130 | # Must direct output somewhere where it won't be considered an untracked file |
78751302 DC |
131 | test_expect_success 'stash save --include-untracked -q is quiet' ' |
132 | echo 1 > file5 && | |
44df2e29 JM |
133 | git stash save --include-untracked --quiet > .git/stash-output.out 2>&1 && |
134 | test_line_count = 0 .git/stash-output.out && | |
135 | rm -f .git/stash-output.out | |
78751302 DC |
136 | ' |
137 | ||
138 | test_expect_success 'stash save --include-untracked removed files' ' | |
139 | rm -f file && | |
140 | git stash save --include-untracked && | |
141 | echo 1 > expect && | |
142 | test_cmp file expect | |
143 | ' | |
144 | ||
145 | rm -f expect | |
146 | ||
147 | test_expect_success 'stash save --include-untracked removed files got stashed' ' | |
148 | git stash pop && | |
44df2e29 | 149 | test_path_is_missing file |
78751302 DC |
150 | ' |
151 | ||
152 | cat > .gitignore <<EOF | |
153 | .gitignore | |
154 | ignored | |
7474b8b4 | 155 | ignored.d/ |
78751302 DC |
156 | EOF |
157 | ||
158 | test_expect_success 'stash save --include-untracked respects .gitignore' ' | |
159 | echo ignored > ignored && | |
7474b8b4 BC |
160 | mkdir ignored.d && |
161 | echo ignored >ignored.d/untracked && | |
78751302 DC |
162 | git stash -u && |
163 | test -s ignored && | |
7474b8b4 | 164 | test -s ignored.d/untracked && |
78751302 DC |
165 | test -s .gitignore |
166 | ' | |
167 | ||
168 | test_expect_success 'stash save -u can stash with only untracked files different' ' | |
169 | echo 4 > file4 && | |
c995ef49 | 170 | git stash -u && |
44df2e29 | 171 | test_path_is_missing file4 |
78751302 DC |
172 | ' |
173 | ||
174 | test_expect_success 'stash save --all does not respect .gitignore' ' | |
175 | git stash -a && | |
44df2e29 JM |
176 | test_path_is_missing ignored && |
177 | test_path_is_missing ignored.d && | |
178 | test_path_is_missing .gitignore | |
78751302 DC |
179 | ' |
180 | ||
181 | test_expect_success 'stash save --all is stash poppable' ' | |
182 | git stash pop && | |
183 | test -s ignored && | |
7474b8b4 | 184 | test -s ignored.d/untracked && |
78751302 DC |
185 | test -s .gitignore |
186 | ' | |
187 | ||
188 | test_done |