stackblitz / core

Online IDE powered by Visual Studio Code ⚡️
https://stackblitz.com
MIT License
10.23k stars 888 forks source link

Respect Github "Keep my email address private" Setting #2976

Open coder0107git opened 7 months ago

coder0107git commented 7 months ago

Description

On Codeflow (may also apply to Webflow or Classic editor, haven't tested on those though), pushing commits fails if you have the Github setting "Keep my email address private" enabled. This is basically the same issue as #1963 and gitpod#387.

Steps to Reproduce

  1. Enable "Keep my email address private" in Github settings.
  2. Open any Github repo that you have commit access to.
  3. Change a file and commit
  4. Try to push changes
  5. See git error log for error

Note: All of this is through the UI, not the command line (although it probably applies to the command line too).

Expected Behavior

Be able to push commits.

Work around

> # ID and USERNAME can be retrieved at https://api.github.com/users/{USERNAME}
> git config user.email "ID+USERNAME@users.noreply.github.com"
>
> # Print configured email to make sure it updated correctly
> git config user.email
>
> git add -A
> git commit -m "Test commit"
> git push
cukabeka commented 7 months ago

I can confirm this, also the related #1963 I tried changing my git email with git config --global user.email "my@mail.com" or git config user.email "my@mail.com" in the terminal, but this seems to make the terminal hang. I can only exit the command with ^C back to the bash prompt with no mails changed.

samdenty commented 7 months ago

👋 we have a fix in the way, @SamVerschueren is working on it

SamVerschueren commented 7 months ago

Yes exactly. We're working on it but can't give an ETA yet on when it will land.

elliottregan commented 7 months ago

Thank you! I've gotten stuck on project recently because I had made a few commits, couldn't push. Couldn't rebase to change the author of those commits either because I the terminal version of git doesn't have a rebase command.

W1Real commented 6 months ago

You can save this as push.sh and execute, or you can simply paste it.

You can find your github commit email here: https://github.com/settings/emails

Add to your .gitignore because you don't want to push this dirty hack to the repo, if you prefer to save it.

Use it at your own risk. I'm not sure what side effects this might have. I added "&&" to have some extra reassurance, but I'm not a pro at bash scripts

git config --global user.email "EMAIL GOES HERE" && \
git config --global user.email && \
git add -A && \
git commit -m "COMMIT MESSAGE" && \
git push

If you prefer to save, paste this to execute it: chmod +x push.sh && ./push.sh

circle-gon commented 5 months ago

Will the fix land anytime soon? I want to use stackblitz codeflow but I can't get it to use my GitHub private email. The workaround doesn't work, it hangs the terminal and after using ^C, nothing happens to the commit email (it's still the same).

edit: I've found a workaround using the simple-git npm package. Paste this in a js file that you can run using node then commit from the command line (not the IDE).

// RUN THIS ON A NEW STACKBLITZ INSTANCE AND USE THE COMMAND LINE TO PUSH

import { simpleGit } from "simple-git"

// this apparently breaks without this wrapper, even for type=module in package.json
(async () => {
    try {
      const git = simpleGit()
      await git.addConfig("user.email", "insert email", false, "global")
      await git.addConfig("user.name", "insert name", false, "global")

      console.log("Done setting config!")
    } catch (e) {
        console.log("Uh oh, something went wrong...")
        console.error(e)
    }
})()