Skip to content

Use git config user.email to determine the author email used when merging with gh pr merge - #5229

Closed
jtaylor100 wants to merge 2 commits into
cli:trunkfrom
jtaylor100:trunk
Closed

jtaylor100 wants to merge 2 commits into
cli:trunkfrom
jtaylor100:trunk

Conversation

@jtaylor100

@jtaylor100 jtaylor100 commented Feb 20, 2022 •

Copy link
Copy Markdown

Fixes #1450

Tested on https://github.com/jtaylor100/test-repo

  • jtaylor100/test-repo@adebf80 was made before the below changes, incorrectly using my GitHub default email as the author email.
  • jtaylor100/test-repo@5d1d23d was made after the below changes, using the value of git config user.email from the repo as the author email.
  • jtaylor100/test-repo@0e2176b was made after the below changes, where locally my value of git config user.email was empty, so the default GitHub email is used.

@jtaylor100
jtaylor100 requested a review from a team as a code owner February 20, 2022 14:43
@jtaylor100
jtaylor100 requested review from mislav and removed request for a team February 20, 2022 14:43
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Feb 20, 2022
@mislav mislav added the discuss Feature changes that require discussion primarily among the GitHub CLI team label Feb 21, 2022

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good so far!

Note that we will have to discuss this feature with our team to make sure we're not introducing too much "magic" by respecting user.email of the current repo. Please allow us some time ponder about this.

In the meantime, could you also add a flag to pr merge so that the user can also explicitly set the email address to be able to opt out of the behavior of reading git config? The flag could be called --author-email for now. Thank you!

Comment thread pkg/cmd/pr/merge/merge.go

// ignore error, since git.Config will return "" for
// authorEmail if any error occurs
authorEmail, _ := git.Config("user.email")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This respects the global setting, but also respects the per-checkout setting when inside of a git checkout of a repo. Should we respect the local setting even when merging a PR in another repository?

For example: I'm in the local directory of repoA, but I'm merging a PR in repoB: gh pr merge --repo mislav/repoB 123. Even though I've explicitly selected the repository to be another repository, git config user.email will read and apply the setting for repoA to my merge, ending in a potentially unwanted result.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, yes that is an interesting case. Intuitively I believe the behaviour should be: if a repo is specified other than the current directory's repo, then always fall back to the GitHub default email.

@jtaylor100

Copy link
Copy Markdown
Author

@mislav Would you advise putting the work to create a flag in a different PR?

@mislav

mislav commented Mar 8, 2022

Copy link
Copy Markdown
Contributor

@jtaylor100 No, I would put it all together because it closely relates to the issue this is all aiming to address.

@darcyclarke darcyclarke removed the discuss Feature changes that require discussion primarily among the GitHub CLI team label Mar 23, 2022
@vilmibm

vilmibm commented Aug 22, 2022

Copy link
Copy Markdown
Contributor

Given the discomfort with introducing implicit coupling with a git config value, we've decided to close this; however, we'd consider a new PR adding a flag to pr merge for setting author info.

@vilmibm vilmibm closed this Aug 22, 2022
cavcrosby added a commit to cavcrosby/aws-cli that referenced this pull request Apr 26, 2026
This was done because, as of the 1b5df39 commit, merge commits are now
authored by me instead of the GitHub Actions user. Which isn't
desirable. Unfortunately, the GitHub (gh) CLI client doesn't seem to
respect Git's user.email configuration, and the client maintainers
haven't been comfortable adding support in the past (at least when
reading this pull request: cli/cli#5229). Hence,
I've decided to use the git CLI client instead.

The fetch-depth parameter is set to 0 to prevent the 'fatal: refusing to
merge unrelated histories' error from occurring. Also, then token
parameter was set so the CLI client would use the fine-grained access
token.

Documentation for the GitHub Actions user can be seen here:
https://github.com/actions/checkout#push-a-commit-using-the-built-in-token.
cavcrosby added a commit to cavcrosby/aws-cli that referenced this pull request Apr 26, 2026
This was done because, as of the 1b5df39 commit, merge commits are now
authored by me instead of the GitHub Actions user. Which isn't
desirable. Unfortunately, the GitHub (gh) CLI client doesn't seem to
respect Git's user.email configuration, and the client maintainers
haven't been comfortable adding support in the past (at least when
reading this pull request: cli/cli#5229). Hence,
I've decided to use the Git CLI client instead.

The fetch-depth parameter is set to 0 to prevent the 'fatal: refusing to
merge unrelated histories' error from occurring. Also, then token
parameter was set so the CLI client would use the fine-grained access
token.

Documentation for the GitHub Actions user can be seen here:
https://github.com/actions/checkout#push-a-commit-using-the-built-in-token.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Select commit email when merging PR

5 participants