File: t2700-refresh.sh

package info (click to toggle)
stgit 0.19-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,748 kB
  • sloc: python: 10,558; sh: 5,739; lisp: 2,678; makefile: 142; perl: 42
file content (186 lines) | stat: -rwxr-xr-x 4,519 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/sh

test_description='Run "stg refresh"'

. ./test-lib.sh

test_expect_success 'Initialize StGit stack' '
    stg init &&
    echo expected*.txt >> .git/info/exclude &&
    echo patches.txt >> .git/info/exclude &&
    echo show.txt >> .git/info/exclude &&
    echo diff.txt >> .git/info/exclude &&
    stg new p0 -m "base" &&
    for i in 1 2 3; do
        echo base >> foo$i.txt &&
        stg add foo$i.txt
    done
    stg refresh &&
    for i in 1 2 3; do
        stg new p$i -m "foo $i" &&
        echo "foo $i" >> foo$i.txt &&
        stg refresh
    done
'

cat > expected.txt <<EOF
p0
p3
EOF
test_expect_success 'Refresh top patch' '
    echo bar 3 >> foo3.txt &&
    stg refresh &&
    stg status &&
    test -z "$(stg status)" &&
    stg patches foo3.txt > patches.txt &&
    test_cmp expected.txt patches.txt
'

cat > expected.txt <<EOF
p0
p2
EOF
test_expect_success 'Refresh middle patch' '
    stg status &&
    echo bar 2 >> foo2.txt &&
    stg refresh -p p2 &&
    stg status &&
    test -z "$(stg status)" &&
    stg patches foo2.txt > patches.txt &&
    test_cmp expected.txt patches.txt
'

cat > expected.txt <<EOF
p0
p1
EOF
test_expect_success 'Refresh bottom patch' '
    stg status &&
    echo bar 1 >> foo1.txt &&
    stg refresh -p p1 &&
    stg status &&
    test -z "$(stg status)" &&
    stg patches foo1.txt > patches.txt &&
    test_cmp expected.txt patches.txt
'

cat > expected.txt <<EOF
p0
p1
p4
EOF
cat > expected2.txt <<EOF
diff --git a/foo1.txt b/foo1.txt
index 728535d..6f34984 100644
--- a/foo1.txt
+++ b/foo1.txt
@@ -1,3 +1,4 @@
 base
 foo 1
 bar 1
+baz 1
EOF
cat > expected3.txt <<EOF
diff --git a/foo1.txt b/foo1.txt
index 6f34984..a80eb63 100644
--- a/foo1.txt
+++ b/foo1.txt
@@ -2,3 +2,4 @@ base
 foo 1
 bar 1
 baz 1
+blah 1
diff --git a/foo2.txt b/foo2.txt
index 415c9f5..43168f2 100644
--- a/foo2.txt
+++ b/foo2.txt
@@ -1,3 +1,4 @@
 base
 foo 2
 bar 2
+baz 2
EOF
test_expect_success 'Refresh --index' '
    stg status &&
    stg new p4 -m "refresh_index" &&
    echo baz 1 >> foo1.txt &&
    stg add foo1.txt &&
    echo blah 1 >> foo1.txt &&
    echo baz 2 >> foo2.txt &&
    stg refresh --index &&
    stg patches foo1.txt > patches.txt &&
    git diff HEAD^..HEAD > show.txt &&
    stg diff > diff.txt &&
    test_cmp expected.txt patches.txt &&
    test_cmp expected2.txt show.txt &&
    test_cmp expected3.txt diff.txt &&
    stg new p5 -m "cleanup again" &&
    stg refresh
'

test_expect_success 'Refresh moved files' '
    stg mv foo1.txt foo1-new.txt &&
    stg refresh
'

test_expect_success 'Attempt invalid options with --index' '
    echo foo4 > foo4.txt &&
    stg add foo4.txt &&
    command_error stg refresh -i . 2>&1 |
    grep -e "Only full refresh is available with the --index option" &&
    command_error stg refresh -i --force 2>&1 |
    grep -e "You cannot --force a full refresh when using --index mode" &&
    command_error stg refresh -i --submodules 2>&1 |
    grep -e "--submodules is meaningless when keeping the current index"
    '

test_expect_success 'Attempt refresh with changed index and working tree' '
    echo "more foo" >> foo4.txt &&
    command_error stg refresh 2>&1 |
    grep -e "The index is dirty. Did you mean --index? To force a full refresh use --force"
'

test_expect_success 'Attempt to refresh to invalid patch name' '
    stg add foo4.txt &&
    command_error stg refresh -p bad-patchname 2>&1 |
    grep -e "bad-patchname: no such patch"
'

test_expect_success 'Attempt to refresh with no applied patches' '
    git rm -f foo4.txt &&
    stg pop -a &&
    echo foo5 > foo5.txt &&
    git add foo5.txt &&
    command_error stg refresh 2>&1 |
    grep -e "Cannot refresh top patch because no patches are applied" &&
    git rm -f foo5.txt
'

test_expect_success 'Attempt update with submodules' '
    stg push -a &&
    echo more >> foo2.txt &&
    command_error stg refresh --update --submodules 2>&1 |
    grep -e "--submodules is meaningless when only updating modified files"
'

test_expect_success 'Test annotate' '
    stg refresh --annotate "My Annotation" &&
    stg log -f | grep -e "My Annotation"
'

test_expect_success 'Attempt refresh with open conflict' '
    stg new -m p6 &&
    echo "foo" > conflicting.txt &&
    stg add conflicting.txt &&
    stg refresh &&
    stg pop &&
    stg new -m p7 &&
    echo "bar" > conflicting.txt &&
    stg add conflicting.txt &&
    stg refresh &&
    conflict stg push p6 &&
    command_error stg refresh 2>&1 |
    grep -e "resolve conflicts first"
'

test_done