in GitKraken, git environment variable not set in commit hooks
Asked Answered
A

2

8

I'm trying to use a commit hook that runs eslint. To hook uses GIT_DIR to find the package local eslint and related eslint configs. Like this:

ESLINT_PATH="${GIT_DIR}/../node_modules/.bin/eslint"

From the command line, this works fine. GIT_DIR is set and everybody is happy. In GitKraken though, GIT_DIR is missing. In fact, no git environment vars are set. I ran env in the hook and looked at the output.

Is this normal behavior for GitKraken? Is there some hidden config that I'm missing?

I can mod the script, so if there's a more "proper" way to do this, I'm all ears.

Aurlie answered 7/6, 2017 at 16:8 Comment(0)
G
3

I know this is a bit late to the party, but I just ran into a similar issue, and I hope this will help any future inquires.

This information is accurate for GitKraken 4.2.2, as I have not tested this with a newer version.

GitKraken does not actually use Git. It works exactly like Git, yes, but it doesn't actually require Git to be installed on your system. As per the main GitKraken download page here:

It works directly with your repositories with no dependencies—you don’t even need to have Git installed on your system. GitKraken is built with NodeGit, a Git framework that is primarily developed and maintained by members of the GitKraken development team.

As such, adding the Git hooks feature, to begin with, was (according to the GitKraken team) challenging. From the "April 3, 2017 2.3.0 Release Notes":

Git hooks! One thing that has prevented some users and teams from being able to adopt GitKraken is the lack of Git hooks support. Until today! You can now create custom scripts that fire off at certain points during Git processes. GitKraken does not require that you install Git on your system, so until now, that independence had meant no Git hooks support. But, with a lot of blood, sweat and tears, v2.3 allows you to hook your way to a bounty of control over your Git actions!

So, you won't be able to use Git environment variables since "regular" Git isn't actually being used under the hood.

In fact, a lot of the more complicated Git features won't necessarily be supported unless specifically mentioned.

Glamour answered 27/4, 2020 at 20:44 Comment(0)
S
0

Gitkraken now includes a terminal, I cannot recall when it was introduced, but it can be accessed via the View menu (View -> Show Terminal Panel). Executing a commit command as follows:

export MY_ENV_VAR="some value" && git commit -m "my commit message" 

allowed my pre-commit hook to see the environment variable, solving the issue for me.

Seigel answered 4/8, 2022 at 11:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.