git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Git credential-cache manager is not treating `path=` correctly
@ 2023-08-23 16:23 Gabriel Nützi
  2023-08-23 19:22 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Nützi @ 2023-08-23 16:23 UTC (permalink / raw)
  To: git@vger.kernel.org

I report this potential bug:
https://stackoverflow.com/questions/76963207/git-credential-cache-does-not-matchpath-correctly

I really dont get Git `2.41.0` and its crude `git credential-cache` manager:

When I test `git credential-cache` with the below script (`setsid test.sh`).
if it can report 3 different passwords it will fail with

```
fatal: could not read Username for
'https://www.server.com/repos/1.git': No such device or address
```
on the first run,
and when the script runs **a second time** it will pass happily.

The `git credential-store` on the other hand does not work at all and
on the first `git credential fill` prompt the user.

**Question: What is going on here. This makes no sense and results in
peculiar fails on CI**

*Note: setsid is to detach from the controlling terminal that git does
not prompt or something.*
*Note: We need `useHttpPath=true` to tell Git to use the `path` in
credential `fill` statements (AFAIK).


```shell
#!/bin/bash
set -e
# set -x
# IMPORTANT: =======================================
# Execute this script inside a container
# and check if it reports all password correctly
#
# ==================================================

# git credential-cache exit || true

git config --global --unset-all credential.helper || true
git config --global --add credential.helper ""
# git config --global --add credential.helper "store" # Does not work at all.
git config --global --add credential.helper "cache --timeout=7200"

git config --global
"credential.https://www.server.com/repos/1.git.useHttpPath" true
git config --global
"credential.https://www.server.com/repos/2.git.useHttpPath" true

export GIT_TRACE=1

# Add 3 credentials, 2 specifics with `path=`
# 1 with general host.
{
    echo "protocol=https"
    echo "host=www.server.com"
    echo "path=repos/1.git"
    echo "username=banana"
    echo "password=banana1"
} | git credential approve

{
    echo "protocol=https"
    echo "host=www.server.com"
    echo "path=repos/2.git"
    echo "username=banana"
    echo "password=banana2"
} | git credential approve

{
    echo "protocol=https"
    echo "host=www.server.com"
    echo "username=banana"
    echo "password=general"
} | git credential approve

echo "Check the credentials"
# Check it
{
    echo "protocol=https"
    echo "host=www.server.com"
    echo "path=repos/1.git"
} | git credential fill | grep -q "password=banana1" || {
    echo "wrong pass banana1"
    exit 1
}

{
    echo "protocol=https"
    echo "host=www.server.com"
    echo "path=repos/2.git"
} | git credential fill | grep -q "password=banana2" || {
    echo "wrong pass banana2"
    exit 1
}

{
    echo "protocol=https"
    echo "host=www.server.com"
} | git credential fill | grep -q "password=general" || {
    echo "wrong pass general"
    exit 1
}

echo "all passwords correctly reported"
```

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

end of thread, other threads:[~2023-08-24 14:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-23 16:23 Git credential-cache manager is not treating `path=` correctly Gabriel Nützi
2023-08-23 19:22 ` Jeff King
2023-08-23 21:02   ` Ganriel Nützi
2023-08-24 14:44     ` Jeff King

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 NNTP newsgroup(s).