Skip to content

Commit 2ae6c70

Browse files
dschoJunio C Hamano
authored andcommitted
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>
1 parent 2573808 commit 2ae6c70

File tree

2 files changed

+212
-19
lines changed

2 files changed

+212
-19
lines changed

Documentation/tutorial.txt

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ your new project. You will now have a `.git` directory, and you can
5252
inspect that with `ls`. For your new empty project, it should show you
5353
three entries, among other things:
5454

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")
5658
+
5759
Don't worry about the fact that the file that the `HEAD` link points to
5860
doesn't even exist yet -- you haven't created the commit that will
@@ -228,6 +230,7 @@ which will spit out
228230

229231
------------
230232
diff --git a/hello b/hello
233+
index 557db03..263414f 100644
231234
--- a/hello
232235
+++ b/hello
233236
@@ -1 +1,2 @@
@@ -290,13 +293,14 @@ also wants to get a commit message
290293
on its standard input, and it will write out the resulting object name for the
291294
commit to its standard output.
292295

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
294297
supposed to contain the reference to the top-of-tree, and since that's
295298
exactly what `git-commit-tree` spits out, we can do this all with a simple
296299
shell pipeline:
297300

298301
------------------------------------------------
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
300304
------------------------------------------------
301305

302306
which will say:
@@ -692,33 +696,49 @@ other point in the history than the current `HEAD`, you can do so by
692696
just telling `git checkout` what the base of the checkout would be.
693697
In other words, if you have an earlier tag or branch, you'd just do
694698

695-
git checkout -b mybranch earlier-commit
699+
------------
700+
git checkout -b mybranch earlier-commit
701+
------------
696702

697703
and it would create the new branch `mybranch` at the earlier commit,
698704
and check out the state at that time.
699705
================================================
700706

701707
You can always just jump back to your original `master` branch by doing
702708

703-
git checkout master
709+
------------
710+
git checkout master
711+
------------
704712

705713
(or any other branch-name, for that matter) and if you forget which
706714
branch you happen to be on, a simple
707715

708-
ls -l .git/HEAD
716+
------------
717+
ls -l .git/HEAD
718+
------------
709719

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
712722

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+
------------
714732

715733
which is nothing more than a simple script around `ls .git/refs/heads`.
716734
There will be asterisk in front of the branch you are currently on.
717735

718736
Sometimes you may wish to create a new branch _without_ actually
719737
checking it out and switching to it. If so, just use the command
720738

721-
git branch <branchname> [startingpoint]
739+
------------
740+
git branch <branchname> [startingpoint]
741+
------------
722742

723743
which will simply _create_ the branch, but will not do anything further.
724744
You can then later -- once you decide that you want to actually develop
@@ -844,7 +864,6 @@ $ git show-branch master mybranch
844864
! [mybranch] Some work.
845865
--
846866
+ [master] Merged "mybranch" changes.
847-
+ [master~1] Some fun.
848867
++ [mybranch] Some work.
849868
------------------------------------------------
850869

@@ -871,8 +890,10 @@ Now, let's pretend you are the one who did all the work in
871890
to the `master` branch. Let's go back to `mybranch`, and run
872891
resolve to get the "upstream changes" back to your branch.
873892

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+
------------
876897

877898
This outputs something like this (the actual commit object names
878899
would be different)
@@ -1088,13 +1109,17 @@ i.e. `<project>.git`. Let's create such a public repository for
10881109
project `my-git`. After logging into the remote machine, create
10891110
an empty directory:
10901111

1091-
mkdir my-git.git
1112+
------------
1113+
mkdir my-git.git
1114+
------------
10921115

10931116
Then, make that directory into a GIT repository by running
10941117
`git init-db`, but this time, since its name is not the usual
10951118
`.git`, we do things slightly differently:
10961119

1097-
GIT_DIR=my-git.git git-init-db
1120+
------------
1121+
GIT_DIR=my-git.git git-init-db
1122+
------------
10981123

10991124
Make sure this directory is available for others you want your
11001125
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.
11181143
Come back to the machine you have your private repository. From
11191144
there, run this command:
11201145

1121-
git push <public-host>:/path/to/my-git.git master
1146+
------------
1147+
git push <public-host>:/path/to/my-git.git master
1148+
------------
11221149

11231150
This synchronizes your public repository to match the named
11241151
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
11281155
repository. Kernel.org mirror network takes care of the
11291156
propagation to other publicly visible machines:
11301157

1131-
git push master.kernel.org:/pub/scm/git/git.git/
1158+
------------
1159+
git push master.kernel.org:/pub/scm/git/git.git/
1160+
------------
11321161

11331162

11341163
Packing your repository
@@ -1141,7 +1170,9 @@ not so convenient to transport over the network. Since git objects are
11411170
immutable once they are created, there is a way to optimize the
11421171
storage by "packing them together". The command
11431172

1144-
git repack
1173+
------------
1174+
git repack
1175+
------------
11451176

11461177
will do it for you. If you followed the tutorial examples, you
11471178
would have accumulated about 17 objects in `.git/objects/??/`
@@ -1165,7 +1196,9 @@ Our programs are always perfect ;-).
11651196
Once you have packed objects, you do not need to leave the
11661197
unpacked objects that are contained in the pack file anymore.
11671198

1168-
git prune-packed
1199+
------------
1200+
git prune-packed
1201+
------------
11691202

11701203
would remove them for you.
11711204

t/t1200-tutorial.sh

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
++ [mybranch] Some work.
123+
EOF
124+
125+
git show-branch master mybranch > show-branch.output
126+
test_expect_success 'git show-branch' 'cmp show-branch.expect show-branch.output'
127+
128+
git checkout mybranch
129+
130+
cat > resolve.expect << EOF
131+
Updating from VARIABLE to VARIABLE.
132+
example | 1 +
133+
hello | 1 +
134+
2 files changed, 2 insertions(+), 0 deletions(-)
135+
EOF
136+
137+
git resolve HEAD master "Merge upstream changes." | \
138+
sed -e "1s/[0-9a-f]\{40\}/VARIABLE/g" > resolve.output
139+
test_expect_success 'git resolve' 'cmp resolve.expect resolve.output'
140+
141+
cat > show-branch2.expect << EOF
142+
! [master] Merged "mybranch" changes.
143+
* [mybranch] Merged "mybranch" changes.
144+
--
145+
++ [master] Merged "mybranch" changes.
146+
EOF
147+
148+
git show-branch master mybranch > show-branch2.output
149+
test_expect_success 'git show-branch' 'cmp show-branch2.expect show-branch2.output'
150+
151+
# TODO: test git fetch
152+
153+
# TODO: test git push
154+
155+
test_expect_success 'git repack' 'git repack'
156+
test_expect_success 'git prune-packed' 'git prune-packed'
157+
test_expect_failure '-> only packed objects' 'find -type f .git/objects/[0-9a-f][0-9a-f]'
158+
159+
test_done
160+

0 commit comments

Comments
 (0)