Skip to content

Commit

Permalink
Commit: Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vHanda committed Apr 29, 2022
1 parent fa9f4f3 commit c96cbda
Show file tree
Hide file tree
Showing 31 changed files with 84 additions and 5 deletions.
35 changes: 30 additions & 5 deletions commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func Test_NoChanges(t *testing.T) {
err := commit(repoPath)
assert.NilError(t, err)

// Get the head commit
r, err := git.PlainOpen(repoPath)
assert.NilError(t, err)

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

// Get the head commit
r, err := git.PlainOpen(repoPath)
assert.NilError(t, err)

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

func Test_OneFileChange(t *testing.T) {
repoPath := prepareFixture(t, "one_file_change")

err := commit(repoPath)
assert.NilError(t, err)

r, err := git.PlainOpen(repoPath)
assert.NilError(t, err)

head, err := r.Head()
assert.NilError(t, err)

assert.Assert(t, head.Hash() != plumbing.NewHash("28cc969d97ddb7640f5e1428bbc8f2947d1ffd57"))
}

func Test_MultipleFileChange(t *testing.T) {
repoPath := prepareFixture(t, "multiple_file_change")

err := commit(repoPath)
assert.NilError(t, err)

r, err := git.PlainOpen(repoPath)
assert.NilError(t, err)

head, err := r.Head()
assert.NilError(t, err)

assert.Assert(t, head.Hash() != plumbing.NewHash("7058b6b292ee3d1382670334b5f29570a1117ef1"))
}

// TODO
// * One file changes
// * Multiple files changed
// * A file in a subdirectory changed
// * The commit message is how we want it
24 changes: 24 additions & 0 deletions testdata/multiple_file_change/.gitted/COMMIT_EDITMSG
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Add another file in a subdir
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
# new file: dirA/2.md
#
# Changes not staged for commit:
# modified: 1.md
#
# Untracked files:
# dirB/
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/dirA/2.md b/dirA/2.md
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/dirA/2.md
@@ -0,0 +1 @@
+2
1 change: 1 addition & 0 deletions testdata/multiple_file_change/.gitted/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
Empty file.
5 changes: 5 additions & 0 deletions testdata/multiple_file_change/.gitted/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
1 change: 1 addition & 0 deletions testdata/multiple_file_change/.gitted/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file added testdata/multiple_file_change/.gitted/index
Binary file not shown.
1 change: 1 addition & 0 deletions testdata/multiple_file_change/.gitted/info/refs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7058b6b292ee3d1382670334b5f29570a1117ef1 refs/heads/master
1 change: 1 addition & 0 deletions testdata/multiple_file_change/.gitted/logs/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
28cc969d97ddb7640f5e1428bbc8f2947d1ffd57 7058b6b292ee3d1382670334b5f29570a1117ef1 Vishesh Handa <[email protected]> 1651236187 +0200 commit: Add another file in a subdir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
28cc969d97ddb7640f5e1428bbc8f2947d1ffd57 7058b6b292ee3d1382670334b5f29570a1117ef1 Vishesh Handa <[email protected]> 1651236187 +0200 commit: Add another file in a subdir
Binary file not shown.
2 changes: 2 additions & 0 deletions testdata/multiple_file_change/.gitted/objects/info/packs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
P pack-8bd23478afc278bb9d444418db77fa24b756f8b8.pack

Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions testdata/multiple_file_change/.gitted/packed-refs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pack-refs with: peeled fully-peeled sorted
7058b6b292ee3d1382670334b5f29570a1117ef1 refs/heads/master
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions testdata/multiple_file_change/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
Foo
1 change: 1 addition & 0 deletions testdata/multiple_file_change/dirA/2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
2 changes: 2 additions & 0 deletions testdata/multiple_file_change/dirB/3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3
4
1 change: 1 addition & 0 deletions testdata/one_file_change/.gitted/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
Empty file.
5 changes: 5 additions & 0 deletions testdata/one_file_change/.gitted/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
1 change: 1 addition & 0 deletions testdata/one_file_change/.gitted/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file added testdata/one_file_change/.gitted/index
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions testdata/one_file_change/.gitted/packed-refs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pack-refs with: peeled fully-peeled sorted
28cc969d97ddb7640f5e1428bbc8f2947d1ffd57 refs/heads/master
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions testdata/one_file_change/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
2

0 comments on commit c96cbda

Please sign in to comment.