I am using Fish shell [1] and Direnv [2], and are having issues with variable scope when using Git aliases.

For example in my config.fish [3] I have a global environment variable e.g. $GIT_MY_EMAIL:

set -xg GIT_MY_EMAIL ola@example.com

and a function that uses this git-claim.fish [4]:

function git-claim
   git config user.email $GIT_MY_EMAIL
end

I have a git alias in .gitconfig[5] to call this:

[alias]
  claim = "!fish -c git-claim"

In a sub folder I have an .envrc that overrides the global variable:

export GIT_MY_EMAIL=work-ola@example.org

Inside this sub folder whenever I call this git command it does not use the Direnv environment variable.

git claim; and git config user.email

The output is:

ola@example.com 

However calling the git-claim fish function directly works fine:

git-claim; and git config user.email 

Then the output is:

work-ola@example.org 

I presume the Git alias is not dynamically using my local scope?

  • I realise the root cause is that git config does not support environment variable expansions[1], and that I fork another fish session to overcome this. But I hoped there might be a way round to pass on the local fish variable scope into the alias. * [1] (stackoverflow.com/questions/11262010/…) – flurdy Nov 1 '17 at 14:45

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.