# gitconfig - interaction between credential.helper and includeIf

3 messages from 2024-06-25 to 2024-06-25. Participants: Ryan Vu, Jeff King.
Thread: https://gitlist.dev/t/61678

## Ryan Vu, 2024-06-25 05:59

Subject: gitconfig - interaction between credential.helper and includeIf
Message-ID: <CAF4erGWF+Lx=K09yFhd_abC2M5b5Ab0vM2uehkdVmridmsHqDg@mail.gmail.com>
URL: https://gitlist.dev/e/CAF4erGWF%2BLx%3DK09yFhd_abC2M5b5Ab0vM2uehkdVmridmsHqDg%40mail.gmail.com

```
What did you do before the bug happened? (Steps to reproduce your issue)

I created the following files:

ˋˋˋ ~/workspace/.gitconfig-workspace
[credential]
    helper = store --file ~/workspace/.git-credentials-workspace
ˋˋˋ

ˋˋˋ ~/.gitconfig
[credential]
    helper = store
[includeIf "gitdir:~/workspace/"]
    path = ~/workspace/.gitconfig-workspace
ˋˋˋ

I then tried to use my credentials in a repository under `~/workspace`.

What did you expect to happen? (Expected behavior)

I expected that within `~/workspace`, the credential file would be
`~/workspace/.git-credentials-workspace`.

I expected that outside `~/workspace`, the credential file would be
`~/.git-credentials`.

The two `.git-credentials*` files have different credentials to the same URL.

What happened instead? (Actual behavior)

The credentials within file `~/workspace/.git-credentials-workspace`
are not being properly applied for repositories within `~/workspace`.

What's different between what you expected and what actually happened?

I expected that `~/.git-credentials` and
`~/workspace/.git-credentials-workspace` would be isolated from each
other. But there are interactions even though `includeIf` was used.

Anything else you want to add:

The following configuration works:

ˋˋˋ ~/.gitconfig
[credential]
    helper = store
[includeIf "gitdir:~/workspace/"]
    path = ~/workspace/.gitconfig-workspace
[includeIf "gitdir:~/another-workspace/"]
    path = ~/another-workspace/.gitconfig-another-workspace
ˋˋˋ

ˋˋˋ ~/another-workspace/.gitconfig-another-workspace
[credential]
    helper = store --file ~/another-workspace/.git-credentials-another-workspace
ˋˋˋ

This is not ideal as repositories must be contained within these
enumerated paths.


This configuration has unexpected behavior:

ˋˋˋ ~/.gitconfig
[includeIf "gitdir:~/workspace/"]
    path = ~/workspace/.gitconfig-workspace
[credential]
    helper = store
ˋˋˋ

The credential in `~/workspace/.git-credentials-workspace` will be
accessed and then stored into `~/.git-credentials`. Git is interacting
with both files.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.

[System Info]
git version:
git version 2.45.2
cpu: arm64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:12:58
PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64
compiler info: clang: 15.0.0 (clang-1500.3.9.4)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh


[Enabled Hooks]

```

## Jeff King, 2024-06-25 13:20

Subject: Re: gitconfig - interaction between credential.helper and includeIf
Message-ID: <20240625132001.GA535756@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20240625132001.GA535756%40coredump.intra.peff.net
In-Reply-To: <CAF4erGWF+Lx=K09yFhd_abC2M5b5Ab0vM2uehkdVmridmsHqDg@mail.gmail.com>

```
On Mon, Jun 24, 2024 at 10:59:33PM -0700, Ryan Vu wrote:

> I created the following files:
> 
> ˋˋˋ ~/workspace/.gitconfig-workspace
> [credential]
>     helper = store --file ~/workspace/.git-credentials-workspace
> ˋˋˋ
> 
> ˋˋˋ ~/.gitconfig
> [credential]
>     helper = store
> [includeIf "gitdir:~/workspace/"]
>     path = ~/workspace/.gitconfig-workspace
> ˋˋˋ

credential.helper is a multi-valued config key that forms a list, and
Git will try each one in sequence. So in your ~/workspace repositories,
you've configured _two_ helpers: a vanilla "store" and one with the
--file option.

You can reset the list with an empty string. So putting:

  [credential]
  helper =
  helper = store --file ~/workspace/.git-credentials-workspace

in your .gitconfig-workspace would do what you want.

-Peff

```

## Ryan Vu, 2024-06-25 16:53

Subject: Re: gitconfig - interaction between credential.helper and includeIf
Message-ID: <CAF4erGXkP3AR3dNvsqmo5FBLxOaGZhd9pHCHKsL8Q0BV5BiKJA@mail.gmail.com>
URL: https://gitlist.dev/e/CAF4erGXkP3AR3dNvsqmo5FBLxOaGZhd9pHCHKsL8Q0BV5BiKJA%40mail.gmail.com
In-Reply-To: <20240625132001.GA535756@coredump.intra.peff.net>

```
Thank you! I have the configurations working now.

On Tue, Jun 25, 2024 at 6:20 AM Jeff King <peff@peff.net> wrote:
>
> On Mon, Jun 24, 2024 at 10:59:33PM -0700, Ryan Vu wrote:
>
> > I created the following files:
> >
> > ˋˋˋ ~/workspace/.gitconfig-workspace
> > [credential]
> >     helper = store --file ~/workspace/.git-credentials-workspace
> > ˋˋˋ
> >
> > ˋˋˋ ~/.gitconfig
> > [credential]
> >     helper = store
> > [includeIf "gitdir:~/workspace/"]
> >     path = ~/workspace/.gitconfig-workspace
> > ˋˋˋ
>
> credential.helper is a multi-valued config key that forms a list, and
> Git will try each one in sequence. So in your ~/workspace repositories,
> you've configured _two_ helpers: a vanilla "store" and one with the
> --file option.
>
> You can reset the list with an empty string. So putting:
>
>   [credential]
>   helper =
>   helper = store --file ~/workspace/.git-credentials-workspace
>
> in your .gitconfig-workspace would do what you want.
>
> -Peff

```
