Adapt tutorial to cygwin and add test case
Lacking reliable symlinks, the instructions in the tutorial did not work in a cygwin setup. Also, a few outputs were not correct. This patch fixes these, and adds a test case which follows the instructions of the tutorial (except git-clone, -fetch and -push, which I have not done yet). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Oct 13, 2005 at 11:36 UTC
2ae6c706749b44f05917fcd04037f545d16fb345
2 files changed
+210
-19
Documentation/tutorial.txt
+52
-19
@@ -52,7 +52,9 @@ your new project. You will now have a `.git` directory, and you can
52
inspect that with `ls`. For your new empty project, it should show you
53
three entries, among other things:
54
55
- - a symlink called `HEAD`, pointing to `refs/heads/master`
55
+ - a symlink called `HEAD`, pointing to `refs/heads/master` (if your
56
+ platform does not have native symlinks, it is a file containing the
57
+ line "ref: refs/heads/master")
58
+
59
Don't worry about the fact that the file that the `HEAD` link points to
60
doesn't even exist yet -- you haven't created the commit that will
@@ -228,6 +230,7 @@ which will spit out
230
231
------------
232
diff --git a/hello b/hello
233
+index 557db03..263414f 100644
234
--- a/hello
235
+++ b/hello
236
@@ -1 +1,2 @@
@@ -290,13 +293,14 @@ also wants to get a commit message
293
on its standard input, and it will write out the resulting object name for the
294
commit to its standard output.
295
293
-And this is where we start using the `.git/HEAD` file. The `HEAD` file is
296
+And this is where we create the `.git/refs/heads/master` file. This file is
297
supposed to contain the reference to the top-of-tree, and since that's
298
exactly what `git-commit-tree` spits out, we can do this all with a simple
299
shell pipeline:
300
301
------------------------------------------------
299
-echo "Initial commit" | git-commit-tree $(git-write-tree) > .git/HEAD
302
+echo "Initial commit" | \
303
+ git-commit-tree $(git-write-tree) > .git/refs/heads/master
304
------------------------------------------------
305
306
which will say:
@@ -692,7 +696,9 @@ other point in the history than the current `HEAD`, you can do so by
696
just telling `git checkout` what the base of the checkout would be.
697
In other words, if you have an earlier tag or branch, you'd just do
698
695
- git checkout -b mybranch earlier-commit
699
+------------
700
+git checkout -b mybranch earlier-commit
701
+------------
702
703
and it would create the new branch `mybranch` at the earlier commit,
704
and check out the state at that time.
@@ -700,17 +706,29 @@ and check out the state at that time.
706
707
You can always just jump back to your original `master` branch by doing
708
703
- git checkout master
709
+------------
710
+git checkout master
711
+------------
712
713
(or any other branch-name, for that matter) and if you forget which
714
branch you happen to be on, a simple
715
708
- ls -l .git/HEAD
716
+------------
717
+ls -l .git/HEAD
718
+------------
719
710
-will tell you where it's pointing. To get the list of branches
711
-you have, you can say
720
+will tell you where it's pointing (Note that on platforms with bad or no
721
+symlink support, you have to execute
722
713
- git branch
723
+------------
724
+cat .git/HEAD
725
+------------
726
+
727
+instead). To get the list of branches you have, you can say
728
+
729
+------------
730
+git branch
731
+------------
732
733
which is nothing more than a simple script around `ls .git/refs/heads`.
734
There will be asterisk in front of the branch you are currently on.
@@ -718,7 +736,9 @@ There will be asterisk in front of the branch you are currently on.
736
Sometimes you may wish to create a new branch _without_ actually
737
checking it out and switching to it. If so, just use the command
738
721
- git branch <branchname> [startingpoint]
739
+------------
740
+git branch <branchname> [startingpoint]
741
+------------
742
743
which will simply _create_ the branch, but will not do anything further.
744
You can then later -- once you decide that you want to actually develop
@@ -844,7 +864,6 @@ $ git show-branch master mybranch
864
! [mybranch] Some work.
865
--
866
+ [master] Merged "mybranch" changes.
847
-+ [master~1] Some fun.
867
++ [mybranch] Some work.
868
------------------------------------------------
869
@@ -871,8 +890,10 @@ Now, let's pretend you are the one who did all the work in
890
to the `master` branch. Let's go back to `mybranch`, and run
891
resolve to get the "upstream changes" back to your branch.
892
874
- git checkout mybranch
875
- git resolve HEAD master "Merge upstream changes."
893
+------------
894
+git checkout mybranch
895
+git resolve HEAD master "Merge upstream changes."
896
+------------
897
898
This outputs something like this (the actual commit object names
899
would be different)
@@ -1088,13 +1109,17 @@ i.e. `<project>.git`. Let's create such a public repository for
1109
project `my-git`. After logging into the remote machine, create
1110
an empty directory:
1111
1091
- mkdir my-git.git
1112
+------------
1113
+mkdir my-git.git
1114
+------------
1115
1116
Then, make that directory into a GIT repository by running
1117
`git init-db`, but this time, since its name is not the usual
1118
`.git`, we do things slightly differently:
1119
1097
- GIT_DIR=my-git.git git-init-db
1120
+------------
1121
+GIT_DIR=my-git.git git-init-db
1122
+------------
1123
1124
Make sure this directory is available for others you want your
1125
changes to be pulled by via the transport of your choice. Also
@@ -1118,7 +1143,9 @@ Your "public repository" is now ready to accept your changes.
1143
Come back to the machine you have your private repository. From
1144
there, run this command:
1145
1121
- git push <public-host>:/path/to/my-git.git master
1146
+------------
1147
+git push <public-host>:/path/to/my-git.git master
1148
+------------
1149
1150
This synchronizes your public repository to match the named
1151
branch head (i.e. `master` in this case) and objects reachable
@@ -1128,7 +1155,9 @@ As a real example, this is how I update my public git
1155
repository. Kernel.org mirror network takes care of the
1156
propagation to other publicly visible machines:
1157
1131
- git push master.kernel.org:/pub/scm/git/git.git/
1158
+------------
1159
+git push master.kernel.org:/pub/scm/git/git.git/
1160
+------------
1161
1162
1163
Packing your repository
@@ -1141,7 +1170,9 @@ not so convenient to transport over the network. Since git objects are
1170
immutable once they are created, there is a way to optimize the
1171
storage by "packing them together". The command
1172
1144
- git repack
1173
+------------
1174
+git repack
1175
+------------
1176
1177
will do it for you. If you followed the tutorial examples, you
1178
would have accumulated about 17 objects in `.git/objects/??/`
@@ -1165,7 +1196,9 @@ Our programs are always perfect ;-).
1196
Once you have packed objects, you do not need to leave the
1197
unpacked objects that are contained in the pack file anymore.
1198
1168
- git prune-packed
1199
+------------
1200
+git prune-packed
1201
+------------
1202
1203
would remove them for you.
1204
[master] Merged "mybranch" changes.
new
+158
@@ -0,0 +1,160 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2005 Johannes Schindelin
4
+#
5
+
6
+test_description='Test git-rev-parse with different parent options'
7
+
8
+. ./test-lib.sh
9
+
10
+echo "Hello World" > hello
11
+echo "Silly example" > example
12
+
13
+git-update-index --add hello example
14
+
15
+test_expect_success 'blob' "test blob = \"$(git-cat-file -t 557db03)\""
16
+
17
+test_expect_success 'blob 557db03' "test \"Hello World\" = \"$(git-cat-file blob 557db03)\""
18
+
19
+echo "It's a new day for git" >>hello
20
+cat > diff.expect << EOF
21
+diff --git a/hello b/hello
22
+index 557db03..263414f 100644
23
+--- a/hello
24
++++ b/hello
25
+@@ -1 +1,2 @@
26
+ Hello World
27
++It's a new day for git
28
+EOF
29
+git-diff-files -p > diff.output
30
+test_expect_success 'git-diff-files -p' 'cmp diff.expect diff.output'
31
+git diff > diff.output
32
+test_expect_success 'git diff' 'cmp diff.expect diff.output'
33
+
34
+tree=$(git-write-tree 2>/dev/null)
35
+
36
+test_expect_success 'tree' "test 8988da15d077d4829fc51d8544c097def6644dbb = $tree"
37
+
38
+output="$(echo "Initial commit" | git-commit-tree $(git-write-tree) 2>&1 > .git/refs/heads/master)"
39
+
40
+test_expect_success 'commit' "test 'Committing initial tree 8988da15d077d4829fc51d8544c097def6644dbb' = \"$output\""
41
+
42
+git-diff-index -p HEAD > diff.output
43
+test_expect_success 'git-diff-index -p HEAD' 'cmp diff.expect diff.output'
44
+
45
+git diff HEAD > diff.output
46
+test_expect_success 'git diff HEAD' 'cmp diff.expect diff.output'
47
+
48
+#rm hello
49
+#test_expect_success 'git-read-tree --reset HEAD' "git-read-tree --reset HEAD ; test \"hello: needs update\" = \"$(git-update-index --refresh)\""
50
+
51
+cat > whatchanged.expect << EOF
52
+diff-tree VARIABLE (from root)
53
+Author: VARIABLE
54
+Date: VARIABLE
55
+
56
+ Initial commit
57
+
58
+diff --git a/example b/example
59
+new file mode 100644
60
+index 0000000..f24c74a
61
+--- /dev/null
62
++++ b/example
63
+@@ -0,0 +1 @@
64
++Silly example
65
+diff --git a/hello b/hello
66
+new file mode 100644
67
+index 0000000..557db03
68
+--- /dev/null
69
++++ b/hello
70
+@@ -0,0 +1 @@
71
++Hello World
72
+EOF
73
+
74
+git-whatchanged -p --root | \
75
+ sed -e "1s/^\(.\{10\}\).\{40\}/\1VARIABLE/" \
76
+ -e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \
77
+> whatchanged.output
78
+test_expect_success 'git-whatchanged -p --root' 'cmp whatchanged.expect whatchanged.output'
79
+
80
+git tag my-first-tag
81
+test_expect_success 'git tag my-first-tag' 'cmp .git/refs/heads/master .git/refs/tags/my-first-tag'
82
+
83
+# TODO: test git-clone
84
+
85
+git checkout -b mybranch
86
+test_expect_success 'git checkout -b mybranch' 'cmp .git/refs/heads/master .git/refs/heads/mybranch'
87
+
88
+cat > branch.expect <<EOF
89
+ master
90
+* mybranch
91
+EOF
92
+
93
+git branch > branch.output
94
+test_expect_success 'git branch' 'cmp branch.expect branch.output'
95
+
96
+git checkout mybranch
97
+echo "Work, work, work" >>hello
98
+git commit -m 'Some work.' hello
99
+
100
+git checkout master
101
+
102
+echo "Play, play, play" >>hello
103
+echo "Lots of fun" >>example
104
+git commit -m 'Some fun.' hello example
105
+
106
+test_expect_failure 'git resolve now fails' 'git resolve HEAD mybranch "Merge work in mybranch"'
107
+
108
+cat > hello << EOF
109
+Hello World
110
+It's a new day for git
111
+Play, play, play
112
+Work, work, work
113
+EOF
114
+
115
+git commit -m 'Merged "mybranch" changes.' hello
116
+
117
+cat > show-branch.expect << EOF
118
+* [master] Merged "mybranch" changes.
119
+ ! [mybranch] Some work.
120
+--
121
++ [master] Merged "mybranch" changes.
122
+EOF
123
+
124
+git show-branch master mybranch > show-branch.output
125
+test_expect_success 'git show-branch' 'cmp show-branch.expect show-branch.output'
126
+
127
+git checkout mybranch
128
+
129
+cat > resolve.expect << EOF
130
+Updating from VARIABLE to VARIABLE.
131
+ example | 1 +
132
+ hello | 1 +
133
+ 2 files changed, 2 insertions(+), 0 deletions(-)
134
+EOF
135
+
136
+git resolve HEAD master "Merge upstream changes." | \
137
+ sed -e "1s/[0-9a-f]\{40\}/VARIABLE/g" > resolve.output
138
+test_expect_success 'git resolve' 'cmp resolve.expect resolve.output'
139
+
140
+cat > show-branch2.expect << EOF
141
+! [master] Merged "mybranch" changes.
142
+ * [mybranch] Merged "mybranch" changes.
143
+--
144
+EOF
145
+
146
+git show-branch master mybranch > show-branch2.output
147
+test_expect_success 'git show-branch' 'cmp show-branch2.expect show-branch2.output'
148
+
149
+# TODO: test git fetch
150
+
151
+# TODO: test git push
152
+
153
+test_expect_success 'git repack' 'git repack'
154
+test_expect_success 'git prune-packed' 'git prune-packed'
155
+test_expect_failure '-> only packed objects' 'find -type f .git/objects/[0-9a-f][0-9a-f]'
156
+
157
+test_done
158
+