Closed bemyak closed 1 year ago
Could you confirm if the committer (not author) for rewritten commits is respecting GIT_COMMITTER_NAME
/ GIT_COMMITTER_EMAIL
or not? That'll confirm where the bug is.
user.signingkey
configured_signing_key
set_signing_key
user.signingkey
get_default_key
git_committer_info(IDENT_STRICT | IDENT_NO_DATE);
From looking at this, it seems like git2 isn't reading GIT_COMMITTER_NAME / GIT_COMMITER_EMAIL but should be reading the configs in the correct order. The way to confirm this is for any other place we read the repo signature and see if its wrong. We generate a new signature for the committer when we rewrite history, using the repo's signature.
Given the setup I described in the reproduction steps, the final result of running git sync
(as shown by git log --format=full --show-signature
) is:
signature: email1@email.com
Author: email3@email.com
Commit: email2@email.com
So, it looks like the author field respects GIT_AUTHOR_EMAIL
and GIT_AUTHOR_NAME
The committer is taken from the git config file (~/.gitconfig
) and the env vars GIT_COMMITTER_EMAIL
and GIT_COMMITTER_NAME
are ignored
And the signature is the first signature from the list, this email isn't used anywhere in git configs.
The committer is taken from the git config file (~/.gitconfig) and the env vars GIT_COMMITTER_EMAIL and GIT_COMMITTER_NAME are ignored
Can you open a bug about this?
And the signature is the first signature from the list, this email isn't used anywhere in git configs.
The fact that the signature and committer are using different emails is bizarre as they should be coming from the same source.
Everytime I've used gpg, it has been an abysmal failure to the point I don't touch it. I wrote all of this code blind, just reading git's source code. Would you be able to help out in debugging this?
To use a local copy of git2-ext
with git-stack
, you can add the following to Cargo.toml
:
[patch.crates-io]
git2-ext = { path = "<put path in here>" }
I came up with a partial fix in the PR linked above. Now the key matches the committer, at least.
However, the committer field still doesn't respect the env variables. I skimmed through the code and found only one suspicion line here, where committer is set to an author, but it is an irrelevant part of the code.
In which project can the issue be?
However, the committer field still doesn't respect the env variables.
The call that is a problem is repo.signature()
as libgit2 is returning the bad information. The way I would fix this is add a new signature
function to git2-ext that checks the env variables and then falls back to repo.signature()
. It'll need to mimic what git does when only one or the other env variable is set. It should also read the env using std::env::var_os
as std::env_var
can panic.
BTW, have you considered switching to gitoxide? This case seems to be handled correctly there. (Not asking to rewrite the entire set of gitext tools to gitoxide, just wondering :slightly_smiling_face: )
I've been in talks with Byron: https://github.com/Byron/gitoxide/issues/311.
std::env_var
can panic
According to the docs, it should not. It returns an error if the var contains an invalid Unicode. So I'll use it as we are not handling non-Unicode symbols elsewhere.
Good call. I got it mixed up with std::env::args
(love that inconsistency)
I did one more fix: https://github.com/gitext-rs/git2-ext/pull/28
Now the signature is correct, but the committer is not :)
Please complete the following tasks
Description
Git-stack picks up the first GPG key to sign commits.
I have a set of GPG keys set up in the following order (
gpg --list-secret-keys --keyid-format LONG
):old-work@email.com
(an email left from the previous job, not mentioned in any git configs or env vars)private@email.com
work@email.com
Whenever I run
git sync
, it always tries to sign commits with the first key from the list (i.e.old-work@email.com
).Version
0.10.10
Steps to reproduce
gpg --full-generate-key
multiple times to create a couple of GPG keys. To make testing easier, I recommend setting different passphrases for them.email1@email.com
email2@email.com
email3@email.com
email2@email.com
:git config --global user.email "email2@email.com"
git config --global commit.gpgSign true
email3@email.com
:export GIT_AUTHOR_EMAIL=email3@email.com
export GIT_COMMITTER_EMAIL=email3@email.com
git sync
in any repo that will require rebasing and resigning commitsActual Behaviour
Git-sync signs commits with
email1@email.com
keyExpected Behaviour
Git-sync should pick up a key in the following priority:
GIT_COMMITTER_EMAIL
~/.config/git/config
~/.gitconfig
Debug Output
No response