• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: High High
    • None
    • 4.2.2
    • Git
    • None
    • Minor

      Env vars from terminal

      .git/hooks/pre-commit

      #!/bin/sh

      echo "SHELL: $SHELL"
      echo "PATH: $PATH"

      exit 2{}

      As can be observed, regular terminal ENV is different than the hook ENV (eg. PATH is missing /Users/vrabac/.rbenv/shims). I assume it's because the hook running mechanism didn't load the ~/.zshrc.

      Setup configuration

      • Macbook Air M1
      • macOS Ventura 13.2
      • Iterm2
      • OhMyZsh
      • SourceTree (v4.2.2)
      • SourceTree installed with homebrew (the same thing happens with binary downloaded from the official site)
      • I started the SourceTree from the terminal in the project root folder with stree . command

       

            [SRCTREE-8015] Hooks don't load the zshrc

            Jonas added a comment -

            Hey @Raman Sidarakin,

            thx for investigating this.
            To be honest I just replaced the full path with the ~ in my comment above for privacy reasons.
            I also tried to omit the quotes from the full path and it did not work.

            Jonas added a comment - Hey @Raman Sidarakin, thx for investigating this. To be honest I just replaced the full path with the ~ in my comment above for privacy reasons. I also tried to omit the quotes from the full path and it did not work.

            ba815226c72d , thanks for response.

            I checked few things on my side basing on information that you've provided.

            At first, I've checked if Sourcetree resolves these constructions inside ~/.zshrc file:

            [ -s "~/.jabba/jabba.sh" ] && source "~/.jabba/jabba.sh"

            And I realised, that it doesn't work for me even I'm trying to source "~/.zshrc" file from Terminal.app. After experimenting I found, that the " ~ " symbol is not being resolved to home directory path when it contained inside square brackets and quoted. So, I changed your entry to this:

            [ -s ~/.jabba/jabba.sh ] && source ~/.jabba/jabba.sh

            and it started working for me.

            I also debugged Sourcetree environment after sourcing user configuration files and could confirm that it sources ~/.zshrc file successfully and environment contains all required variables.

            So, could you please try to adjust your ~/.zshrc by removing quotes from paths to ~/.jabba/jabba.sh (in both cases: inside square brackets and inside source command)? After modifying ~/.zshrc you need to restart Sourcetree, so it will pickup updated profile.

            Please, let me know if it helped or not.

            Raman Sidarakin (Inactive) added a comment - - edited ba815226c72d , thanks for response. I checked few things on my side basing on information that you've provided. At first, I've checked if Sourcetree resolves these constructions inside ~/.zshrc file: [ -s "~/.jabba/jabba.sh" ] && source "~/.jabba/jabba.sh" And I realised, that it doesn't work for me even I'm trying to source "~/.zshrc" file from Terminal.app. After experimenting I found, that the " ~ " symbol is not being resolved to home directory path when it contained inside square brackets and quoted. So, I changed your entry to this: [ -s ~/.jabba/jabba.sh ] && source ~/.jabba/jabba.sh and it started working for me. I also debugged Sourcetree environment after sourcing user configuration files and could confirm that it sources ~/.zshrc file successfully and environment contains all required variables. So, could you please try to adjust your ~/.zshrc by removing quotes from paths to ~/.jabba/jabba.sh (in both cases: inside square brackets and inside source command)? After modifying ~/.zshrc you need to restart Sourcetree, so it will pickup updated profile. Please, let me know if it helped or not.

            Jonas added a comment -

            Hey @Raman Sidarakin,

            We just tested on another machine of a colleague of mine and there it works.
            I assume it has something to do with my jabba setup. As he is using sdkman to manage different java versions.
            Following the related content of ~/.zshrc:

            [ -s "~/.jabba/jabba.sh" ] && source "~/.jabba/jabba.sh" 

            I think I will just switch to sdkman as well.

            pre-push hook:

            #!/bin/sh
            
            echo $SHELL       # prints "/bin/zsh"
            echo $JAVA_HOME   # prints "" (nothing)
            source ~/.zshrc
            echo $JAVA_HOME   # prints "~/.jabba/jdk/openjdk@1.11.0/Contents/Home" (full path instead of ~)
            
            set -e
            ##### KOTLINTER HOOK START #####
            ##### KOTLINTER 3.14.0 #####
            GRADLEW=***path-to-project***/gradlew
            if ! $GRADLEW lintBuildscripts lintKotlin ; then
                echo 1>&2 "\nlintBuildscripts & lintKotlin found problems, running formatBuildscripts & formatKotlin; commit the result and re-push"
                $GRADLEW formatBuildscripts formatKotlin
                exit 1
            fi
            ##### KOTLINTER HOOK END ##### 

             

             

            Jonas added a comment - Hey @Raman Sidarakin, We just tested on another machine of a colleague of mine and there it works. I assume it has something to do with my jabba setup. As he is using sdkman to manage different java versions. Following the related content of ~/.zshrc: [ -s "~/.jabba/jabba.sh" ] && source "~/.jabba/jabba.sh" I think I will just switch to sdkman as well. pre-push hook: #!/bin/sh echo $SHELL       # prints "/bin/zsh" echo $JAVA_HOME   # prints "" (nothing) source ~/.zshrc echo $JAVA_HOME   # prints "~/.jabba/jdk/openjdk@1.11.0/Contents/Home" (full path instead of ~) set -e ##### KOTLINTER HOOK START ##### ##### KOTLINTER 3.14.0 ##### GRADLEW=***path-to-project***/gradlew if ! $GRADLEW lintBuildscripts lintKotlin ; then     echo 1>&2 "\nlintBuildscripts & lintKotlin found problems, running formatBuildscripts & formatKotlin; commit the result and re-push"     $GRADLEW formatBuildscripts formatKotlin     exit 1 fi ##### KOTLINTER HOOK END #####    

            Hi, ba815226c72d 

            Starting from Sourcetree 4.2.3 configuration profiles for your current shell in the system should be loaded automatically by Sourcetree. Let's try to figure out what's may go wrong in your case.

            • You mentioned that when you are sourcing ~/.zshrc then your hook start working. Could you please check if `zsh` is configured as current shell in the system. Check output of this command in terminal: `echo $SHELL`. In case it's not `/bin/zsh` then you need to define your environment vars inside configuration profile that corresponds to configured shell. For example, if it /bin/bash, then you need to use `/.bashrc` file.
            • In case you determined that your shell is zsh, then could you please try to set `JAVA_HOME` explicitly inside your ~/.zshrc or ~/.zshenv file. You could add this line: 
              export JAVA_HOME=/your/path/to/java/home
            • Unlikely, but could you also check if your user has read permissions to "~/.zshrc" file.
            • In case nothing helped, then could you please describe actions what you are trying to do inside pre-push hook, so I'll try to reproduce the same issue on my machine. In addition you could provide entries from your ~/.zshrc that are related to java, if any.

            Thank you so much in advance.

            Raman Sidarakin (Inactive) added a comment - - edited Hi, ba815226c72d   Starting from Sourcetree 4.2.3 configuration profiles for your current shell in the system should be loaded automatically by Sourcetree. Let's try to figure out what's may go wrong in your case. You mentioned that when you are sourcing ~/.zshrc then your hook start working. Could you please check if `zsh` is configured as current shell in the system. Check output of this command in terminal: `echo $SHELL`. In case it's not `/bin/zsh` then you need to define your environment vars inside configuration profile that corresponds to configured shell. For example, if it /bin/bash, then you need to use `/.bashrc` file. In case you determined that your shell is zsh, then could you please try to set `JAVA_HOME` explicitly inside your ~/.zshrc or ~/.zshenv file. You could add this line:  export JAVA_HOME=/your/path/to/java/home Unlikely, but could you also check if your user has read permissions to "~/.zshrc" file. In case nothing helped, then could you please describe actions what you are trying to do inside pre-push hook, so I'll try to reproduce the same issue on my machine. In addition you could provide entries from your ~/.zshrc that are related to java, if any. Thank you so much in advance.

            remon added a comment -

            I also have 4.2.3 and the problem seems to be solved, at least on my computer it is, have not yet checked with coworkers.

            Thank you @Raman !!!!!

            remon added a comment - I also have 4.2.3 and the problem seems to be solved, at least on my computer it is, have not yet checked with coworkers. Thank you @Raman !!!!!

            Jonas added a comment - - edited

            I already have version 4.2.3 and still have this issue in our pre-push hook.
            In Sourcetree JAVA_HOME is not set - in the terminal it is.
            If I source ~/.zshrc in the hook it works.

            Let me know what I can test to help you get more relevant information.

            Jonas added a comment - - edited I already have version 4.2.3 and still have this issue in our pre-push hook. In Sourcetree JAVA_HOME is not set - in the terminal it is. If I source ~/.zshrc in the hook it works. Let me know what I can test to help you get more relevant information.

            Fixed in 4.2.3

            Arati Mohanty added a comment - Fixed in 4.2.3

            I've just upgraded to the 4.2.3 version and the changelog lists this bug as being fixed.

            I can confirm it's working on my machine!

            Enormous thanks to Raman and the Sourcetree team! 

            vedran.hrncic added a comment - I've just upgraded to the 4.2.3 version and the changelog lists this bug as being fixed. I can confirm it's working on my machine! Enormous thanks to Raman and the Sourcetree team! 

            Bump, no way is this a minor symptom severity. 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 - Bump, no way is this a minor symptom severity. We're being forced into moving away from Sourcetree because of this show stopper of a bug where githooks don't work.

            Hi, f8be79715b47
            Thanks for your comment.
            This ticket was marked as a low priority, because originally it was created with low priority. So, I've changed it to High.
            I understand, that this issue is important for you and some other people, but we also have another issues on plate, which are affecting a lot of users. I'm not telling, that this particular issue is not important, I'm telling, that this issue is not only one on our board.
            For now I see, that this issue is targeted to the next release and I hope we will be able to deliver fix for it in next Sourcetree release.

            Thank you.

            Raman Sidarakin (Inactive) added a comment - Hi, f8be79715b47 Thanks for your comment. This ticket was marked as a low priority, because originally it was created with low priority. So, I've changed it to High. I understand, that this issue is important for you and some other people, but we also have another issues on plate, which are affecting a lot of users. I'm not telling, that this particular issue is not important, I'm telling, that this issue is not only one on our board. For now I see, that this issue is targeted to the next release and I hope we will be able to deliver fix for it in next Sourcetree release. Thank you.

              43c951f935c6 Raman Sidarakin (Inactive)
              3fe25263d131 vrabac_266
              Affected customers:
              1 This affects my team
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: