git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git appears to ignore GIT_CONFIG environment variable
@ 2018-11-02  1:32 Sirio Balmelli
  2018-11-02  3:07 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Sirio Balmelli @ 2018-11-02  1:32 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 2014 bytes --]

It appears that git ignores the GIT_CONFIG environment variable, while git-config *does* consider it.

I have written a short script that shows this in detail and reproduces, it is included below and also posted on github at https://github.com/siriobalmelli/toolbench/blob/master/git/git-env-check.sh
This behavior is confirmed in 2.17.1, 2.18.0 and 2.19.1

I have tried to google this but don’t see any references to GIT_CONFIG outside of the git-config manual.
Is it intended behavior that this environment variable is only valid with git-config?

Thank you very much,

Sirio

—

#!/bin/bash
# this script demonstrates that the GIT_CONFIG is used by 'git-config'
# but *not* by 'git' itself.
# 2018 Sirio Balmelli

cleanup()
{
rm -rf ~/.gitconfig git-env-check
}

fail()
{
	echo "$*" >&2
	cleanup
	exit 1
}

# don't break the user's config
if [[ -e ~/.gitconfig ]]; then
	# don't fail, deleting ~/.gitconfig, for obvious reasons
	echo "this script would break your existing ~/.gitconfig - please remove it and run again" >&2
	exit 1
fi

unset GIT_CONFIG
git config -l | grep -q alias.he=help \
	&& fail "alias 'he' already set, can't use it for this test" \
	|| echo "1. the alias 'he' is unset by default"

echo "2. write a gitconfig in a non-standard location; export to GIT_CONFIG:"
mkdir git-env-check
cat <<EOF | tee git-env-check/gitconfig
[alias]
  he = help
EOF
export GIT_CONFIG=$(realpath git-env-check/gitconfig)
env | grep GIT_CONFIG

git config -l | grep -q alias.he=help \
	|| fail "unexpected: git-config doesn't see GIT_CONFIG" \
	&& echo "3. git-config DID see 'he' from GIT_CONFIG"

git he \
	&& fail "git does see GIT_CONFIG: please ignore this report" \
	|| echo "4. git, however, did NOT see 'he'"

ln -s $GIT_CONFIG ~/.gitconfig
git he >/dev/null \
	|| fail "unexpected: git also ignores ~/.gitconfig" \
	&& echo "5. git DOES see 'he' if conf is linked to '~/.gitconfig'"

echo "6. this was $(git --version)"
cleanup


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 874 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git appears to ignore GIT_CONFIG environment variable
  2018-11-02  1:32 git appears to ignore GIT_CONFIG environment variable Sirio Balmelli
@ 2018-11-02  3:07 ` Junio C Hamano
  2018-11-03 17:58   ` Sirio Balmelli
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2018-11-02  3:07 UTC (permalink / raw)
  To: Sirio Balmelli; +Cc: git

Sirio Balmelli <sirio.bm@gmail.com> writes:

> It appears that git ignores the GIT_CONFIG environment variable,
> while git-config *does* consider it.

Yup, that is exactly how it is designed and documented.  These
dasys, with "git config" taking "--file" to work on any arbitrary
filename, you do not necessarily need GIT_CONFIG enviornment.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git appears to ignore GIT_CONFIG environment variable
  2018-11-02  3:07 ` Junio C Hamano
@ 2018-11-03 17:58   ` Sirio Balmelli
  0 siblings, 0 replies; 3+ messages in thread
From: Sirio Balmelli @ 2018-11-03 17:58 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

Thank you very much, I appreciate the answer :)

best,

Sirio

> On Nov 2, 2018, at 04:07, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Sirio Balmelli <sirio.bm@gmail.com> writes:
> 
>> It appears that git ignores the GIT_CONFIG environment variable,
>> while git-config *does* consider it.
> 
> Yup, that is exactly how it is designed and documented.  These
> dasys, with "git config" taking "--file" to work on any arbitrary
> filename, you do not necessarily need GIT_CONFIG enviornment.
> 


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 874 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-03 17:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-02  1:32 git appears to ignore GIT_CONFIG environment variable Sirio Balmelli
2018-11-02  3:07 ` Junio C Hamano
2018-11-03 17:58   ` Sirio Balmelli

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).