extrawurst / gitui

Blazing 💥 fast terminal-ui for git written in rust 🦀
MIT License
17.81k stars 541 forks source link

Respect git environment variables when committing #1622

Open Lillecarl opened 1 year ago

Lillecarl commented 1 year ago

Describe the bug According to https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables git uses environment variables as primary source for name and email configuration.

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.

To Reproduce Steps to reproduce the behavior:

  1. Set:
    export GIT_COMMITTER_NAME="Your Name"
    export GIT_AUTHOR_EMAIL="git@example.com"
    export GIT_COMMITTER_EMAIL="git@example.com"
    export GIT_AUTHOR_NAME=Your Name"
    export EMAIL="git@example.com"
  2. Commit something with git commit
  3. See in the logs that the env var values were used
  4. Commit something with gitui
  5. See in the logs that the git configured user was used instead.

Expected behavior As git docs explains, environment variables should be used as primary source for the git commit command. If the variables are not configured we fall back to git configuration values.

Screenshots Not applicable

Context (please complete the following information):

Additional context Even though it's suboptimal it's quite common that humans share users on certain machines, when working with Git it's nice to be able to send GIT_* and EMAIL over SSH to Git and gitui 😄 Workaround: Stage with gitui, commit with git (Same workaround as signing commits).

extrawurst commented 1 year ago

I think libgit2 does not support that yet: https://github.com/libgit2/libgit2/issues/6182

Lillecarl commented 1 year ago

@extrawurst I've seen that there are other blockers like GPG signing not being supported in libgit2 (ish, more complex). This would then be another thing to pile on top of "dependency not complete". I know your stance is to never shell out. Would you consider exempting commiting and potentially other one-off operations that aren't performance sensitive for a more feature-complete application?

If so, I'd like to accept the challenge, going from reading about Rust on a daily basis to actually writing some.

Thanks for the quick turnaround and thanks for the great project! 😄

extrawurst commented 10 months ago

@Lillecarl can you test if the env vars are now respected in the latest release?

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had any activity half a year. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

ZNielsen commented 2 weeks ago

I am seeing gitui fail to use $EMAIL. In my case, user.email is not set, so I would expect $EMAIL to be used instead.

version: gitui nightly 2024-06-13 ()

To clarify, I don't think the initial description of when $EMAIL is used is correct. Quoting from that linked page on environment variables:

EMAIL is the fallback email address in case the user.email configuration value isn’t set. If this isn’t set, Git falls back to the system user and host names.

So I would expect precedence order as $GIT_* > config (user.email) > $EMAIL