3 test_description
='Run "stg refresh"'
7 test_expect_success
'Initialize StGit stack' '
9 echo expected*.txt >> .git/info/exclude &&
10 echo patches.txt >> .git/info/exclude &&
11 echo show.txt >> .git/info/exclude &&
12 echo diff.txt >> .git/info/exclude &&
13 stg new p0 -m "base" &&
14 git notes add -m note0 &&
16 echo base >> foo$i.txt &&
21 stg new p$i -m "foo $i" &&
22 git notes add -m note$i &&
23 echo "foo $i" >> foo$i.txt &&
28 cat > expected.txt
<<EOF
32 test_expect_success
'Refresh top patch' '
33 echo bar 3 >> foo3.txt &&
35 test "$(git notes show)" = "note3" &&
37 test -z "$(stg status)" &&
38 stg patches foo3.txt > patches.txt &&
39 test_cmp expected.txt patches.txt
42 cat > expected.txt
<<EOF
46 test_expect_success
'Refresh middle patch' '
48 echo bar 2 >> foo2.txt &&
50 test "$(git notes show $(stg id p2))" = "note2" &&
51 test "$(git notes show)" = "note3" &&
53 test -z "$(stg status)" &&
54 stg patches foo2.txt > patches.txt &&
55 test_cmp expected.txt patches.txt
58 cat > expected.txt
<<EOF
62 test_expect_success
'Refresh bottom patch' '
64 echo bar 1 >> foo1.txt &&
66 test "$(git notes show $(stg id p1))" = "note1" &&
67 test "$(git notes show $(stg id p2))" = "note2" &&
68 test "$(git notes show)" = "note3" &&
70 test -z "$(stg status)" &&
71 stg patches foo1.txt > patches.txt &&
72 test_cmp expected.txt patches.txt
75 cat > expected.txt
<<EOF
80 cat > expected2.txt
<<EOF
81 diff --git a/foo1.txt b/foo1.txt
82 index 728535d..6f34984 100644
91 cat > expected3.txt
<<EOF
92 diff --git a/foo1.txt b/foo1.txt
93 index 6f34984..a80eb63 100644
101 diff --git a/foo2.txt b/foo2.txt
102 index 415c9f5..43168f2 100644
111 test_expect_success
'Refresh --index' '
113 stg new p4 -m "refresh_index" &&
114 git notes add -m note4
115 echo baz 1 >> foo1.txt &&
117 echo blah 1 >> foo1.txt &&
118 echo baz 2 >> foo2.txt &&
119 stg refresh --index &&
120 test "$(git notes show)" = "note4" &&
121 stg patches foo1.txt > patches.txt &&
122 git diff HEAD^..HEAD > show.txt &&
123 stg diff > diff.txt &&
124 test_cmp expected.txt patches.txt &&
125 test_cmp expected2.txt show.txt &&
126 test_cmp expected3.txt diff.txt &&
127 stg new p5 -m "cleanup again" &&
131 test_expect_success
'Refresh moved files' '
132 stg mv foo1.txt foo1-new.txt &&
136 test_expect_success
'Attempt invalid options with --index' '
137 echo foo4 > foo4.txt &&
139 command_error stg refresh -i . 2>&1 |
140 grep -e "Only full refresh is available with the --index option" &&
141 command_error stg refresh -i --force 2>&1 |
142 grep -e "You cannot --force a full refresh when using --index mode" &&
143 command_error stg refresh -i --submodules 2>&1 |
144 grep -e "--submodules is meaningless when keeping the current index"
147 test_expect_success
'Attempt refresh with changed index and working tree' '
148 echo "more foo" >> foo4.txt &&
149 command_error stg refresh 2>&1 |
150 grep -e "The index is dirty. Did you mean --index?"
153 test_expect_success
'Attempt to refresh to invalid patch name' '
155 command_error stg refresh -p bad-patchname 2>&1 |
156 grep -e "bad-patchname: no such patch"
159 test_expect_success
'Attempt to refresh with no applied patches' '
160 git rm -f foo4.txt &&
162 echo foo5 > foo5.txt &&
164 command_error stg refresh 2>&1 |
165 grep -e "Cannot refresh top patch because no patches are applied" &&
169 test_expect_success
'Attempt update with submodules' '
171 echo more >> foo2.txt &&
172 command_error stg refresh --update --submodules 2>&1 |
173 grep -e "--submodules is meaningless when only updating modified files"
176 test_expect_success
'Test annotate' '
177 stg refresh --annotate "My Annotation" &&
178 stg log -f | grep -e "My Annotation"
181 test_expect_success
'Attempt refresh with open conflict' '
183 echo "foo" > conflicting.txt &&
184 stg add conflicting.txt &&
188 echo "bar" > conflicting.txt &&
189 stg add conflicting.txt &&
191 conflict stg push p6 &&
192 command_error stg refresh 2>&1 |
193 grep -e "resolve conflicts first"