1
0
mirror of https://github.com/go-gitea/git.git synced 2026-02-05 06:45:03 +01:00

CommitChanges: allow set both committer and author

This commit is contained in:
Unknwon
2016-08-27 13:37:00 -07:00
parent 7b206b529a
commit 0a18ab0f2b
2 changed files with 24 additions and 8 deletions

View File

@@ -107,14 +107,30 @@ func AddChanges(repoPath string, all bool, files ...string) error {
return err
}
// CommitChanges commits local changes with given message and author.
func CommitChanges(repoPath, message string, author *Signature) error {
cmd := NewCommand("commit", "-m", message)
if author != nil {
cmd.AddArguments(fmt.Sprintf("--author='%s <%s>'", author.Name, author.Email))
}
_, err := cmd.RunInDir(repoPath)
type CommitChangesOptions struct {
Committer *Signature
Author *Signature
Message string
}
// CommitChanges commits local changes with given committer, author and message.
// If author is nil, it will be the same as committer.
func CommitChanges(repoPath string, opts CommitChangesOptions) error {
cmd := NewCommand()
if opts.Committer != nil {
cmd.AddArguments("-c", "user.name="+opts.Committer.Name, "-c", "user.email="+opts.Committer.Email)
}
cmd.AddArguments("commit")
if opts.Author == nil {
opts.Author = opts.Committer
}
if opts.Author != nil {
cmd.AddArguments(fmt.Sprintf("--author='%s <%s>'", opts.Author.Name, opts.Author.Email))
}
cmd.AddArguments("-m", opts.Message)
_, err := cmd.RunInDir(repoPath)
// No stderr but exit status 1 means nothing to commit.
if err != nil && err.Error() == "exit status 1" {
return nil

2
git.go
View File

@@ -10,7 +10,7 @@ import (
"time"
)
const _VERSION = "0.3.8"
const _VERSION = "0.4.0"
func Version() string {
return _VERSION