diff options
author | Paulo Gomes <pjbgf@linux.com> | 2022-12-03 16:34:35 +0000 |
---|---|---|
committer | Paulo Gomes <pjbgf@linux.com> | 2022-12-03 16:34:35 +0000 |
commit | a513415283c4628259c016587858fe56d7b0fa13 (patch) | |
tree | c39b970b1403d10693795ad6d61dd1ea59db4a2d /options.go | |
parent | 3e07c5030b4e3b2fcbcb461f9f6b23212f978335 (diff) | |
download | go-git-a513415283c4628259c016587858fe56d7b0fa13.tar.gz |
Return error instead of creating empty commits
BuildTree now returns an ErrEmptyCommit error, when there are no
changes to be committed. This can be opted-out via
CommitOptions.AllowEmptyCommits.
This is a breaking change which enables applications to detect when
empty commits are to be created.
Some instances in which this can occur is when the fs (e.g. `billy/osfs`)
make changes to the underlying files, causing a conflict between what
the previous Git worktree state was, and the current state. Changes to
the fs implementations are orthogonal to this, and will be dealt with
separately.
The new behaviour aligns with the Git CLI, in which empty commits
returns the error message: 'nothing to commit, working tree clean'.
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'options.go')
-rw-r--r-- | options.go | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -458,6 +458,10 @@ type CommitOptions struct { // All automatically stage files that have been modified and deleted, but // new files you have not told Git about are not affected. All bool + // AllowEmptyCommits enable empty commits to be created. An empty commit + // is when no changes to the tree were made, but a new commit message is + // provided. The default behavior is false, which results in ErrEmptyCommit. + AllowEmptyCommits bool // Author is the author's signature of the commit. If Author is empty the // Name and Email is read from the config, and time.Now it's used as When. Author *object.Signature |