0
Completed

MacOS - use login shell (with profile) to run all Git commands

Ben Gould 1 week ago updated by Daniel Siegl yesterday at 1:45 a.m. 9

I had an issue with a new customer's project where there were pre-commit hooks that needed the login shell to run.

As such I was unable to commit the change via smartgit and had to commit via the command line git.

What was the hook?  An eslint operation that needed the nvm default nodejs for the project (18) as that's how we manage node versions.

Since the login shell was not invoked, nvm didn't setup its default version, and thus the pre-commit hook failed.

Answer

Answer

I tried what Thomas sugested - I hope this helps.

From zsh you can open SmartGit via:

open -n /Applications/SmartGit.app

Hi

Just to clarify:

* we are not talking about an interactive pre-commit hook

* the problem is that the shell context that is used to run the precommit hook is not aware of the environment variables required to finish the task

Did I understand it?

Cheers

Daniel

Yes, the environment has not been picked up.  It is not interactive, just a linter.  I think you need 'login' instead of 'zsh' to bring the environment in to the pre-commit hook.

Ok - I am not a Mac expert - but I would use the same way that I use to do precommit logic in powershell but use "zsh" instead of powershell:

#!/bin/sh
echo 
exec powershell.exe -ExecutionPolicy RemoteSigned -File '.\pre-commit.ps1'
exit


https://blog.nimblepros.com/blogs/setting-up-pre-commit-git-hook-on-windows-with-powershell/

Well I am not the author on this repository!  Developers work on linux and mac, mostly mac.  So the pre-commit hook starts with #!/bin/sh.  I am not sure if you just go ahead and execute this, or if you first start up the users shell to execute this.

Obviously, with my environment set, I can go ahead and run the commit in terminal.  However, SmartGit doesn't have this environment so can't.

/usr/bin/login won't work, so please ignore that suggestion.

It could be that this is not an issue you can fix in smartgit.

Both linux and Windows will pick up the environment variables in the normal way always at first login.  Mac doesn't work this way, so this could be a more general Mac issue.  Mac only picks up environment variables when the shell is invoked as a login shell, by Terminal.app.  Mac software applications, like SmartGit, have a tiny default environment.

+1

According to my knowledge Windows behaves differently than Linux/MacOS. While Windows has a central place to configure environment variables, those on Linux/MacOS usually are configured in some shell scripts. But when launching a Linux/MacOS GUI application from its icon, those shell scripts are not executed and hence have a different environment. A quick workaround would be to start SmartGit from such a shell instead of starting it from the GUI icon.

Answer

I tried what Thomas sugested - I hope this helps.

From zsh you can open SmartGit via:

open -n /Applications/SmartGit.app

+1

Works for me, please close the issue.  Thanks again.