-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_utils_test.go
87 lines (73 loc) · 1.86 KB
/
git_utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"path/filepath"
"testing"
"time"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
)
var testSignature = object.Signature{
Name: "John Doe",
Email: "[email protected]",
When: time.Now(),
}
func TestGetWorktree(t *testing.T) {
path := CreateTempDirectory()
repo := InitRepo(path)
tree := GetWorktree(repo)
if tree == nil {
t.Fatalf("worktree was empty")
}
}
func TestCommitAll(t *testing.T) {
path := CreateTempDirectory()
repo := InitRepo(path)
filename := filepath.Join(path, "foo")
WriteFileWithContent(filename, "bar")
CommitAll(repo, "intial commit", &testSignature)
hasChanges := HasChanges(repo)
if hasChanges != false {
t.Fatalf("did not expect changes after commit")
}
cIter, err := repo.Log(&git.LogOptions{})
check(err)
commitCount := 0
err = cIter.ForEach(func(c *object.Commit) error {
commitCount++
return nil
})
check(err)
}
func TestEmptyRepositoryHasNoChanges(t *testing.T) {
path := CreateTempDirectory()
repo := InitRepo(path)
hasChanges := HasChanges(repo)
if hasChanges != false {
t.Fatalf("did not expect to have changes")
}
DeleteDirectory(path)
}
func TestRepositoryWithModifiedFilesHasChanges(t *testing.T) {
path := CreateTempDirectory()
repo := InitRepo(path)
filename := filepath.Join(path, "foo")
WriteFileWithContent(filename, "bar")
CommitAll(repo, "initial commit", &testSignature)
WriteFileWithContent(filename, "newbar")
hasChanges := HasChanges(repo)
if !hasChanges {
t.Fatalf("did expect to have changes")
}
DeleteDirectory(path)
}
func TestRepositoryWithUntrackedFilesHasChanges(t *testing.T) {
path := CreateTempDirectory()
repo := InitRepo(path)
filename := filepath.Join(path, "foo")
WriteFileWithContent(filename, "bar")
hasChanges := HasChanges(repo)
if hasChanges == false {
t.Fatalf("did expect to have changes")
}
DeleteDirectory(path)
}