desktop: Improve context on pre-commit hook failures and provide escape hatch
Describe the bug
I cannot commit to the excalidraw/excalidraw repo in GitHub Desktop. Using GitUp (another GUI) or the git CLI both work fine.L
Version & OS
GitHub Desktop Version 2.4.0, macOS Version 10.15.3 (19D76)
Steps to reproduce the behavior
- Clone
https://github.com/excalidraw/excalidraw - Run
npm installto install the dependencies - Open the repo in your favorite editor and delete lines 8–18 of
src/index.tsxso you have something to commit. - In GitHub Desktop, commit the change.
Expected behavior
The commit occurs successfully.
Actual behavior
An error dialog displaying this text:
Commit failed - exit code 1 received, with output: 'husky > pre-commit (node v13.11.0)
Preparing... [started]
Preparing... [failed]
→ error: unknown option 'ignore-skip-worktree-entries'
usage: git update-index [<options>] [--] [<file>...]
[removed: listing of all options]
Cannot save the current worktree state
Running tasks... [started]
Running tasks... [skipped]
→ Skipped because of previous git error.
Applying modifications... [started]
Applying modifications... [skipped]
→ Skipped because of previous git error.
Cleaning up... [started]
Cleaning up... [skipped]
→ Skipped because of previous git error.
✖ lint-staged failed due to a git error.
Any lost modifications can be restored from a git stash:
> git stash list
stash@{0}: On master: automatic lint-staged backup
> git stash pop stash@{0}
error: unknown option 'ignore-skip-worktree-entries'
[removed: listing of all options]
Cannot save the current worktree state
husky > pre-commit hook failed (add --no-verify to bypass)
Additional context
I’m guessing this is because --ignore-skip-worktree-entries was recently added to Git and Husky is using Desktop’s bundled version for some reason?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 25
- Comments: 27 (4 by maintainers)
This came up again in #11802. If a contributor wants to take a crack at adding a “Commit anyway” button to the error dialog, I think that’d be a great next step.
A ➕ to make this happen [9]
I’ve confirmed with @j-f1 that
git config stash.usebuiltin falsefixes the issue, so this can be used as a workaround.It’s still unclear why does lint-staged executes the system git binary in some systems. This could probably be caused by some specific bash configuration…
Anyways, I see 3 different things going on here:
git, which causesgitto spawn internally a binary of a different version causing failures when usingGIT_EXEC_PATH.Maybe we can refocus this issue (or create a new issue) to try to address point 3. so:
Why can’t there be a button to “commit anyway” on the error window that uses --no-verify? That is a no brainer since this window only shows for people with pre-commit.
I’ve been trying to move to github desktop from another gui tool, but I guess I might have to find yet another option
Thanks for reporting @j-f1 !
After some offline discussion with @j-f1 , he realized that the issue comes from the
lint-stagednpm package.These are the events that I think are happening based on the conversation with @j-f1 (I haven’t been able to reproduce the problem in my machine though, so take this with a grain of salt):
huskycreates apre-commitgit hook, which gets executed by the version ofgitthat gets bundled by Desktop.pre-commithook executes anshscript that ends up executinglint-stagedon theexcalibur/excaliburproject (source).pre-commithook gets executed with theGIT_EXEC_PATHenv variable set to the path of the git binary bundled in Desktop and adds its path to the beginning of thePATHenv var.lint-stagedrunsgit stash save --include-untracked --keep-index 'lint-staged automatic backup'(source).gitbinary used for the previous command gets resolved to the system version ofgit(I have no idea why this happens???lint-stagedusesexecato executegit).gitis above v2.25.0, thegit stashcommand will internally callgit update-index --ignore-skip-worktree-entries -z --add --remove --stdin(source).gitcommand will get executed using the git binary bundled in Desktop (thanks to theGIT_EXEC_PATHenv var).--ignore-skip-worktree-entriesparam so the command fails.Based on the sourcecode of
git stash, looks like this behaviour can be avoided by using setting thestash.useBuiltinconfig param tofalse(this way, the old legacy stash logic will get executed):(this is just a potential workaround and may cause other issues).
The main question here is regarding point 5., and why does
lint-stagedignores the path and resolves to the system git binary in some systems. I think that if we can figure out that issue and resolve it, this issue will go away.