sublime_merge icon indicating copy to clipboard operation
sublime_merge copied to clipboard

Husky pre-commit hook not working

Open mwolman opened this issue 3 years ago • 23 comments

Version info

  • OS: macOS Big Sur 11.2.3
  • Build: 2049

Description

My repo has a pre-commit hook and is not working only in Sublime Merge.

Screenshot 2021-03-24 at 16 10 50

I already have the 2.5.5 version of ruby. I think it's trying to use my global gems instead of my local gems. If I create a commit from my terminal, I have no problems. There's no issue with the repo and ruby; this only happens when trying to create a commit from Sublime Merge.

mwolman avatar Mar 24 '21 19:03 mwolman

Hi @mwolman,

Thanks for reaching out to the Sublime Merge team - I will be investigating this further.

When you have a spare moment, could you:

  • Try switching Sublime Merge to use system Git and see if this resolves the issue
    1. Open Sublime Merge
    2. Navigate to Preferences > Preferences... > Advanced
    3. Set Git Binary to system
  • Share your Sublime Merge git version debug information
    1. Open Sublime Merge
    2. Navigate to Help > Debug Information
    3. Share the section of the debug information labelled === Git Version Information === here
  • Confirm which shell you are using on the terminal e.g. zsh (if you're unsure, it should say in the title of the terminal window)

Thanks, - Dylan

dpjohnst avatar Mar 25 '21 01:03 dpjohnst

Changing Git Binary to system didn't fix the issue 😢

=== App Version Information === Build: 2049

=== Git Version Information === Using Git: git (system) git version 2.24.3 (Apple Git-128) PATH: /Users/micaelawolman/.rvm/gems/ruby-2.7.1/bin:/Users/micaelawolman/.rvm/gems/ruby-2.7.1@global/bin:/Users/micaelawolman/.rvm/rubies/ruby-2.7.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/micaelawolman/.rvm/bin (from shell) environment variables loaded using: /bin/zsh -l

=== Browse Page Information === HEAD: 223c7d0b06f7d7fc3e77a4c41f21cddc81678908 Is in merge: 0 Is in cherry_pick: 0 Is in rebase: 0 Is in revert: 0

=== Git Status Information === M spec/models/document_spec.rb

=== Our Status Information === M spec/models/document_spec.rb

=== Git Config Information === branch.i18n-locale-in-documents.merge=refs/heads/i18n-locale-in-documents branch.i18n-locale-in-documents.remote=origin branch.master.merge=refs/heads/master branch.master.remote=origin core.bare=false core.filemode=true core.ignorecase=true core.logallrefupdates=true core.precomposeunicode=true core.repositoryformatversion=0 credential.helper=osxkeychain remote.origin.fetch=+refs/heads/:refs/remotes/origin/ remote.origin.url=https://github.com/yankaindustries/masterclass.git [email protected] user.name=Micaela Wolman

=== Our Config Information === Git Config Path Information Using config path: /etc/gitconfig Using config path: /Users/micaelawolman/.config/git/config Using config path: /Users/micaelawolman/.gitconfig Using config path: /Users/micaelawolman/Documents/masterclass/.git/config

Our config output is identical to the Git config output

=== Git Attributes Information === git check_attr --all output

=== Our Modified Files Newline Normalisation and EOL Information ===

=== Our Modified Files Flag Information === Ignoring symlinks: 0

I'm using zsh, didn't understand where I should see it

mwolman avatar Mar 25 '21 15:03 mwolman

Screenshot 2021-03-25 at 12 36 25

This is what I have inside /Users/micaelawolman/.rvm/gems/, the 2.5.5 version is there, but Sublime Merge is not loading it

mwolman avatar Mar 25 '21 15:03 mwolman

Hi @mwolman,

Thanks for the additional information.

Sublime Merge will load the PATH variable from your system to determine the location of binaries / files etc. If you're using zsh, it will do this by calling /bin/zsh -l (i.e. a non interactive zsh), and will only load user environment variables from the .zprofile file.

The simplest way to get Sublime Merge to use ruby-2.5.5 would be appending the path to ruby-2.5.5 to the PATH variable within .zprofile i.e. add the following to ~/.zprofile, replacing /path/to/ruby/ with the real path

export PATH=/path/to/ruby/:$PATH

You'll then likely need to restart Sublime Merge for changes to take effect.

Thanks, - Dylan

dpjohnst avatar Mar 25 '21 23:03 dpjohnst

Same problem here, using SM Build 2048 under Win 10 x64: Git hooks fail to work when using the bundled Git binary, but work fine when using system Git.

tajmone avatar Apr 19 '21 06:04 tajmone

@dpjohnst forgot to answer this! I couldn't make it work, I don't have a ~/.zprofile file

mwolman avatar Apr 19 '21 14:04 mwolman

Hi @mwolman,

Thanks for getting back to me!

No worries if you don't have a .zprofile file - just go ahead and create one in your home directory, adding the following to the file:

export PATH=/path/to/ruby/:$PATH

Replacing /path/to/ruby/ with the path to the specific ruby version you require.

Let me know how this goes!

Kind regards, - Dylan

dpjohnst avatar Apr 22 '21 00:04 dpjohnst

Same kind of problem here.

Error from Sublime Merge:

.husky/pre-commit: line 4: yarn: command not found
husky - pre-commit hook exited with code 127 (error)

It's well defined in the $PATH variable.

$ echo $PATH
/Users/j0k/.nvm/versions/node/v12.22.1/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/local/opt/[email protected]/bin:#{HOMEBREW_PREFIX}/bin:~/.composer/vendor/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ which yarn
/usr/local/bin/yarn
$

What can I try next?

If I echo $PATH from the pre-commit script, I got a value which has nothing to do with the previous one 🤔 :

/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin

j0k3r avatar Jul 01 '21 12:07 j0k3r

What can I try next?

Since I started using Git hooks I had to change Sublime Merge settings to use native Git instead of SM's Git.

That worked for me, and since then I haven't reverted to using SM's native Git.

tajmone avatar Jul 01 '21 13:07 tajmone

I already have system as default for the Git Binary, but it changed nothin... image

j0k3r avatar Jul 01 '21 14:07 j0k3r

I already have system as default for the Git Binary, but it changed nothin...

then it looks like there's a problem with some paths not being seen by the Sys PATH passed to Git. You should probably edit your Git configuration to ensure that your PATH env var has all that you need. But this is an OS specific problem. From what you pasted above, I get the impression you're working under macOS. I use Windows, so have no idea how macOS handle this, but under Windows the Git Bash inherits the full System PATH at startup (both machine-wide and User-specific).

tajmone avatar Jul 01 '21 16:07 tajmone

Hi @j0k3r,

Thanks for reaching out - have you tried creating a .zprofile file already and updating the PATH variable via this (as described above)?

Thanks, - Dylan

dpjohnst avatar Jul 02 '21 04:07 dpjohnst

I created it, restarted Sublime Merge and the problem is still here:

$ cat ~/.zprofile
export PATH=/usr/local/bin/:$PATH

I'm on Big Sur and my default terminal is still bash.

j0k3r avatar Jul 02 '21 07:07 j0k3r

Hi @j0k3r,

Thanks for the info - does it work if you rename .zprofile to .bash_profile, and then restart Sublime Merge?

If this doesn't work, would you mind sharing the Sublime Merge debug information via Help > Debug Information. Before sharing this, please take a moment to remove any information that's sensitive (paths, email addresses, remotes etc)

Thanks, - Dylan

dpjohnst avatar Jul 02 '21 07:07 dpjohnst

I already have a .bash_profile with the whole $PATH well configured.

Here are the debug info
=== App Version Information ===
Build: 2056

=== Git Version Information ===
Using Git: git (system)
git version 2.30.1 (Apple Git-130)
PATH: /usr/bin:/bin:/usr/sbin:/sbin
no output from shell "/usr/local/bin/bash" in 1500ms

=== Browse Page Information ===
HEAD: 74b74d60f94eae7a70c1483c26ea6224537bc419
Is in merge: 0
Is in cherry_pick: 0
Is in rebase: 0
Is in revert: 0

=== Git Status Information ===
M  tests/functional/mutations/userFront.test.js

=== Our Status Information ===
M  tests/functional/mutations/userFront.test.js

=== Git Config Information ===
alias.amend=commit --amend
alias.br=branch --verbose
alias.ci=commit
alias.co=checkout
alias.df=diff --ignore-space-at-eol -b -w --ignore-blank-lines
alias.dfc=diff --cached
alias.fe=fetch --all -p
alias.fixup=commit --fixup
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
alias.lgs=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --max-count=10
alias.pop=stash pop
alias.st=status -sb
alias.unadd=reset HEAD
alias.up=pull --rebase
branch.autosetuprebase=always
branch.feature/searchable.merge=refs/heads/feature/searchable
branch.feature/searchable.rebase=true
branch.feature/searchable.remote=origin
branch.master.merge=refs/heads/master
branch.master.rebase=true
branch.master.remote=upstream
color.branch.current=yellow reverse
color.branch.local=yellow
color.branch.remote=green
color.diff.frag=magenta bold
color.diff.meta=yellow bold
color.diff.new=green bold
color.diff.old=red bold
color.status.added=yellow
color.status.changed=green
color.status.untracked=cyan
color.ui=auto
commit.gpgsign=true
core.bare=false
core.excludesfile=/Users/j0k/.gitignore_global
core.filemode=true
core.hookspath=.husky
core.ignorecase=true
core.logallrefupdates=true
core.precomposeunicode=true
core.repositoryformatversion=0
credential.helper=osxkeychain
current-profile.name=perso
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
gpg.program=/usr/local/bin/gpg
mergetool.keepbackup=true
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
push.default=current
rebase.autostash=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
[email protected]:j0k3r/nova.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
[email protected]:20minutes/nova.git

=== Our Config Information ===
Git Config Path Information
Using config path: /etc/gitconfig
Using config path: /Users/j0k/.config/git/config
Using config path: /Users/j0k/.gitconfig
Using config path: /Users/j0k/Sites/20mn/nova/.git/config

Our config output is different to the Git config output
alias.amend=commit --amend
alias.br=branch --verbose
alias.ci=commit
alias.co=checkout
alias.df=diff --ignore-space-at-eol -b -w --ignore-blank-lines
alias.dfc=diff --cached
alias.fe=fetch --all -p
alias.fixup=commit --fixup
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
alias.lgs=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --max-count=10
alias.pop=stash pop
alias.st=status -sb
alias.unadd=reset HEAD
alias.up=pull --rebase
branch.autosetuprebase=always
branch.feature/searchable.merge=refs/heads/feature/searchable
branch.feature/searchable.rebase=true
branch.feature/searchable.remote=origin
branch.master.merge=refs/heads/master
branch.master.rebase=true
branch.master.remote=upstream
color.branch.current=yellow reverse
color.branch.local=yellow
color.branch.remote=green
color.diff.frag=magenta bold
color.diff.meta=yellow bold
color.diff.new=green bold
color.diff.old=red bold
color.status.added=yellow
color.status.changed=green
color.status.untracked=cyan
color.ui=auto
commit.gpgsign=true
core.bare=false
core.excludesfile=/Users/j0k/.gitignore_global
core.filemode=true
core.hookspath=.husky
core.ignorecase=true
core.logallrefupdates=true
core.precomposeunicode=true
core.repositoryformatversion=0
current-profile.name=perso
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
gpg.program=/usr/local/bin/gpg
mergetool.keepbackup=true
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
push.default=current
rebase.autostash=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
[email protected]:j0k3r/nova.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
[email protected]:20minutes/nova.git

=== Git Attributes Information ===
git check_attr --all output

=== Our Modified Files Newline Normalisation and EOL Information ===

=== Our Modified Files Flag Information ===
Ignoring symlinks: 0

j0k3r avatar Jul 02 '21 07:07 j0k3r

@dpjohnst is the debug info help you understand my problem?

j0k3r avatar Jul 29 '21 09:07 j0k3r

Hi @j0k3r,

Thank you for your patience while I've looked into this - It seems as if it's timing out when trying to load the environment variables.

One of the reasons this can occur is if the login shell is attempting to perform many tasks at start-up. Could you confirm whether you have a .bash_login file in your home (~) directory, and whether there are any intensive tasks within the script?

Thanks, - Dylan

dpjohnst avatar Aug 03 '21 05:08 dpjohnst

As of build 2068, it's fixed!

j0k3r avatar Dec 23 '21 10:12 j0k3r

As of build 2068, it's fixed!

I have dev 2067, which I believe is the same, but Git hooks are still not working (Windows 10 x64).

tajmone avatar Dec 24 '21 20:12 tajmone

Hi @dpjohnst 👋🏻

Just wanted to tell you that I changed my computer and now everything is working fine. I don't know if you want to close this issue or not, since other users seem to experience the same bug.

mwolman avatar Apr 22 '22 15:04 mwolman

FYI, I got the problem again using the latest version (2077) and restarting Sublime Merge solved it. Looks like, if it fails, just restart it until the $PATH is properly filled.

j0k3r avatar Oct 20 '22 08:10 j0k3r

Restarting doesn't solve the problem. Build 2083.

thoran avatar Jun 20 '23 06:06 thoran

I hit this issue as well. I finally got it to work, but I'm not sure what exactly did it. One thing I did try was switching to the system git, restarting Merge, setting it back to bundled, and then restarting Merge one more time.

willrowe avatar Jan 23 '24 16:01 willrowe