forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository_common_test.go
More file actions
62 lines (50 loc) · 1.27 KB
/
repository_common_test.go
File metadata and controls
62 lines (50 loc) · 1.27 KB
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
package git
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/go-git/go-git/v6/plumbing"
formatcfg "github.com/go-git/go-git/v6/plumbing/format/config"
"github.com/go-git/go-git/v6/plumbing/object"
)
func forEachFormat(t *testing.T, fnT func(*testing.T, formatcfg.ObjectFormat)) {
formats := []struct {
name string
format formatcfg.ObjectFormat
}{
{name: "default"},
{name: "sha1", format: formatcfg.SHA1},
{name: "sha256", format: formatcfg.SHA256},
}
for _, f := range formats {
t.Run(f.name, func(t *testing.T) {
t.Parallel()
fnT(t, f.format)
})
}
}
func createCommit(t *testing.T, r *Repository) plumbing.Hash {
// Create a commit so there is a HEAD to check
wt, err := r.Worktree()
require.NoError(t, err)
f, err := wt.Filesystem.Create("foo.txt")
require.NoError(t, err)
defer f.Close()
_, err = f.Write([]byte("foo text"))
require.NoError(t, err)
_, err = wt.Add("foo.txt")
require.NoError(t, err)
author := object.Signature{
Name: "go-git",
Email: "go-git@fake.local",
When: time.Now(),
}
h, err := wt.Commit("test commit message", &CommitOptions{
All: true,
Author: &author,
Committer: &author,
AllowEmptyCommits: true,
})
require.NoError(t, err)
return h
}