• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: High High
    • None
    • 4.0
    • General, Git
    • Severity 2 - Major

      I've recently noticed that linting errors are not caught with our pre-commit hooks.

      At first I thought it's a problem with lint-staged or husky but eventually found that SourceTree on Mac just skips the commit hooks.
      Committing from the command line or IDE works ok (pre-commit runs).

      As the commit window closes quickly, I didn't even know what was the problem.
      Only after checking Preferences > Advanced > Always display full console output, I saw the following:

      git --no-optional-locks -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree commit -q -F /var/folders/vj/md8l7z_52v751h494yhrjr580000gn/T/SourceTreeTemp.B8F4vi

      Can't find yarn in PATH: /Applications/Sourcetree.app/Contents/Resources/git_local/libexec/git-core:/Applications/Sourcetree.app/Contents/Resources/bin:/Applications/Sourcetree.app/Contents/Resources/git_local/bin:/Applications/Sourcetree.app/Contents/Resources/git_local/gitflow:/Applications/Sourcetree.app/Contents/Resources/git_local/git-lfs:/usr/bin:/bin:/usr/sbin:/sbin

      Skipping pre-commit hook

      Completed successfully

      After spending several hours trying to fix it, without luck, I checked with other developers if they have the issue as well, and indeed, they had the same issue.

      Observed on different versions of SourceTree and macOS:

      SourceTree 3.x on macOS 10.15.1.
      SourceTree 4.0.1 on macOS 10.14.6.

      Also the PATH error can be other things like:

      Can't find node in PATH
      Can't find npx in PATH

      Basically the issue is that /usr/local/bin is not in the PATH list.

      This is really disheartening (making us doubt the reliability of SourceTree).
      Please give this issue priority.

      Thanks.

            [SRCTREE-7184] Commit hooks are skipped due to PATH issues

            Fixed in 4.2.3 release.

            Natchiar Venkatachalam (Inactive) added a comment - Fixed in 4.2.3 release.

            Hi Raman Sidarakin,

            Just downloaded and installed 4.2.3 (252) and can confirm pre-commit hooks are working here. Thank you for the fix, its much appreciated here.

            Kind Regards

            Kate

            Kate Wilkins added a comment - Hi Raman Sidarakin, Just downloaded and installed 4.2.3 (252) and can confirm pre-commit hooks are working here. Thank you for the fix, its much appreciated here. Kind Regards Kate

            Hi, 2b3b7c8a7f14 

            Thanks for providing your comment on this.

            Since version 4.2.3 Sourcetree is sourcing user's environment configuration files depending on shell configured in the system to be able to pick up modifications of PATH variable before invoking git or hg commands. This was done because by default gui applications are not inheriting any user environment automatically at launch, which causes this issue. So, Sourcetree is trying to load user's PATH from shell configuration files.

            So, for example, in case of zsh shell Sourcetree will load the next profiles: "/.zshenv", "/.zprofile", "/.zshrc", "/.zlogin". For sh shell Sourcetree will source these profiles: "/.profile", "/.bashrc".

            Most probably, the tools that you are using inside hook script are not added to the PATH env variable inside any of the shell configuration file that corresponds to your current shell.

            Let me provide few recommendations which you could try to resolve your issue:

            1. To get your current shell name you could run "echo $SHELL" in terminal.
            2. Most probably it will be zsh shell. Check if any of these files are existing: "/.zshenv", "/.zprofile", "/.zshrc". In case there are no any of them, then create new  "/.zshrc" file.
            3. Identify where your tool is located (I mean tool which is failing in commit hook). For example run: "which yarn" in terminal. The result will be some path. For example: "/usr/local/bin/yarn". You need to take the path to directory where tool is located. In provided example it's "/usr/local/bin"
            4. Open "~/.zshrc" and add the next line into it:
              export PATH="/usr/local/bin:${PATH}"

               here "/usr/local/bin"should be a path to directory where your tool is located. Then save the file.

            1. Relaunch Sourcetree and your hook should work now.

            Please, let me know about any results or any questions. 

            Looking forward to your reply.

             

            Raman Sidarakin (Inactive) added a comment - - edited Hi, 2b3b7c8a7f14   Thanks for providing your comment on this. Since version 4.2.3 Sourcetree is sourcing user's environment configuration files depending on shell configured in the system to be able to pick up modifications of PATH variable before invoking git or hg commands. This was done because by default gui applications are not inheriting any user environment automatically at launch, which causes this issue. So, Sourcetree is trying to load user's PATH from shell configuration files. So, for example, in case of zsh shell Sourcetree will load the next profiles: " /.zshenv", " /.zprofile", " /.zshrc", " /.zlogin". For sh shell Sourcetree will source these profiles: " /.profile", " /.bashrc". Most probably, the tools that you are using inside hook script are not added to the PATH env variable inside any of the shell configuration file that corresponds to your current shell. Let me provide few recommendations which you could try to resolve your issue: To get your current shell name you could run "echo $SHELL" in terminal. Most probably it will be zsh shell. Check if any of these files are existing: " /.zshenv", " /.zprofile", " /.zshrc". In case there are no any of them, then create new  " /.zshrc" file. Identify where your tool is located (I mean tool which is failing in commit hook). For example run: "which yarn" in terminal. The result will be some path. For example: "/usr/local/bin/yarn". You need to take the path to directory where tool is located. In provided example it's "/usr/local/bin" Open "~/.zshrc" and add the next line into it: export PATH= "/usr/local/bin:${PATH}"  here "/usr/local/bin"should be a path to directory where your tool is located. Then save the file. Relaunch Sourcetree and your hook should work now. Please, let me know about any results or any questions.  Looking forward to your reply.  

            I'm running 4.2.3 on Mac and I'm still having this issue. Scott's command worked for me, but opening it normally results these issues still.

            jasonpworden added a comment - I'm running 4.2.3 on Mac and I'm still having this issue. Scott's command worked for me, but opening it normally results these issues still.

            Hi, 19cf0ef3a288.
            It will be Sourcetree 4.2.3 release. I hope we will deliver it by the mid of may 2023.

            Raman Sidarakin (Inactive) added a comment - Hi, 19cf0ef3a288 . It will be Sourcetree 4.2.3 release. I hope we will deliver it by the mid of may 2023.

            Kate Wilkins added a comment - - edited

            Hi Raman,

            Thanks, I did read your response to my ticket and followed it here. Hence the bump in the comments.

            Can you clarify what is meant by 'working on resolving this and fix is tagreted to the next release'. Ticket doesn't show as assigned also what does next release mean, next major or minor release. It would be good to understand some sort of timeline, we talking days/weeks/months?

            Thanks

            Kate

            Kate Wilkins added a comment - - edited Hi Raman, Thanks, I did read your response to my ticket and followed it here. Hence the bump in the comments. Can you clarify what is meant by 'working on resolving this and fix is tagreted to the next release'. Ticket doesn't show as assigned also what does next release mean, next major or minor release. It would be good to understand some sort of timeline, we talking days/weeks/months? Thanks Kate

            Hi, 19cf0ef3a288
            I've closed your issue https://jira.atlassian.com/browse/SRCTREE-8025 as a duplicate.

            I also left comment when closed it. Main part of my message is:
            We are working on resolving this and fix is targeted to the next Sourcetree release.

            Raman Sidarakin (Inactive) added a comment - Hi, 19cf0ef3a288 I've closed your issue https://jira.atlassian.com/browse/SRCTREE-8025 as a duplicate. I also left comment when closed it. Main part of my message is: We are working on resolving this and fix is targeted to the next Sourcetree release.

            Just a bump on this issue, how on earth can this still not be fixed. I raised a separate ticket and thats been closed, linked to this. Come on people. We're being forced into moving away from Sourcetree because of this show stopper of a bug where githooks don't work.

            Kate Wilkins added a comment - Just a bump on this issue, how on earth can this still not be fixed. I raised a separate ticket and thats been closed, linked to this. Come on people. We're being forced into moving away from Sourcetree because of this show stopper of a bug where githooks don't work.

            Scott Parkerson added a comment - - edited

            The only completely successful workaround I've found is to launch Sourcetree from a terminal whose PATH environment is set correctly using the following command:

                 /Applications/Sourcetree.app/Contents/MacOS/Sourcetree > /dev/null 2>&1 &

            and it'll use your PATH environment.

            (Of course, one should not have to do this.)

            The biggest clue here is that Sourcetree seems to ignore the path set in in `launchctl` since 4.1.2 (see https://jira.atlassian.com/browse/SRCTREE-7184?focusedCommentId=2932285&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-2932285 above). I wonder if it's just ... overwriting it with its own paths instead of extending it or merging it?

             

             

            Scott Parkerson added a comment - - edited The only completely successful workaround I've found is to launch Sourcetree from a terminal whose PATH environment is set correctly using the following command:      /Applications/Sourcetree.app/Contents/MacOS/Sourcetree > /dev/null 2>&1 & and it'll use your PATH environment. (Of course, one should not have to do this.) The biggest clue here is that Sourcetree seems to ignore the path set in in `launchctl` since 4.1.2 (see https://jira.atlassian.com/browse/SRCTREE-7184?focusedCommentId=2932285&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-2932285 above). I wonder if it's just ... overwriting it with its own paths instead of extending it or merging it?    

            luchaos added a comment - - edited

            Solution for Apple m1 Pro chip MacBook Pro - macOS 12.4 - using homebrew:

            > Settings -> Git -> Use System Git -> "/opt/homebrew/bin/git" (NOT "/usr/*/git")

            This magically added "/opt/homebrew/bin" to SourceTree's $PATH and all git hooks started working again.

            That's an even easier fix than on my Intel MacBook where I had to open stree via CLI to make it work.

            I'm happy this is the only issue I have with SourceTree and that it's fixable without changing my hooks' scripts or modifying $PATH in other ways - collaborators do not care about my local issues. I cannot for my life work with any other git GUI client - i tried (Tower, GitKraken, JetBrains/VSCode integrated, ...). I'd rather stick with SourceTree + git cli as long as I can for productivity at no cost. The paid and integrated options are too restrictive in the wrong places and/or the UI is lacking imo.

            luchaos added a comment - - edited Solution for Apple m1 Pro chip MacBook Pro - macOS 12.4 - using homebrew: > Settings -> Git -> Use System Git -> "/opt/homebrew/bin/git" (NOT "/usr/*/git") This magically added "/opt/homebrew/bin" to SourceTree's $PATH and all git hooks started working again. That's an even easier fix than on my Intel MacBook where I had to open stree via CLI to make it work. I'm happy this is the only issue I have with SourceTree and that it's fixable without changing my hooks' scripts or modifying $PATH in other ways - collaborators do not care about my local issues. I cannot for my life work with any other git GUI client - i tried (Tower, GitKraken, JetBrains/VSCode integrated, ...). I'd rather stick with SourceTree + git cli as long as I can for productivity at no cost. The paid and integrated options are too restrictive in the wrong places and/or the UI is lacking imo.

              43c951f935c6 Raman Sidarakin (Inactive)
              6666d464e45a alexilyaev
              Affected customers:
              78 This affects my team
              Watchers:
              71 Start watching this issue

                Created:
                Updated:
                Resolved: