-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable the use of environment variables in configuration #139
Comments
Hi @giggio : Thats true. We do not yet substitute envvars in the variable. But since we read in all Git config variables at startup anyway (we cache them) we could easily do a env substitute I guess on some relevant variables. Are you doing this because you manage your dotfiles? I do it with chezmoi here: |
See for a possible solution #141 |
Yes, that is exactly what I'm doing. GITHOOKS_RUNNER=$(git config githooks.runner | envsubst) But |
We'd still need to change the hook script, the |
Ah yeah correct. hm... The installer/updater at the moment will always overwrite the variables The fact that you want to change the
edit:: My thougth do not work I guess, since we need |
Could you use |
Regarding This is it: {
finalstr = $0
while (1) {
if (match(finalstr, /\$([A-Za-z0-9_]+)/)) {
newstr = substr(finalstr, 1, RSTART - 1)
newstr = newstr ENVIRON[substr(finalstr, RSTART + 1, RLENGTH - 1)]
newstr = newstr substr(finalstr, RSTART + RLENGTH)
finalstr = newstr
} else {
break
}
}
print finalstr
} We could add this (or a minimized version of it) to the default hooks script. |
Here is the full script: #!/usr/bin/env sh
# Read the runner script from the local/global or system config and expands environment variables
GITHOOKS_RUNNER=`git config githooks.runner | awk '{
finalstr = $0
while (1) {
if (match(finalstr, /\$([A-Za-z0-9_]+)/)) {
newstr = substr(finalstr, 1, RSTART - 1)
newstr = newstr ENVIRON[substr(finalstr, RSTART + 1, RLENGTH - 1)]
newstr = newstr substr(finalstr, RSTART + RLENGTH)
finalstr = newstr
} else {
break
}
}
print finalstr
}'`
if [ ! -x "$GITHOOKS_RUNNER" ]; then
echo "! Githooks runner points to a non existing location" >&2
echo " \`$GITHOOKS_RUNNER\`" >&2
echo " or it is not executable!" >&2
echo " Please run the Githooks install script again to fix it." >&2
exit 1
fi
exec "$GITHOOKS_RUNNER" "$0" "$@" |
Regarding the installer, yes, it is a problem that it keeps changing the values in .gitconfig. I'll open another issue about that. Opened: #142. |
If we use the above script (which expands environment variables) I believe we could close #141. What do you think? |
My main problem here is the variable expansion. I can't use it with the default This is another reason I opened #140, besides consistency. |
This is a good idea, it would simplify the configuration. You could make it extensible, e.g.: if a config has a relative path, use the prefix, if not use it as an absolute path. If it is not present, use a default. But, if you do that, you still need to change the hooks (the |
Ok. thanks for sharing the awk snippet. Honestly, I do not favor this approach. All this only to have environment variables subst in some config files:
if [ -z "$GITHOOKS_RUNNER" ]; then
GITHOOKS_RUNNER=$(git config githooks.runner)
fi inside the
|
That is what I'm looking for. |
Are you fine with having |
Yes, this should be enough. |
I just added to the issue, |
With the new 3.0 release I see a new property which needs to support environment variables: |
With version 3, I think the only ones needing env. support is: |
I commit my gitconfig, and, with the installation happening at $HOME, is creating a problema with the path.
I'd like to be able to use environment variable in config, like so:
The alias is already working. Setting it as
hooks = !\"$HOME/.githooks/bin/cli\"
already works.The text was updated successfully, but these errors were encountered: