Skip to content

Commit 1db9541

Browse files
committed
Add docs to Committing process
1 parent dfc790b commit 1db9541

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

pseudogit/Committing.groovy

+21-9
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ Tree root = new Tree([
1818
'dir' : d1,
1919
'dir2' : d2,
2020
'c.txt': b1])
21-
Commit c1 = new Commit(root)
21+
Commit c1 = new Commit('Initial commit', root)
2222
/**
23-
* This is an empty commit since it references the same tree, so it doesn't change the tree structure
23+
* This is an empty commit since it references the same tree, so it doesn't change the tree structure:
24+
* {@code git commit --allow-empty}
25+
*/
26+
Commit c2 = new Commit('Empty commit since it references the same tree as its parent', root, c1)
27+
/**
28+
* New files were added:
29+
*
30+
* echo 'Hello' > dir/a.txt
31+
* echo 'blah' > dir/d.txt
32+
* git add -u
2433
*/
25-
Commit c2 = new Commit(root, c1) // same tree, so it's an empty commit
26-
2734
d1 = new Tree([
2835
'a.txt': b1,
2936
'd.txt': new Blob('blah'.bytes)])
@@ -38,8 +45,13 @@ d1 = new Tree([
3845
* c.txt // new content!
3946
* </pre>
4047
*/
41-
Commit c3 = new Commit(new Tree([// new root
42-
'dir': d1,// new d1 with additional file
43-
'dir2': d2,
44-
'c.txt': new Blob("blah2".bytes)/*file content changed*/],
45-
), c2)
48+
root = new Tree([
49+
'dir' : d1,// new d1 with additional file
50+
'dir2' : d2,
51+
'c.txt': new Blob("blah2".bytes)/*additionally changed the file content*/],
52+
)
53+
/**
54+
* Now new commit references new Tree and prev commit becomes its parent:
55+
* git commit -m '...'
56+
*/
57+
Commit c3 = new Commit('New commit references new root Tree because it in turn references new sub-Tree', root, c2)

pseudogit/GitLog.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import objects.*
22

33
Tree t = new Tree()
4-
Commit commit = new Commit(t, new Commit(t, new Commit(t, new Commit())))
4+
Commit commit = new Commit('1st', t, new Commit('2nd', t, new Commit('3d', t, new Commit('4th', t))))
55

66
for(Commit c = commit; c.parent != null; c = c.parent)
77
println c

pseudogit/objects/Commit.groovy

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package objects
22

33
class Commit {
4+
String message
45
Tree root
56
Commit parent
67

7-
Commit(Tree root, Commit parent = null) {
8+
Commit(String message, Tree root, Commit parent = null) {
9+
this.message = message
810
this.root = root
911
this.parent = parent
1012
}

0 commit comments

Comments
 (0)