c57c9d5300d7f6cbd8c0ea1174cc9e27191f3740
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 echo "Initial commit" | \
51 git commit-tree $(git write-tree) 2>&1 > .git/refs/heads/master &&
52 git diff-index -p HEAD > diff.output &&
53 cmp diff.expect diff.output
54'
55
56test_expect_success 'git diff HEAD' '
57 git diff HEAD > diff.output &&
58 cmp diff.expect diff.output
59'
60
61cat > whatchanged.expect << EOF
62commit VARIABLE
63Author: VARIABLE
64Date: VARIABLE
65
66 Initial commit
67
68diff --git a/example b/example
69new file mode 100644
70index 0000000..f24c74a
71--- /dev/null
72+++ b/example
73@@ -0,0 +1 @@
74+Silly example
75diff --git a/hello b/hello
76new file mode 100644
77index 0000000..557db03
78--- /dev/null
79+++ b/hello
80@@ -0,0 +1 @@
81+Hello World
82EOF
83
84test_expect_success 'git whatchanged -p --root' '
85 git whatchanged -p --root | \
86 sed -e "1s/^\(.\{7\}\).\{40\}/\1VARIABLE/" \
87 -e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \
88 > whatchanged.output &&
89 cmp whatchanged.expect whatchanged.output
90'
91
92test_expect_success 'git tag my-first-tag' '
93 git tag my-first-tag &&
94 cmp .git/refs/heads/master .git/refs/tags/my-first-tag
95'
96
97test_expect_success 'git checkout -b mybranch' '
98 git checkout -b mybranch &&
99 cmp .git/refs/heads/master .git/refs/heads/mybranch
100'
101
102cat > branch.expect <<EOF
103 master
104* mybranch
105EOF
106
107test_expect_success 'git branch' '
108 git branch > branch.output &&
109 cmp branch.expect branch.output
110'
111
112test_expect_success 'git resolve now fails' '
113 git checkout mybranch &&
114 echo "Work, work, work" >>hello &&
115 git commit -m "Some work." -i hello &&
116
117 git checkout master &&
118
119 echo "Play, play, play" >>hello &&
120 echo "Lots of fun" >>example &&
121 git commit -m "Some fun." -i hello example &&
122
123 test_must_fail git merge -m "Merge work in mybranch" mybranch
124'
125
126cat > hello << EOF
127Hello World
128It's a new day for git
129Play, play, play
130Work, work, work
131EOF
132
133cat > show-branch.expect << EOF
134* [master] Merged "mybranch" changes.
135 ! [mybranch] Some work.
136--
137- [master] Merged "mybranch" changes.
138*+ [mybranch] Some work.
139EOF
140
141test_expect_success 'git show-branch' '
142 git commit -m "Merged \"mybranch\" changes." -i hello &&
143 git show-branch --topo-order master mybranch > show-branch.output &&
144 cmp show-branch.expect show-branch.output
145'
146
147cat > resolve.expect << EOF
148Updating VARIABLE..VARIABLE
149Fast forward (no commit created; -m option ignored)
150 example | 1 +
151 hello | 1 +
152 2 files changed, 2 insertions(+), 0 deletions(-)
153EOF
154
155test_expect_success 'git resolve' '
156 git checkout mybranch &&
157 git merge -m "Merge upstream changes." master | \
158 sed -e "1s/[0-9a-f]\{7\}/VARIABLE/g" >resolve.output &&
159 cmp resolve.expect resolve.output
160'
161
162cat > show-branch2.expect << EOF
163! [master] Merged "mybranch" changes.
164 * [mybranch] Merged "mybranch" changes.
165--
166-- [master] Merged "mybranch" changes.
167EOF
168
169test_expect_success 'git show-branch (part 2)' '
170 git show-branch --topo-order master mybranch > show-branch2.output &&
171 cmp show-branch2.expect show-branch2.output
172'
173
174test_expect_success 'git repack' 'git repack'
175test_expect_success 'git prune-packed' 'git prune-packed'
176test_expect_success '-> only packed objects' '
177 git prune && # Remove conflict marked blobs
178 ! find .git/objects/[0-9a-f][0-9a-f] -type f
179'
180
181test_done