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