Skip to content

Commit c96cbda

Browse files
committed
Commit: Add more tests
1 parent fa9f4f3 commit c96cbda

31 files changed

+84
-5
lines changed

commit_test.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func Test_NoChanges(t *testing.T) {
3333
err := commit(repoPath)
3434
assert.NilError(t, err)
3535

36-
// Get the head commit
3736
r, err := git.PlainOpen(repoPath)
3837
assert.NilError(t, err)
3938

@@ -49,7 +48,6 @@ func Test_NewFile(t *testing.T) {
4948
err := commit(repoPath)
5049
assert.NilError(t, err)
5150

52-
// Get the head commit
5351
r, err := git.PlainOpen(repoPath)
5452
assert.NilError(t, err)
5553

@@ -59,8 +57,35 @@ func Test_NewFile(t *testing.T) {
5957
assert.Assert(t, head.Hash() != plumbing.NewHash("28cc969d97ddb7640f5e1428bbc8f2947d1ffd57"))
6058
}
6159

60+
func Test_OneFileChange(t *testing.T) {
61+
repoPath := prepareFixture(t, "one_file_change")
62+
63+
err := commit(repoPath)
64+
assert.NilError(t, err)
65+
66+
r, err := git.PlainOpen(repoPath)
67+
assert.NilError(t, err)
68+
69+
head, err := r.Head()
70+
assert.NilError(t, err)
71+
72+
assert.Assert(t, head.Hash() != plumbing.NewHash("28cc969d97ddb7640f5e1428bbc8f2947d1ffd57"))
73+
}
74+
75+
func Test_MultipleFileChange(t *testing.T) {
76+
repoPath := prepareFixture(t, "multiple_file_change")
77+
78+
err := commit(repoPath)
79+
assert.NilError(t, err)
80+
81+
r, err := git.PlainOpen(repoPath)
82+
assert.NilError(t, err)
83+
84+
head, err := r.Head()
85+
assert.NilError(t, err)
86+
87+
assert.Assert(t, head.Hash() != plumbing.NewHash("7058b6b292ee3d1382670334b5f29570a1117ef1"))
88+
}
89+
6290
// TODO
63-
// * One file changes
64-
// * Multiple files changed
65-
// * A file in a subdirectory changed
6691
// * The commit message is how we want it
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Add another file in a subdir
2+
# Please enter the commit message for your changes. Lines starting
3+
# with '#' will be ignored, and an empty message aborts the commit.
4+
#
5+
# On branch master
6+
# Changes to be committed:
7+
# new file: dirA/2.md
8+
#
9+
# Changes not staged for commit:
10+
# modified: 1.md
11+
#
12+
# Untracked files:
13+
# dirB/
14+
#
15+
# ------------------------ >8 ------------------------
16+
# Do not modify or remove the line above.
17+
# Everything below it will be ignored.
18+
diff --git a/dirA/2.md b/dirA/2.md
19+
new file mode 100644
20+
index 0000000..0cfbf08
21+
--- /dev/null
22+
+++ b/dirA/2.md
23+
@@ -0,0 +1 @@
24+
+2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master

testdata/multiple_file_change/.gitted/branches/.gitignore

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
238 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7058b6b292ee3d1382670334b5f29570a1117ef1 refs/heads/master
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
28cc969d97ddb7640f5e1428bbc8f2947d1ffd57 7058b6b292ee3d1382670334b5f29570a1117ef1 Vishesh Handa <[email protected]> 1651236187 +0200 commit: Add another file in a subdir
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
28cc969d97ddb7640f5e1428bbc8f2947d1ffd57 7058b6b292ee3d1382670334b5f29570a1117ef1 Vishesh Handa <[email protected]> 1651236187 +0200 commit: Add another file in a subdir

0 commit comments

Comments
 (0)