Sublime Forum

Pre-commit hooks work differently in SM and terminal

#1

Hi, I am having a problem and I am looking for some help to solve it.

I am on the latest macOS and am using Sublime Merge as my main git tool (it’s great and worth a lot more than price that I’ve paid for it). I currently have “inconsistent” behaviour of pylint that runs as a part of the pre-commit hook.

When I commit from from SM - pylint checks all the repo and when I commit it from the terminal (git commit -m "my commit message") it checks only the files that are staged. The latter behaviour is what I want to have in SM.

Git (that’s available in the terminal) was installed from homebrew. The SM settings json looks like this:

{
    "theme": "Merge Dark.sublime-theme",
    "git_binary": "system",
    "side_bar_layout": "locations_as_column",
    "hardware_acceleration": "opengl",
    "editor_path": "/usr/local/bin/code",
    "editor_argument_format": "--goto ${file}:${line}:${col}",
    "always_show_command_status": false,
}

Can someone point me to a solution? I suppose that this is related to the environment setup, is it?

Thanks

0 Likes

Husky pre-commit hook failing in Sublime Merge
#2

Hi @pll_llq,

Thanks for reaching out to us! I’ll be investigating this further.

This could be related to environment variables.

When you have a spare moment, would you mind sharing your Sublime Merge debug information?
This can be found in the application menu under Help > Debug Information.

Before sharing this, please take a moment to remove any information you feel is sensitive such as file paths, author information, remote URLs etc.

Thanks,
- Dylan from Sublime HQ

0 Likes

#3

Thanks @djohnston

Here’s the debug information

=== App Version Information ===
Build: 2063

=== Git Version Information ===
Using Git: git (system)
git version 2.34.0
PATH: /Users/MyUser/.nvm/versions/node/v16.13.0/bin:/Users/MyUser/.rvm/gems/ruby-3.0.0/bin:/Users/MyUser/.rvm/gems/ruby-3.0.0@global/bin:/Users/MyUser/.rvm/rubies/ruby-3.0.0/bin:/usr/local/sbin:/usr/local/opt/python@3.8/bin:/usr/local/lib/python3.8/site-packages:/usr/local/opt/ruby/bin:/usr/local/opt/gnu-getopt/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/git/bin:/Users/MyUser/MyRepo/venv/bin:/Users/MyUser/.nvm/versions/node/v16.13.0/bin:/Users/MyUser/.rvm/gems/ruby-3.0.0/bin:/Users/MyUser/.rvm/gems/ruby-3.0.0@global/bin:/Users/MyUser/.rvm/rubies/ruby-3.0.0/bin:/Users/MyUser/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/opt/python@3.8/bin:/usr/local/lib/python3.8/site-packages:/usr/local/opt/ruby/bin:/usr/local/opt/gnu-getopt/bin:/Users/MyUser/.rvm/bin (from shell)
environment variables loaded using: /bin/bash -l

=== Browse Page Information ===
HEAD: 0914593e9583134b9bb35a6bd3ae871ac0d2503d
Is in merge: 0
Is in cherry_pick: 0
Is in rebase: 0
Is in revert: 0

=== Git Status Information ===

=== Our Status Information ===

=== Git Config Information ===
branch.main.merge=refs/heads/main
branch.main.remote=upstream
branch.BranchFolder/mybranch.github-pr-owner-number=MyRepo#MyRepo#1049
branch.BranchFolder/mybranch.merge=refs/heads/BranchFolder/mybranch
branch.BranchFolder/mybranch.remote=upstream
branch.prbranch.github-pr-owner-number=MyRepo#MyRepo#1041
branch.prbranch.merge=refs/heads/prbranch
branch.prbranch.remote=upstream
color.all=true
color.branch=auto
color.branch.current=yellow reverse
color.branch.local=yellow
color.branch.remote=green
color.diff=auto
color.diff.frag=magenta bold
color.diff.meta=yellow bold
color.diff.new=green bold
color.diff.old=red bold
color.status=auto
color.status.added=green
color.status.changed=red
color.status.untracked=yellow
color.ui=auto
commit.template=/Users/MyUser/.stCommitMsg
core.bare=false
core.excludesfile=/Users/MyUser/.gitignore_global
core.filemode=true
core.ignorecase=true
core.logallrefupdates=true
core.precomposeunicode=true
core.repositoryformatversion=0
credential.helper=osxkeychain
diff.tool=smerge
difftool.smerge.cmd=subl -n --wait "$REMOTE" "$LOCAL" --command "smerge_diff_views {\"left_read_only\": true, \"right_read_only\": true}"
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.smudge=git-lfs smudge -- %f
filter.media.clean=git-media-clean %f
filter.media.smudge=git-media-smudge %f
gui.recentrepo=/Users/MyUser/OtherRepo
help.autocorrect=1
init.defaultbranch=main
merge.tool=smerge
mergetool.smerge.cmd=subl -n --wait "$REMOTE" "$BASE" "$LOCAL" "$MERGED" --command "smerge_diff_views"
mergetool.smerge.trustexitcode=false
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
pull.ff=only
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=git@github.com:mygithub/MyRepo.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
remote.upstream.url=git@github.com:MyRepo/MyRepo.git
url.git@github.com:.insteadof=https://github.com/
user.email=my@email.com
user.name=My Name

=== Our Config Information ===
Git Config Path Information
Using config path: /usr/local/etc/gitconfig
Using config path: /Users/MyUser/.config/git/config
Using config path: /Users/MyUser/.gitconfig
Using config path: /Users/MyUser/MyRepo/.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

Let me know if I can provide any other info to help you look into this.

0 Likes

#4

Hi @pll_llq,

Thanks for the additional information - if the contents of the pre-commit hook is not sensitive, would you mind sharing it here?

Thanks,
- Dylan

0 Likes

#5

Sure @djohnston no problem.
The hooks are defined in this file

If it does matter I launch SM from the terminal using the following alias:
alias smerge='/Applications/AnotherFolder/Sublime\ Merge.app/Contents/SharedSupport/bin/smerge'

0 Likes

#6

Hey @djohnston, any update on this?

0 Likes

#7

Hey @djohnston, any update on this issue?

0 Likes

#8

Hi @pll_llq,

Apologies for the delay in getting back to you as we’ve been closed over the holiday period.

So far I haven’t been able narrow down the cause of this issue, but I will continue to investigate today and keep you updated.

Thanks,
- Dylan from Sublime HQ

1 Like

#9

Hey @djohnston, a small update from my side. I’ve migrated to a new mac and on a fresh system smerge can’t find pylint from the pre-commit hook environment, while it can find other liners mentioned in the hook and pylint itself works from the CLI (see pictue, smerge on the left).

On this machine I’m using a conda environment instead of a local virtual environment folder. It might be that smerge doesn’t know where to look for hooks that have the
- repo: local in the config but invoke a dependency

I did try launching smerge from the folder with the environment activated (like it helped here Solved: Environment (?)) and from the OS GUI with nothing activated, but it didn’t help and the hooks are currently not working for me…

Can you advice anything on the issue?

0 Likes

#10

OK, so I “fixed” it.
I needed to explicitly launch smerge . from the project folder AND with the environment activated.
Like that merge will loads the PATH env variable correctly and the hooks run successfully

0 Likes

#11

Are you setting the PATH env variable in the correct file? See https://www.sublimetext.com/docs/command_line.html

1 Like

#12

Thanks, I’ve changed the PATH and it started working without the hiccups.

Added 2 lines to the .zshrc:

export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"
export PATH="/Applications/Sublime Merge.app/Contents/SharedSupport/bin:$PATH"
``
0 Likes