diff options
author | John Cai <jcai@gitlab.com> | 2022-01-03 15:40:28 -0500 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2022-01-03 15:49:31 -0500 |
commit | 5882d60fb7ccd4cfc0fe69286aa96e198c9d1eb0 (patch) | |
tree | a310e673d288758403d0e99086cec6f801480d3b /options.go | |
parent | f0b111ab70e4e90013658b0835929b2083902017 (diff) | |
download | go-git-5882d60fb7ccd4cfc0fe69286aa96e198c9d1eb0.tar.gz |
Add Amend option to CommitOptions
Adds an Amend option to CommitOptions that behaves like git --amend.
This change includes modifications to the Validate function to disallow
a Commit call with both Amend and either Parents or All enabled.
Diffstat (limited to 'options.go')
-rw-r--r-- | options.go | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -471,10 +471,21 @@ type CommitOptions struct { // commit will not be signed. The private key must be present and already // decrypted. SignKey *openpgp.Entity + // Amend will create a new commit object and replace the commit that HEAD currently + // points to. Cannot be used with All nor Parents. + Amend bool } // Validate validates the fields and sets the default values. func (o *CommitOptions) Validate(r *Repository) error { + if o.All && o.Amend { + return errors.New("all and amend cannot be used together") + } + + if o.Amend && len(o.Parents) > 0 { + return errors.New("parents cannot be used with amend") + } + if o.Author == nil { if err := o.loadConfigAuthorAndCommitter(r); err != nil { return err |