]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3905-stash-include-untracked.sh
Update draft release notes to 1.7.9
[thirdparty/git.git] / t / t3905-stash-include-untracked.sh
CommitLineData
78751302
DC
1#!/bin/sh
2#
3# Copyright (c) 2011 David Caldwell
4#
5
6test_description='Test git stash --include-untracked'
7
8. ./test-lib.sh
9
10test_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
27cat > expect <<EOF
4fd73124 28?? actual
78751302 29?? expect
78751302
DC
30EOF
31
32test_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
37cat > expect.diff <<EOF
38diff --git a/file2 b/file2
39new file mode 100644
40index 0000000..d00491f
41--- /dev/null
42+++ b/file2
43@@ -0,0 +1 @@
44+1
7474b8b4
BC
45diff --git a/untracked/untracked b/untracked/untracked
46new file mode 100644
47index 0000000..5a72eb2
48--- /dev/null
49+++ b/untracked/untracked
50@@ -0,0 +1 @@
51+untracked
78751302
DC
52EOF
53cat > expect.lstree <<EOF
54file2
7474b8b4 55untracked
78751302
DC
56EOF
57
58test_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'
66test_expect_success 'stash save --patch --include-untracked fails' '
67 test_must_fail git stash --patch --include-untracked
68'
69
70test_expect_success 'stash save --patch --all fails' '
71 test_must_fail git stash --patch --all
72'
73
74git clean --force --quiet
75
76cat > expect <<EOF
77 M file
4fd73124 78?? actual
78751302
DC
79?? expect
80?? file2
7474b8b4 81?? untracked/
78751302
DC
82EOF
83
84test_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 92git clean --force --quiet -d
78751302
DC
93
94test_expect_success 'stash save -u dirty index' '
95 echo 4 > file3 &&
96 git add file3 &&
97 test_tick &&
98 git stash -u
99'
100
101cat > expect <<EOF
102diff --git a/file3 b/file3
103new file mode 100644
104index 0000000..b8626c4
105--- /dev/null
106+++ b/file3
107@@ -0,0 +1 @@
108+4
109EOF
110
111test_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
117git reset > /dev/null
118
119test_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
125test_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
132rm -f expect
133
134test_expect_success 'stash save --include-untracked removed files got stashed' '
135 git stash pop &&
136 test ! -f file
137'
138
139cat > .gitignore <<EOF
140.gitignore
141ignored
7474b8b4 142ignored.d/
78751302
DC
143EOF
144
145test_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
155test_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
161test_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
168test_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
175test_done