2
2
. t/test-lib.sh
3
3
set -e -o ' pipefail'
4
4
5
- echo " 1..9 "
5
+ echo " 1..11 "
6
6
7
7
branch=testbr
8
8
repo=tmp/test/repo
@@ -83,12 +83,12 @@ start_test 'Commit data correct'
83
83
make_test_repo
84
84
$git branch $branch
85
85
assert_branch ' 737b0f439051 refs/heads/master' master
86
- assert_branch ' 737b0f439051 refs/heads/testbr '
86
+ assert_branch " 737b0f439051 refs/heads/$branch "
87
87
88
88
echo bar > $files /one
89
89
echo bar > $files /subdir/two
90
90
$git commit-filetree $branch $files
91
- assert_branch ' 003e5987f385 refs/heads/testbr '
91
+ assert_branch " 003e5987f385 refs/heads/$branch "
92
92
93
93
end_test
94
94
@@ -102,7 +102,7 @@ $git branch $branch
102
102
echo bar > $files /one
103
103
echo bar > $files /subdir/two
104
104
$git commit-filetree refs/heads/$branch $files
105
- assert_branch ' 003e5987f385 refs/heads/testbr '
105
+ assert_branch " 003e5987f385 refs/heads/$branch "
106
106
107
107
end_test
108
108
@@ -116,7 +116,7 @@ $git branch $branch
116
116
echo bar > $files /one
117
117
echo bar > $files /subdir/two
118
118
(cd $repo && ../../../bin/git-commit-filetree $branch ../files)
119
- assert_branch ' 003e5987f385 refs/heads/testbr '
119
+ assert_branch " 003e5987f385 refs/heads/$branch "
120
120
121
121
end_test
122
122
@@ -130,7 +130,7 @@ echo bar > $files/subdir/two
130
130
$git commit-filetree $branch $files
131
131
$git commit-filetree $branch $files
132
132
$git commit-filetree $branch $files
133
- assert_branch ' 003e5987f385 refs/heads/testbr '
133
+ assert_branch " 003e5987f385 refs/heads/$branch "
134
134
end_test
135
135
136
136
# #### 9
@@ -146,3 +146,80 @@ test_equal \
146
146
737b0f4 testbr@{1}: branch: Created from master' \
147
147
" $( $git reflog --no-decorate $branch ) "
148
148
end_test
149
+
150
+ # #### fast-foward test support
151
+
152
+ make_test_repo_with_two_branches () {
153
+ make_test_repo
154
+
155
+ # Test branch to which we commit
156
+ $git branch $branch
157
+ assert_branch " 737b0f439051 refs/heads/$branch "
158
+ touch $files /one; $git commit-filetree $branch $files
159
+ assert_branch " 8a4cf12bef5f refs/heads/$branch "
160
+
161
+ # Test tracking branch with an additional commit
162
+ $git branch $branch -tracking $branch
163
+ assert_branch " 8a4cf12bef5f refs/heads/$branch -tracking" $branch -tracking
164
+ touch $files /two; $git commit-filetree $branch -tracking $files
165
+ assert_branch " fcb13b95f172 refs/heads/$branch -tracking" $branch -tracking
166
+ }
167
+
168
+ # If you want to view the commit graph in a test, add the following.
169
+ view_commit_graph () {
170
+ $git log --all --graph --pretty=oneline --abbrev=12
171
+ }
172
+
173
+ # #### 10
174
+
175
+ start_test ' Fast-forward commit branch'
176
+ make_test_repo_with_two_branches
177
+
178
+ # Make test branch track test-tracking branch, but it's one commit behind.
179
+ $git > /dev/null branch --set-upstream-to=$branch -tracking $branch
180
+ assert_branch " 8a4cf12bef5f refs/heads/$branch "
181
+
182
+ touch $files /three
183
+ test_equal 0 " $( $git commit-filetree 2>&1 $branch $files ; echo $? ) "
184
+ # Parent commit is head of tracking branch.
185
+ expected_log="
186
+ ef65bb4d9108 978307200
187
+ fcb13b95f172 978307200
188
+ 8a4cf12bef5f 978307200"
189
+ test_equal " $expected_log " \
190
+ " $( echo; $git log -3 --abbrev=12 --pretty=' format:%h %ct' $branch ) "
191
+
192
+ # We can add more commits to commit branch when already ahead of tracking
193
+ touch $files /four
194
+ test_equal 0 " $( $git commit-filetree 2>&1 $branch $files ; echo $? ) "
195
+ expected_log="
196
+ 191c80c3688d 978307200
197
+ ef65bb4d9108 978307200
198
+ fcb13b95f172 978307200
199
+ 8a4cf12bef5f 978307200"
200
+ test_equal " $expected_log " \
201
+ " $( echo; $git log -4 --abbrev=12 --pretty=' format:%h %ct' $branch ) "
202
+
203
+ end_test
204
+
205
+ # #### 11
206
+
207
+ start_test ' Cannot fast-forward commit branch'
208
+ make_test_repo_with_two_branches
209
+
210
+ # Add another commit to local branch that's not on tracking branch.
211
+ touch $files /commit-from-elsewhere
212
+ $git commit-filetree $branch $files
213
+ assert_branch " 58cce3125df7 refs/heads/$branch "
214
+
215
+ # Make test branch track test-tracking branch, but 1/1 ahead/behind
216
+ $git > /dev/null branch --set-upstream-to=$branch -tracking $branch
217
+
218
+ touch $files /three
219
+ exitcode=" $( $git commit-filetree $branch $files > /dev/null 2>&1 ; echo $? ) "
220
+ test_equal 3 " $exitcode "
221
+ message=$( $git commit-filetree 2>&1 $branch $files || true)
222
+ expected=' Branch testbr has diverged from tracking refs/heads/testbr-tracking'
223
+ [[ $message =~ $expected ]] || fail_test " bad message: $message "
224
+
225
+ end_test
0 commit comments