Skip to content

Commit b8de280

Browse files
committed
handle git commit author signature
1 parent 021b504 commit b8de280

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

git/embed.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Embed(
4545
mergedTreeHash := mergeTrees(ctx, repo, branchCommit.TreeHash, embeddingsTreeHash, allowOverride)
4646

4747
// create a commit
48-
opts := git.CommitOptions{}
48+
opts := git.CommitOptions{Author: GetAuthor()}
4949
must.NoError(ctx, opts.Validate(repo))
5050
commit := object.Commit{
5151
Author: *opts.Author,

git/embed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ func populate(ctx context.Context, r *git.Repository, nonce string, createBranch
9191
must.NoError(ctx, err)
9292
_, err = w.Add(nonce)
9393
must.NoError(ctx, err)
94-
_, err = w.Commit(nonce, &git.CommitOptions{})
94+
_, err = w.Commit(nonce, &git.CommitOptions{Author: GetAuthor()})
9595
must.NoError(ctx, err)
9696
}

git/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func Add(ctx context.Context, wt *Tree, path string) {
128128
}
129129

130130
func Commit(ctx context.Context, wt *Tree, msg string) {
131-
if _, err := wt.Commit(msg, &git.CommitOptions{}); err != nil {
131+
if _, err := wt.Commit(msg, &git.CommitOptions{Author: GetAuthor()}); err != nil {
132132
must.Panic(ctx, err)
133133
}
134134
}

git/signature.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package git
2+
3+
import (
4+
"sync"
5+
"time"
6+
7+
"github.com/go-git/go-git/v5/plumbing/object"
8+
)
9+
10+
var (
11+
authorLk sync.Mutex
12+
author *object.Signature = &object.Signature{
13+
Name: "gov4git",
14+
Email: "no-reply@gov4git.xyz",
15+
}
16+
)
17+
18+
func SetAuthor(name string, email string) {
19+
authorLk.Lock()
20+
defer authorLk.Unlock()
21+
author = &object.Signature{
22+
Name: name,
23+
Email: email,
24+
When: time.Now(),
25+
}
26+
}
27+
28+
func GetAuthor() *object.Signature {
29+
authorLk.Lock()
30+
defer authorLk.Unlock()
31+
return author
32+
}

0 commit comments

Comments
 (0)