]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1200-tutorial.sh
GIT-VERSION-GEN: support non-standard $GIT_DIR path
[thirdparty/git.git] / t / t1200-tutorial.sh
CommitLineData
2ae6c706
JS
1#!/bin/sh
2#
3# Copyright (c) 2005 Johannes Schindelin
4#
5
b599deec 6test_description='A simple turial in the form of a test case'
2ae6c706
JS
7
8. ./test-lib.sh
9
1a994dc3
SB
10test_expect_success 'blob' '
11 echo "Hello World" > hello &&
12 echo "Silly example" > example &&
2ae6c706 13
1a994dc3 14 git update-index --add hello example &&
2ae6c706 15
1a994dc3
SB
16 test blob = "$(git cat-file -t 557db03)"
17'
2ae6c706 18
1a994dc3
SB
19test_expect_success 'blob 557db03' '
20 test "Hello World" = "$(git cat-file blob 557db03)"
21'
2ae6c706
JS
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
2ae6c706 33
1a994dc3
SB
34test_expect_success 'git diff-files -p' '
35 git diff-files -p > diff.output &&
b9f3bde1 36 test_cmp diff.expect diff.output
1a994dc3 37'
2ae6c706 38
1a994dc3
SB
39test_expect_success 'git diff' '
40 git diff > diff.output &&
b9f3bde1 41 test_cmp diff.expect diff.output
1a994dc3 42'
2ae6c706 43
1a994dc3 44test_expect_success 'tree' '
a48fcd83 45 tree=$(git write-tree 2>/dev/null) &&
1a994dc3
SB
46 test 8988da15d077d4829fc51d8544c097def6644dbb = $tree
47'
2ae6c706 48
1a994dc3 49test_expect_success 'git diff-index -p HEAD' '
5d166ccb
NS
50 test_tick &&
51 tree=$(git write-tree) &&
7c5858a6
SB
52 commit=$(echo "Initial commit" | git commit-tree $tree) &&
53 git update-ref HEAD $commit &&
1a994dc3 54 git diff-index -p HEAD > diff.output &&
b9f3bde1 55 test_cmp diff.expect diff.output
1a994dc3 56'
2ae6c706 57
1a994dc3
SB
58test_expect_success 'git diff HEAD' '
59 git diff HEAD > diff.output &&
b9f3bde1 60 test_cmp diff.expect diff.output
1a994dc3 61'
2ae6c706
JS
62
63cat > whatchanged.expect << EOF
91539833 64commit VARIABLE
2ae6c706
JS
65Author: VARIABLE
66Date: VARIABLE
67
68 Initial commit
69
70diff --git a/example b/example
71new file mode 100644
72index 0000000..f24c74a
73--- /dev/null
74+++ b/example
75@@ -0,0 +1 @@
76+Silly example
77diff --git a/hello b/hello
78new file mode 100644
79index 0000000..557db03
80--- /dev/null
81+++ b/hello
82@@ -0,0 +1 @@
83+Hello World
84EOF
85
1a994dc3 86test_expect_success 'git whatchanged -p --root' '
b9f3bde1 87 git whatchanged -p --root |
1a994dc3 88 sed -e "1s/^\(.\{7\}\).\{40\}/\1VARIABLE/" \
2ae6c706 89 -e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \
1a994dc3 90 > whatchanged.output &&
b9f3bde1 91 test_cmp whatchanged.expect whatchanged.output
1a994dc3 92'
2ae6c706 93
1a994dc3
SB
94test_expect_success 'git tag my-first-tag' '
95 git tag my-first-tag &&
b9f3bde1 96 test_cmp .git/refs/heads/master .git/refs/tags/my-first-tag
1a994dc3 97'
2ae6c706 98
1a994dc3
SB
99test_expect_success 'git checkout -b mybranch' '
100 git checkout -b mybranch &&
b9f3bde1 101 test_cmp .git/refs/heads/master .git/refs/heads/mybranch
1a994dc3 102'
2ae6c706
JS
103
104cat > branch.expect <<EOF
105 master
106* mybranch
107EOF
108
1a994dc3
SB
109test_expect_success 'git branch' '
110 git branch > branch.output &&
b9f3bde1 111 test_cmp branch.expect branch.output
1a994dc3 112'
2ae6c706 113
1a994dc3
SB
114test_expect_success 'git resolve now fails' '
115 git checkout mybranch &&
116 echo "Work, work, work" >>hello &&
5d166ccb 117 test_tick &&
1a994dc3 118 git commit -m "Some work." -i hello &&
2ae6c706 119
1a994dc3 120 git checkout master &&
2ae6c706 121
1a994dc3
SB
122 echo "Play, play, play" >>hello &&
123 echo "Lots of fun" >>example &&
5d166ccb 124 test_tick &&
1a994dc3 125 git commit -m "Some fun." -i hello example &&
2ae6c706 126
d492b31c 127 test_must_fail git merge -m "Merge work in mybranch" mybranch
207dfa07 128'
2ae6c706
JS
129
130cat > hello << EOF
131Hello World
132It's a new day for git
133Play, play, play
134Work, work, work
135EOF
136
2ae6c706 137cat > show-branch.expect << EOF
7c5858a6 138* [master] Merge work in mybranch
2ae6c706
JS
139 ! [mybranch] Some work.
140--
7c5858a6 141- [master] Merge work in mybranch
ebedc319 142*+ [mybranch] Some work.
7c5858a6 143* [master^] Some fun.
2ae6c706
JS
144EOF
145
1a994dc3 146test_expect_success 'git show-branch' '
5d166ccb 147 test_tick &&
7c5858a6
SB
148 git commit -m "Merge work in mybranch" -i hello &&
149 git show-branch --topo-order --more=1 master mybranch \
150 > show-branch.output &&
b9f3bde1 151 test_cmp show-branch.expect show-branch.output
1a994dc3 152'
2ae6c706
JS
153
154cat > resolve.expect << EOF
1a994dc3 155Updating VARIABLE..VARIABLE
5c5dd6e5 156FASTFORWARD (no commit created; -m option ignored)
dc801e71
ZJS
157 example | 1 +
158 hello | 1 +
7f814632 159 2 files changed, 2 insertions(+)
2ae6c706
JS
160EOF
161
1a994dc3
SB
162test_expect_success 'git resolve' '
163 git checkout mybranch &&
b9f3bde1 164 git merge -m "Merge upstream changes." master |
5c5dd6e5 165 sed -e "1s/[0-9a-f]\{7\}/VARIABLE/g" \
2ceb61e0
ÆAB
166 -e "s/^Fast[- ]forward /FASTFORWARD /" >resolve.output
167'
168
c36f9412
JH
169test_expect_success 'git resolve output' '
170 test_i18ncmp resolve.expect resolve.output
1a994dc3 171'
2ae6c706
JS
172
173cat > show-branch2.expect << EOF
7c5858a6
SB
174! [master] Merge work in mybranch
175 * [mybranch] Merge work in mybranch
2ae6c706 176--
7c5858a6 177-- [master] Merge work in mybranch
2ae6c706
JS
178EOF
179
1a994dc3
SB
180test_expect_success 'git show-branch (part 2)' '
181 git show-branch --topo-order master mybranch > show-branch2.output &&
b9f3bde1 182 test_cmp show-branch2.expect show-branch2.output
1a994dc3 183'
2ae6c706 184
7c5858a6
SB
185cat > show-branch3.expect << EOF
186! [master] Merge work in mybranch
187 * [mybranch] Merge work in mybranch
188--
189-- [master] Merge work in mybranch
190+* [master^2] Some work.
191+* [master^] Some fun.
192EOF
193
194test_expect_success 'git show-branch (part 3)' '
195 git show-branch --topo-order --more=2 master mybranch \
196 > show-branch3.output &&
b9f3bde1 197 test_cmp show-branch3.expect show-branch3.output
7c5858a6
SB
198'
199
200test_expect_success 'rewind to "Some fun." and "Some work."' '
201 git checkout mybranch &&
202 git reset --hard master^2 &&
203 git checkout master &&
204 git reset --hard master^
205'
206
207cat > show-branch4.expect << EOF
208* [master] Some fun.
209 ! [mybranch] Some work.
210--
7c5858a6 211* [master] Some fun.
5d166ccb
NS
212 + [mybranch] Some work.
213*+ [master^] Initial commit
7c5858a6
SB
214EOF
215
216test_expect_success 'git show-branch (part 4)' '
217 git show-branch --topo-order > show-branch4.output &&
b9f3bde1 218 test_cmp show-branch4.expect show-branch4.output
7c5858a6
SB
219'
220
221test_expect_success 'manual merge' '
222 mb=$(git merge-base HEAD mybranch) &&
223 git name-rev --name-only --tags $mb > name-rev.output &&
224 test "my-first-tag" = $(cat name-rev.output) &&
225
226 git read-tree -m -u $mb HEAD mybranch
227'
228
229cat > ls-files.expect << EOF
230100644 7f8b141b65fdcee47321e399a2598a235a032422 0 example
231100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1 hello
232100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2 hello
233100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello
234EOF
235
236test_expect_success 'git ls-files --stage' '
237 git ls-files --stage > ls-files.output &&
b9f3bde1 238 test_cmp ls-files.expect ls-files.output
7c5858a6
SB
239'
240
241cat > ls-files-unmerged.expect << EOF
242100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1 hello
243100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2 hello
244100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello
245EOF
246
247test_expect_success 'git ls-files --unmerged' '
248 git ls-files --unmerged > ls-files-unmerged.output &&
b9f3bde1 249 test_cmp ls-files-unmerged.expect ls-files-unmerged.output
7c5858a6
SB
250'
251
252test_expect_success 'git-merge-index' '
253 test_must_fail git merge-index git-merge-one-file hello
254'
255
256test_expect_success 'git ls-files --stage (part 2)' '
257 git ls-files --stage > ls-files.output2 &&
b9f3bde1 258 test_cmp ls-files.expect ls-files.output2
7c5858a6
SB
259'
260
2ae6c706
JS
261test_expect_success 'git repack' 'git repack'
262test_expect_success 'git prune-packed' 'git prune-packed'
41ac414e 263test_expect_success '-> only packed objects' '
1a994dc3 264 git prune && # Remove conflict marked blobs
15caa410 265 test $(find .git/objects/[0-9a-f][0-9a-f] -type f -print 2>/dev/null | wc -l) = 0
41ac414e 266'
2ae6c706
JS
267
268test_done