Sublime Forum

How to Set Environment Var for Git

#1

When I commit from within Sublime Merge it fails…

The failure is due to a precommit hook which uses an environment variable which Sublime Merge does not know. The commit works when I try directly on CLI.

Here is a portion of the precommit…

cd $SOME_ENV_VAR/tests

How can I set an environment variable in Sublime Merge?

0 Likes

Issue when working with a repo with Overcommit installed
#2

Merge should be inheriting the environment of the process that launches it, I would think. What OS are you on?

Windows, applications always get a copy of the global environment.

Linux applications inherit the environment of their parent, which would be the launcher task of your window manager, or the environment that’s current in your shell if you launch applications from the Terminal.

On MacOS applications have a constrained environment on purpose, which is inherited from the application launcher; the launcher does not share the full environment.

For this reason, on MacOS Sublime Text will launch a shell behind the scenes and gather the environment, I would assume that Merge does the same thing, though I can’t verify that at the moment.

0 Likes

#3

I am using MacOS.

0 Likes

#4

Do you get a different result if you start Merge from a terminal (while it’s not running) versus starting it from the launcher?

0 Likes

#5

Launching from command line works! Thanks.

For the record I setup running from the command line like this…

# Do once...
> ln -sv "/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge" /usr/local/bin/smerge

# Then can do...
> smerge
0 Likes

#6

If that works, then something to investigate is if the environment variables you expect to be present are set in .zshrc or in .zprofile, and move them to .zprofile if that’s not where they are.

If that’s the case, swapping that location should let you launch from the dock and still have things work.

1 Like

#7

Also potentially helpful:

0 Likes