Environment variables are not loaded for commit action
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 = trueThis configuration forces to set user.email setting for each repo.
I went on debugging this:
- the error is triggered by https://github.com/go-git/go-git/blob/99457e570d34320b12fb4fcd0f054f3d0b1d3eec/options.go#L505-L507 in the https://github.com/go-git/go-git/blob/99457e570d34320b12fb4fcd0f054f3d0b1d3eec/options.go#L475 function
loadConfigAuthorAndCommitteris called byCommitOptions.Validate(), executed as first step inWorktree.Commit()https://github.com/go-git/go-git/blob/99457e570d34320b12fb4fcd0f054f3d0b1d3eec/worktree_commit.go#L21-L24loadConfigAuthorAndCommitterfunction first step is to load the system configurations: https://github.com/go-git/go-git/blob/99457e570d34320b12fb4fcd0f054f3d0b1d3eec/options.go#L476
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.
Source: go-git/go-git