@@ -107,14 +107,30 @@ func AddChanges(repoPath string, all bool, files ...string) error {
107
107
return err
108
108
}
109
109
110
- // CommitChanges commits local changes with given message and author.
111
- func CommitChanges (repoPath , message string , author * Signature ) error {
112
- cmd := NewCommand ("commit" , "-m" , message )
113
- if author != nil {
114
- cmd .AddArguments (fmt .Sprintf ("--author='%s <%s>'" , author .Name , author .Email ))
110
+ type CommitChangesOptions struct {
111
+ Committer * Signature
112
+ Author * Signature
113
+ Message string
114
+ }
115
+
116
+ // CommitChanges commits local changes with given committer, author and message.
117
+ // If author is nil, it will be the same as committer.
118
+ func CommitChanges (repoPath string , opts CommitChangesOptions ) error {
119
+ cmd := NewCommand ()
120
+ if opts .Committer != nil {
121
+ cmd .AddArguments ("-c" , "user.name=" + opts .Committer .Name , "-c" , "user.email=" + opts .Committer .Email )
115
122
}
116
- _ , err := cmd .RunInDir ( repoPath )
123
+ cmd .AddArguments ( "commit" )
117
124
125
+ if opts .Author == nil {
126
+ opts .Author = opts .Committer
127
+ }
128
+ if opts .Author != nil {
129
+ cmd .AddArguments (fmt .Sprintf ("--author='%s <%s>'" , opts .Author .Name , opts .Author .Email ))
130
+ }
131
+ cmd .AddArguments ("-m" , opts .Message )
132
+
133
+ _ , err := cmd .RunInDir (repoPath )
118
134
// No stderr but exit status 1 means nothing to commit.
119
135
if err != nil && err .Error () == "exit status 1" {
120
136
return nil
0 commit comments