Code

strbuf_add_wrapped_text(): factor out strbuf_add_indented_text()
[git.git] / t / t1200-tutorial.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Johannes Schindelin
4 #
6 test_description='A simple turial in the form of a test case'
8 . ./test-lib.sh
10 test_expect_success 'blob'  '
11         echo "Hello World" > hello &&
12         echo "Silly example" > example &&
14         git update-index --add hello example &&
16         test blob = "$(git cat-file -t 557db03)"
17 '
19 test_expect_success 'blob 557db03' '
20         test "Hello World" = "$(git cat-file blob 557db03)"
21 '
23 echo "It's a new day for git" >>hello
24 cat > diff.expect << EOF
25 diff --git a/hello b/hello
26 index 557db03..263414f 100644
27 --- a/hello
28 +++ b/hello
29 @@ -1 +1,2 @@
30  Hello World
31 +It's a new day for git
32 EOF
34 test_expect_success 'git diff-files -p' '
35         git diff-files -p > diff.output &&
36         test_cmp diff.expect diff.output
37 '
39 test_expect_success 'git diff' '
40         git diff > diff.output &&
41         test_cmp diff.expect diff.output
42 '
44 test_expect_success 'tree' '
45         tree=$(git write-tree 2>/dev/null)
46         test 8988da15d077d4829fc51d8544c097def6644dbb = $tree
47 '
49 test_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         test_cmp diff.expect diff.output
55 '
57 test_expect_success 'git diff HEAD' '
58         git diff HEAD > diff.output &&
59         test_cmp diff.expect diff.output
60 '
62 cat > whatchanged.expect << EOF
63 commit VARIABLE
64 Author: VARIABLE
65 Date:   VARIABLE
67     Initial commit
69 diff --git a/example b/example
70 new file mode 100644
71 index 0000000..f24c74a
72 --- /dev/null
73 +++ b/example
74 @@ -0,0 +1 @@
75 +Silly example
76 diff --git a/hello b/hello
77 new file mode 100644
78 index 0000000..557db03
79 --- /dev/null
80 +++ b/hello
81 @@ -0,0 +1 @@
82 +Hello World
83 EOF
85 test_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         test_cmp whatchanged.expect whatchanged.output
91 '
93 test_expect_success 'git tag my-first-tag' '
94         git tag my-first-tag &&
95         test_cmp .git/refs/heads/master .git/refs/tags/my-first-tag
96 '
98 test_expect_success 'git checkout -b mybranch' '
99         git checkout -b mybranch &&
100         test_cmp .git/refs/heads/master .git/refs/heads/mybranch
103 cat > branch.expect <<EOF
104   master
105 * mybranch
106 EOF
108 test_expect_success 'git branch' '
109         git branch > branch.output &&
110         test_cmp branch.expect branch.output
113 test_expect_success 'git resolve now fails' '
114         git checkout mybranch &&
115         echo "Work, work, work" >>hello &&
116         git commit -m "Some work." -i hello &&
118         git checkout master &&
120         echo "Play, play, play" >>hello &&
121         echo "Lots of fun" >>example &&
122         git commit -m "Some fun." -i hello example &&
124         test_must_fail git merge -m "Merge work in mybranch" mybranch
127 cat > hello << EOF
128 Hello World
129 It's a new day for git
130 Play, play, play
131 Work, work, work
132 EOF
134 cat > 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.
141 EOF
143 test_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         test_cmp show-branch.expect show-branch.output
150 cat > resolve.expect << EOF
151 Updating VARIABLE..VARIABLE
152 FASTFORWARD (no commit created; -m option ignored)
153  example |    1 +
154  hello   |    1 +
155  2 files changed, 2 insertions(+), 0 deletions(-)
156 EOF
158 test_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" \
162                 -e "s/^Fast[- ]forward /FASTFORWARD /" >resolve.output &&
163         test_cmp resolve.expect resolve.output
166 cat > show-branch2.expect << EOF
167 ! [master] Merge work in mybranch
168  * [mybranch] Merge work in mybranch
169 --
170 -- [master] Merge work in mybranch
171 EOF
173 test_expect_success 'git show-branch (part 2)' '
174         git show-branch --topo-order master mybranch > show-branch2.output &&
175         test_cmp show-branch2.expect show-branch2.output
178 cat > show-branch3.expect << EOF
179 ! [master] Merge work in mybranch
180  * [mybranch] Merge work in mybranch
181 --
182 -- [master] Merge work in mybranch
183 +* [master^2] Some work.
184 +* [master^] Some fun.
185 EOF
187 test_expect_success 'git show-branch (part 3)' '
188         git show-branch --topo-order --more=2 master mybranch \
189                 > show-branch3.output &&
190         test_cmp show-branch3.expect show-branch3.output
193 test_expect_success 'rewind to "Some fun." and "Some work."' '
194         git checkout mybranch &&
195         git reset --hard master^2 &&
196         git checkout master &&
197         git reset --hard master^
200 cat > show-branch4.expect << EOF
201 * [master] Some fun.
202  ! [mybranch] Some work.
203 --
204  + [mybranch] Some work.
205 *  [master] Some fun.
206 *+ [mybranch^] Initial commit
207 EOF
209 test_expect_success 'git show-branch (part 4)' '
210         git show-branch --topo-order > show-branch4.output &&
211         test_cmp show-branch4.expect show-branch4.output
214 test_expect_success 'manual merge' '
215         mb=$(git merge-base HEAD mybranch) &&
216         git name-rev --name-only --tags $mb > name-rev.output &&
217         test "my-first-tag" = $(cat name-rev.output) &&
219         git read-tree -m -u $mb HEAD mybranch
222 cat > ls-files.expect << EOF
223 100644 7f8b141b65fdcee47321e399a2598a235a032422 0       example
224 100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1       hello
225 100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2       hello
226 100644 cc44c73eb783565da5831b4d820c962954019b69 3       hello
227 EOF
229 test_expect_success 'git ls-files --stage' '
230         git ls-files --stage > ls-files.output &&
231         test_cmp ls-files.expect ls-files.output
234 cat > ls-files-unmerged.expect << EOF
235 100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1       hello
236 100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2       hello
237 100644 cc44c73eb783565da5831b4d820c962954019b69 3       hello
238 EOF
240 test_expect_success 'git ls-files --unmerged' '
241         git ls-files --unmerged > ls-files-unmerged.output &&
242         test_cmp ls-files-unmerged.expect ls-files-unmerged.output
245 test_expect_success 'git-merge-index' '
246         test_must_fail git merge-index git-merge-one-file hello
249 test_expect_success 'git ls-files --stage (part 2)' '
250         git ls-files --stage > ls-files.output2 &&
251         test_cmp ls-files.expect ls-files.output2
254 test_expect_success 'git repack' 'git repack'
255 test_expect_success 'git prune-packed' 'git prune-packed'
256 test_expect_success '-> only packed objects' '
257         git prune && # Remove conflict marked blobs
258         ! find .git/objects/[0-9a-f][0-9a-f] -type f
261 test_done