git config вместо этого не работает без --global для локального репозитория - PullRequest
0 голосов
/ 02 апреля 2020

Этот вопрос уже задавался ранее на git config --global вместо для проекта, а не глобального , но принятое решение не работает для меня.

# Random directory

$ pwd
$ /tmp/nwani_1585850170


# Now, a local repo

$ git init
Initialized empty Git repository in /tmp/nwani_1585850170/.git/


# Pretty modern git (as of April, 2020)

$ git --version
git version 2.21.1


# Don't have any existing config

$ git config --list | grep url


# Let's configure the insteadOf thingy for the local repo:

$ git config url."ssh://".insteadOf "https://"


# Verify that it indeed got added:

$ git config --list | grep url
url.ssh://.insteadof=https://


# Yes, it is in the local config

$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[url "ssh://"]
    insteadOf = https://


# Check if it works? Spoiler alert: It doesn't!

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone --progress --verbose https://domain.doesnt.exist/blah
13:57:17.426161 git.c:419               trace: built-in: git clone --progress --verbose https://domain.doesnt.exist/blah
Cloning into 'blah'...
13:57:17.427962 run-command.c:643       trace: run_command: git-remote-https origin https://domain.doesnt.exist/blah
* Couldn't find host domain.doesnt.exist in the .netrc file; using defaults
*   Trying 92.242.140.21:443...
* TCP_NODELAY set
^C


# As one can see in the trace above, it runs the command git-remote-https, so it didn't honor the insteadOf thingy.


# Now let's make the config global:

$ git config --global url."ssh://".insteadOf "https://"


# Let's try it now. Spoiler alert: It works!

GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone --progress --verbose https://domain.doesnt.exist/blah
13:57:48.910586 git.c:419               trace: built-in: git clone --progress --verbose https://domain.doesnt.exist/blah
Cloning into 'blah'...
13:57:48.912966 run-command.c:643       trace: run_command: unset GIT_DIR; ssh domain.doesnt.exist 'git-upload-pack '\''/blah'\'''
^C

# As one can see, now it is using the ssh command

Итак, мой запрос: Как мне заставить git соблюдать мою локальную insteadOf конфигурацию?

1 Ответ

2 голосов
/ 02 апреля 2020

git clone определенно не подчиняется локальной конфигурации - для клонирования пока нет локальной конфигурации, только глобальная. Попробуйте что-нибудь, что использует локальный конфиг; git fetch/pull/push например:

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 git fetch https://domain.doesnt.exist/blah master
22:21:01.075552 git.c:371               trace: built-in: git 'fetch' 'https://domain.doesnt.exist/blah' 'master'
22:21:01.076706 run-command.c:350       trace: run_command: 'ssh' 'domain.doesnt.exist' 'git-upload-pack '\''/blah'\'''
ssh: Could not resolve hostname domain.doesnt.exist: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Если вы хотите использовать url.insteadOf для clone без его глобальной настройки, вы можете передать значение конфигурации в командной строке:

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 git -c url.ssh://.insteadof=https:// clone --verbose https://domain.doesnt.exist/blah
22:25:33.588762 git.c:371               trace: built-in: git 'clone' '--verbose' 'https://domain.doesnt.exist/blah'
Cloning into 'blah'...
22:25:33.596631 run-command.c:350       trace: run_command: 'ssh' 'domain.doesnt.exist' 'git-upload-pack '\''/blah'\'''
ssh: Could not resolve hostname domain.doesnt.exist: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...