I'm using go-git through a project and faced this error: [...]: author field is required.
In my Git configuration I do not specify the user.email field; here is the excerpt:
1 │ [user]
2 │ name = Edoardo ...
3 │ useConfigOnly = true
This configuration forces to set user.email setting for each repo.
I went on debugging this:
- the error is triggered by
|
if o.Author == nil { |
|
return ErrMissingAuthor |
|
} |
in the
|
func (o *CommitOptions) loadConfigAuthorAndCommitter(r *Repository) error { |
function
loadConfigAuthorAndCommitter is called by CommitOptions.Validate(), executed as first step in Worktree.Commit()
|
func (w *Worktree) Commit(msg string, opts *CommitOptions) (plumbing.Hash, error) { |
|
if err := opts.Validate(w.r); err != nil { |
|
return plumbing.ZeroHash, err |
|
} |
loadConfigAuthorAndCommitter function first step is to load the system configurations:
|
cfg, err := r.ConfigScoped(config.SystemScope) |
This behaviour seems to contradicts the git documentation about Environment variables. Under Committing in Git Internals Environment variables is written:
The final creation of a Git commit object is usually done by git-commit-tree, which uses these environment variables as its primary source of information, falling back to configuration values only if these aren’t present.
(Incidentally these variables include GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL, which should override any file based configuration and I tried using to overcome the mentioned error).
Expected behaviour: go-git follows git behaviour and respects environment variables at commit time, not relying only on file based configurations
By looking at other issues I noticed aligning with what git does is important, so I would contribute a PR to change this behaviour by loading specified environment variables in loadConfigAuthorAndCommitter before system configuration and configuring author and committer accordingly to what git docs say.
I'm using
go-gitthrough a project and faced this error:[...]: author field is required.In my Git configuration I do not specify the
user.emailfield; here is the excerpt:This configuration forces to set
user.emailsetting for each repo.I went on debugging this:
go-git/options.go
Lines 505 to 507 in 99457e5
in the
go-git/options.go
Line 475 in 99457e5
function
loadConfigAuthorAndCommitteris called byCommitOptions.Validate(), executed as first step inWorktree.Commit()go-git/worktree_commit.go
Lines 21 to 24 in 99457e5
loadConfigAuthorAndCommitterfunction first step is to load the system configurations:go-git/options.go
Line 476 in 99457e5
This behaviour seems to contradicts the
gitdocumentation about Environment variables. UnderCommittingin Git Internals Environment variables is written:(Incidentally these variables include
GIT_AUTHOR_NAMEandGIT_AUTHOR_EMAIL, which should override any file based configuration and I tried using to overcome the mentioned error).Expected behaviour:
go-gitfollows git behaviour and respects environment variables at commit time, not relying only on file based configurationsBy looking at other issues I noticed aligning with what git does is important, so I would contribute a PR to change this behaviour by loading specified environment variables in
loadConfigAuthorAndCommitterbefore system configuration and configuring author and committer accordingly to what git docs say.