299e72417535c2a24458cc9c4ab5dd1f193de11a
1#!/bin/sh
2#
3# Copyright (c) 2005 Johannes Schindelin
4#
5
6test_description='A simple turial in the form of a test case'
7
8. ./test-lib.sh
9
10test_expect_success 'blob' '
11 echo "Hello World" > hello &&
12 echo "Silly example" > example &&
13
14 git update-index --add hello example &&
15
16 test blob = "$(git cat-file -t 557db03)"
17'
18
19test_expect_success 'blob 557db03' '
20 test "Hello World" = "$(git cat-file blob 557db03)"
21'
22
23echo "It's a new day for git" >>hello
24cat > diff.expect << EOF
25diff --git a/hello b/hello
26index 557db03..263414f 100644
27--- a/hello
28+++ b/hello
29@@ -1 +1,2 @@
30 Hello World
31+It's a new day for git
32EOF
33
34test_expect_success 'git diff-files -p' '
35 git diff-files -p > diff.output &&
36 cmp diff.expect diff.output
37'
38
39test_expect_success 'git diff' '
40 git diff > diff.output &&
41 cmp diff.expect diff.output
42'
43
44test_expect_success 'tree' '
45 tree=$(git write-tree 2>/dev/null)
46 test 8988da15d077d4829fc51d8544c097def6644dbb = $tree
47'
48
49test_expect_success 'git diff-index -p HEAD' '
50 tree=$(git write-tree)
51 commit=$(echo "Initial commit" | git commit-tree $tree) &&
52 git update-ref HEAD $commit &&
53 git diff-index -p HEAD > diff.output &&
54 cmp diff.expect diff.output
55'
56
57test_expect_success 'git diff HEAD' '
58 git diff HEAD > diff.output &&
59 cmp diff.expect diff.output
60'
61
62cat > whatchanged.expect << EOF
63commit VARIABLE
64Author: VARIABLE
65Date: VARIABLE
66
67 Initial commit
68
69diff --git a/example b/example
70new file mode 100644
71index 0000000..f24c74a
72--- /dev/null
73+++ b/example
74@@ -0,0 +1 @@
75+Silly example
76diff --git a/hello b/hello
77new file mode 100644
78index 0000000..557db03
79--- /dev/null
80+++ b/hello
81@@ -0,0 +1 @@
82+Hello World
83EOF
84
85test_expect_success 'git whatchanged -p --root' '
86 git whatchanged -p --root | \
87 sed -e "1s/^\(.\{7\}\).\{40\}/\1VARIABLE/" \
88 -e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \
89 > whatchanged.output &&
90 cmp whatchanged.expect whatchanged.output
91'
92
93test_expect_success 'git tag my-first-tag' '
94 git tag my-first-tag &&
95 cmp .git/refs/heads/master .git/refs/tags/my-first-tag
96'
97
98test_expect_success 'git checkout -b mybranch' '
99 git checkout -b mybranch &&
100 cmp .git/refs/heads/master .git/refs/heads/mybranch
101'
102
103cat > branch.expect <<EOF
104 master
105* mybranch
106EOF
107
108test_expect_success 'git branch' '
109 git branch > branch.output &&
110 cmp branch.expect branch.output
111'
112
113test_expect_success 'git resolve now fails' '
114 git checkout mybranch &&
115 echo "Work, work, work" >>hello &&
116 git commit -m "Some work." -i hello &&
117
118 git checkout master &&
119
120 echo "Play, play, play" >>hello &&
121 echo "Lots of fun" >>example &&
122 git commit -m "Some fun." -i hello example &&
123
124 test_must_fail git merge -m "Merge work in mybranch" mybranch
125'
126
127cat > hello << EOF
128Hello World
129It's a new day for git
130Play, play, play
131Work, work, work
132EOF
133
134cat > show-branch.expect << EOF
135* [master] Merge work in mybranch
136 ! [mybranch] Some work.
137--
138- [master] Merge work in mybranch
139*+ [mybranch] Some work.
140* [master^] Some fun.
141EOF
142
143test_expect_success 'git show-branch' '
144 git commit -m "Merge work in mybranch" -i hello &&
145 git show-branch --topo-order --more=1 master mybranch \
146 > show-branch.output &&
147 cmp show-branch.expect show-branch.output
148'
149
150cat > resolve.expect << EOF
151Updating VARIABLE..VARIABLE
152Fast forward (no commit created; -m option ignored)
153 example | 1 +
154 hello | 1 +
155 2 files changed, 2 insertions(+), 0 deletions(-)
156EOF
157
158test_expect_success 'git resolve' '
159 git checkout mybranch &&
160 git merge -m "Merge upstream changes." master | \
161 sed -e "1s/[0-9a-f]\{7\}/VARIABLE/g" >resolve.output &&
162 cmp resolve.expect resolve.output
163'
164
165cat > show-branch2.expect << EOF
166! [master] Merge work in mybranch
167 * [mybranch] Merge work in mybranch
168--
169-- [master] Merge work in mybranch
170EOF
171
172test_expect_success 'git show-branch (part 2)' '
173 git show-branch --topo-order master mybranch > show-branch2.output &&
174 cmp show-branch2.expect show-branch2.output
175'
176
177cat > show-branch3.expect << EOF
178! [master] Merge work in mybranch
179 * [mybranch] Merge work in mybranch
180--
181-- [master] Merge work in mybranch
182+* [master^2] Some work.
183+* [master^] Some fun.
184EOF
185
186test_expect_success 'git show-branch (part 3)' '
187 git show-branch --topo-order --more=2 master mybranch \
188 > show-branch3.output &&
189 cmp show-branch3.expect show-branch3.output
190'
191
192test_expect_success 'rewind to "Some fun." and "Some work."' '
193 git checkout mybranch &&
194 git reset --hard master^2 &&
195 git checkout master &&
196 git reset --hard master^
197'
198
199cat > show-branch4.expect << EOF
200* [master] Some fun.
201 ! [mybranch] Some work.
202--
203 + [mybranch] Some work.
204* [master] Some fun.
205*+ [mybranch^] Initial commit
206EOF
207
208test_expect_success 'git show-branch (part 4)' '
209 git show-branch --topo-order > show-branch4.output &&
210 cmp show-branch4.expect show-branch4.output
211'
212
213test_expect_success 'manual merge' '
214 mb=$(git merge-base HEAD mybranch) &&
215 git name-rev --name-only --tags $mb > name-rev.output &&
216 test "my-first-tag" = $(cat name-rev.output) &&
217
218 git read-tree -m -u $mb HEAD mybranch
219'
220
221cat > ls-files.expect << EOF
222100644 7f8b141b65fdcee47321e399a2598a235a032422 0 example
223100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1 hello
224100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2 hello
225100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello
226EOF
227
228test_expect_success 'git ls-files --stage' '
229 git ls-files --stage > ls-files.output &&
230 cmp ls-files.expect ls-files.output
231'
232
233cat > ls-files-unmerged.expect << EOF
234100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1 hello
235100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2 hello
236100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello
237EOF
238
239test_expect_success 'git ls-files --unmerged' '
240 git ls-files --unmerged > ls-files-unmerged.output &&
241 cmp ls-files-unmerged.expect ls-files-unmerged.output
242'
243
244test_expect_success 'git-merge-index' '
245 test_must_fail git merge-index git-merge-one-file hello
246'
247
248test_expect_success 'git ls-files --stage (part 2)' '
249 git ls-files --stage > ls-files.output2 &&
250 cmp ls-files.expect ls-files.output2
251'
252
253test_expect_success 'git repack' 'git repack'
254test_expect_success 'git prune-packed' 'git prune-packed'
255test_expect_success '-> only packed objects' '
256 git prune && # Remove conflict marked blobs
257 ! find .git/objects/[0-9a-f][0-9a-f] -type f
258'
259
260test_done