vmware-archive / git-author

An easy way to setup multiple authors based on `git commit --template`. It depends on git-together
BSD 3-Clause "New" or "Revised" License
30 stars 11 forks source link

git author pulls author info both global and local git configs when using commit aliases #22

Closed cwlbraa closed 4 years ago

cwlbraa commented 5 years ago

This took the CAPI team an eternity to track down, but when using git-author , we've noticed some inconsistency in whose names get applied to a commit if folks use aliases in combination with raw git with. Some folks here have reflexes around ci for "commit" and with for author, and it's been causing lots of havoc.

The bug is basically this:

git config --file ~/.gitconfig --add git-together.aliases ci
git config --file ~/.gitconfig --add alias.ci commit --verbose
git with cb am
git author cs sj
git ci
git show --format=full
commit 7fff7d131ea08e5c58fdb4c60aa5caacd9780947 (HEAD -> master)
Author: Connor Braa <cbraa@pivotal.io>
Commit: Andres Medina <amedina@pivotal.io>

    wat

    Co-authored-by: Chris Selzo <cselzo@pivotal.io>
    Co-authored-by: Sannidhi Jalukar <sjalukar@pivotal.io>

The git with command sets the local repo's .git/config file's git-together.active, and git author (correctly) sets the same in ${HOME}/.gitconfig, and we end up with surprising commit messages because the local state sticks around in places where we wouldn't expect.

professor commented 5 years ago

I wanted to make sure I understood the problem. Members of the team are using both git with and git author commands to record who is pairing with who.

In this case git author is correctly setting the commit message.

In general, I recommend only using one git pairing tool at a time. I realize that git author uses git together under the covers. It wouldn't surprise me that there's odd behaviors.

cwlbraa commented 5 years ago

I recommend only using one git pairing tool at a time.

This is not a straightforward recommendation.

git-author is a pairing tool that directly depends on having another pairing tool installed and usable. On CF teams, we move between teams' workstation setups all the time and everyone has a different set of commands they expect to work. It's fine if the other tools fail, but in this particular case we can't disable git with or else git author will no longer work. We can't easily stop team members or cross-team-pairs from erroneously using git with, and that corrupts usage of git-author.

xinzweb commented 5 years ago

First, just want to confirm, the git with is actually git-together with?

Second, inside git author, we actually called git-together with --global.

In the repro, people set different authors with git with and git author. Where git author correctly set the commit template message and global setting, and git with correctly set the author and committer information locally for this repo.

However, that's confusing. We actually have 2 pairs working on the same commit. Hence this ends up the author and committer no longer consistent with the commit message template of Co-authored-by:. I think that's the root cause of the issue.

I would recommend people to use consistent pairs, e.g.

git with cb am
git author cb am
cwlbraa commented 5 years ago

Yup yup, I think you've described the issue pretty clearly, @xinzweb, but your recommendation is not ideal-- we work across many repos and we'd need to constantly re-run git with cb am to keep things consistent.

All we really want is to force global state to be the only state. git-author is already trying to do this, but its git-together dependency leaks through and still allows repo-local state to be set and read.

We have found a workaround, though, based on the observation that git with --clear always correctly removes local state- it's ugly, but it seems to be working so far!

alias git="git-together with --clear 2>/dev/null || true ; git-together"