Can't run `git` commands with Hazel

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Can't run `git` commands with Hazel Sun May 20, 2018 5:46 pm • by nikivi
I have a rule that runs a shell command that commits changes to a file and pushes them with Git. Here is how it looks:

Image


Whenever this rule gets ran, this error occurs in Console:

Code: Select all
2018-05-20 23:40:35.768 hazelworker[66330] websites.csv: Rule Auto commit (websites.csv) matched.
2018-05-20 23:40:36.743 hazelworker[66330] [Error] Shell script failed: Error processing shell script on file /Users/nikivi/dev/alfred/alfred-web-searches/workflow/websites.csv.



Basically Hazel fails to run the appropriate Git commands.

I am then forced to go to iTerm and `git push` the changes from there. In iTerm everything works perfectly and I also use Zsh there too.



In Hazel it fails. What can I do to make this work? This is my Git config for reference. I do sign my commits and my GitHub has 2FA.

Thank you very much for the help.
nikivi
 
Posts: 39
Joined: Tue Mar 08, 2016 10:04 am

Re: Can't run `git` commands with Hazel Mon May 21, 2018 10:41 am • by Mr_Noodle
To get script output in the logs, turn on debug logging as described here: https://www.noodlesoft.com/kb/hazel-debug-mode/

Also, it appears your script doesn't process any arguments, but instead is hardcoded to commit the readme file. Is that just for example or is that the intent of your script?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Can't run `git` commands with Hazel Mon May 21, 2018 12:27 pm • by nikivi
The entire script looks like this:

Image

The goal is to auto commit changes made to readme.md of this repo.

I activated the `Debug Mode` and here is the error I get in Console:

Code: Select all
 2018-05-21 18:24:27.121 hazelworker[82875] DEBUG: == script output ==
fatal: unable to access 'https://github.com/learn-anything/ios-apps.git/': SSL: can't load CA certificate file /bin/curl-ca-bundle.crt
[master eb94dd5] add app
 1 file changed, 1 insertion(+)
fatal: unable to access 'https://github.com/learn-anything/ios-apps.git/': SSL: can't load CA certificate file /bin/curl-ca-bundle.crt


The same commands work in my iTerm terminal. How can I make Hazel see the certificates and everything? I use Zsh as my shell if that matters and here are my dotfiles.
nikivi
 
Posts: 39
Joined: Tue Mar 08, 2016 10:04 am

Re: Can't run `git` commands with Hazel Mon May 21, 2018 2:57 pm • by Mr_Noodle
Note that scripts in Hazel are not run interactively and will not have environmental variables set. I think you need to set SSL_CERT_FILE though not sure what value it should have. Check the value in a shell where the script does work and use that.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Can't run `git` commands with Hazel Mon May 21, 2018 5:18 pm • by nikivi
Code: Select all
echo $SSL_CERT_FILE
returns nothing for me in Terminal.

Thing is that these exact commands worked before I added 2FA to GitHub. I wonder if maybe I should stop using 2FA on GitHub just to have the commands work. I really relied on these Hazel rules.

I don't really know which environment variables I need to set to be honest. :(
nikivi
 
Posts: 39
Joined: Tue Mar 08, 2016 10:04 am

Re: Can't run `git` commands with Hazel Tue May 22, 2018 10:40 am • by Mr_Noodle
You may want to try disabling 2FA temporarily to see if it works. Not sure how that affects things but it's worth looking into.

You can try the 'printenv' command to print out your environment variables. I don't now which ones will be relevant so you will have to experiment a bit.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Can't run `git` commands with Hazel Tue May 22, 2018 1:07 pm • by nikivi
Solved it with:

Code: Select all
export USER=nikitavoloboev
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
   . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
git add readme.md
git commit -m "add subreddit"
git push


I am using Nix package manager and needed to use the Git programme installed by Nix it seemed.
nikivi
 
Posts: 39
Joined: Tue Mar 08, 2016 10:04 am


Return to Support