Improve test coverage for stg pull
[stgit.git] / t / t2700-refresh.sh
blob2ef20dda6adc5d466dda0821427c93072698d9e6
1 #!/bin/sh
3 test_description='Run "stg refresh"'
5 . ./test-lib.sh
7 test_expect_success 'Initialize StGit stack' '
8 stg init &&
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 &&
15 for i in 1 2 3; do
16 echo base >> foo$i.txt &&
17 stg add foo$i.txt
18 done
19 stg refresh &&
20 for i in 1 2 3; do
21 stg new p$i -m "foo $i" &&
22 git notes add -m note$i &&
23 echo "foo $i" >> foo$i.txt &&
24 stg refresh
25 done
28 cat > expected.txt <<EOF
31 EOF
32 test_expect_success 'Refresh top patch' '
33 echo bar 3 >> foo3.txt &&
34 stg refresh &&
35 test "$(git notes show)" = "note3" &&
36 stg status &&
37 test -z "$(stg status)" &&
38 stg patches foo3.txt > patches.txt &&
39 test_cmp expected.txt patches.txt
42 cat > expected.txt <<EOF
45 EOF
46 test_expect_success 'Refresh middle patch' '
47 stg status &&
48 echo bar 2 >> foo2.txt &&
49 stg refresh -p p2 &&
50 test "$(git notes show $(stg id p2))" = "note2" &&
51 test "$(git notes show)" = "note3" &&
52 stg status &&
53 test -z "$(stg status)" &&
54 stg patches foo2.txt > patches.txt &&
55 test_cmp expected.txt patches.txt
58 cat > expected.txt <<EOF
61 EOF
62 test_expect_success 'Refresh bottom patch' '
63 stg status &&
64 echo bar 1 >> foo1.txt &&
65 stg refresh -p p1 &&
66 test "$(git notes show $(stg id p1))" = "note1" &&
67 test "$(git notes show $(stg id p2))" = "note2" &&
68 test "$(git notes show)" = "note3" &&
69 stg status &&
70 test -z "$(stg status)" &&
71 stg patches foo1.txt > patches.txt &&
72 test_cmp expected.txt patches.txt
75 cat > expected.txt <<EOF
79 EOF
80 cat > expected2.txt <<EOF
81 diff --git a/foo1.txt b/foo1.txt
82 index 728535d..6f34984 100644
83 --- a/foo1.txt
84 +++ b/foo1.txt
85 @@ -1,3 +1,4 @@
86 base
87 foo 1
88 bar 1
89 +baz 1
90 EOF
91 cat > expected3.txt <<EOF
92 diff --git a/foo1.txt b/foo1.txt
93 index 6f34984..a80eb63 100644
94 --- a/foo1.txt
95 +++ b/foo1.txt
96 @@ -2,3 +2,4 @@ base
97 foo 1
98 bar 1
99 baz 1
100 +blah 1
101 diff --git a/foo2.txt b/foo2.txt
102 index 415c9f5..43168f2 100644
103 --- a/foo2.txt
104 +++ b/foo2.txt
105 @@ -1,3 +1,4 @@
106 base
107 foo 2
108 bar 2
109 +baz 2
111 test_expect_success 'Refresh --index' '
112 stg status &&
113 stg new p4 -m "refresh_index" &&
114 git notes add -m note4
115 echo baz 1 >> foo1.txt &&
116 stg add 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" &&
128 stg refresh
131 test_expect_success 'Refresh moved files' '
132 stg mv foo1.txt foo1-new.txt &&
133 stg refresh
136 test_expect_success 'Attempt invalid options with --index' '
137 echo foo4 > foo4.txt &&
138 stg add 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' '
154 stg add foo4.txt &&
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 &&
161 stg pop -a &&
162 echo foo5 > foo5.txt &&
163 git add foo5.txt &&
164 command_error stg refresh 2>&1 |
165 grep -e "Cannot refresh top patch because no patches are applied" &&
166 git rm -f foo5.txt
169 test_expect_success 'Attempt update with submodules' '
170 stg push -a &&
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' '
182 stg new -m p6 &&
183 echo "foo" > conflicting.txt &&
184 stg add conflicting.txt &&
185 stg refresh &&
186 stg pop &&
187 stg new -m p7 &&
188 echo "bar" > conflicting.txt &&
189 stg add conflicting.txt &&
190 stg refresh &&
191 conflict stg push p6 &&
192 command_error stg refresh 2>&1 |
193 grep -e "resolve conflicts first"
196 test_done