Home > Software design >  Git includeIf GIT_AUTHOR_NAME set to my name
Git includeIf GIT_AUTHOR_NAME set to my name

Time:10-20

I'm working on a joint account with some other users, but would like to use my own .gitconfig. I use SendEnv with SSH to send GIT_AUTHOR_NAME among other things and my idea is that I would like to use this to only source my gitconfig if my name is contained in that variable.

What I've tried so far is to use includeIf

[includeIf "hasconfig:author.name:My Name"]
    path = ~/my_name/.gitconfig

however, either hasconfig isn't available in git 2.27.0 (which is the version I'm using) or this fails because of another reason.

There is also to possibility of using

if [[ "$GIT_AUTHOR_NAME" == "My Name" ]]; then
    . ~/my_name/.bashrc
fi

in the joint .bashrc and then taking care of it in my .bashrc.

But using GIT_CONFIG environment variable seem to only work with the git config command. If that still worked for all commands it would have been the best solution for me.

I have seen a suggestion of creating an alias

alias git="HOME=~/my_name command git"

and that is the best one I've seen so far, but I don't like that solution particularly much.

Is it possible to query environment variables in an includeIf expression? Or is there some other approach to include if GIT_AUTHOR_NAME is set to a specific variable?

CodePudding user response:

First, hasconfig was in fact new in Git 2.36.0 (see the release notes). Second, includeIf.hasconfig:remote.*.url:... only works for remote URLs (see the same release notes and the accompanying updated documentation). This means even if you update your Git version, you won't be able to test author.name here.

Is it possible to query environment variables in an includeIf expression?

Not in general, no.

CodePudding user response:

Rather than have Git do logic on the environment, just set it up as you like. You can set the $HOME and $XDG_* vars to your customized-to-you-personally environment and everything will Just Work. Start with $XDG_CONFIG_HOME, put git/config there and it's your personal git config. XDG vars.

  • Related