threads / bug / 57192

Git bug report git remote get-url

Subject: Git bug report git remote get-url

## tl;dr

2 messages between Jan 5, 2022 and Jan 6, 2022.

replies: 1people: 2as markdown or json

Nanekrangsan, Sucheela (NYC-GIS)· Jan 5, 2022, 17:22 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
1. I put [remote] entries in /etc/gitconfig
2. `git config --get remote.xxx.url` returns the correct URL. I can `git pull` from this remote.
3. `git remote get-url xxx` returns "error: No such remote 'xxx'"
4. After `git remote add xxx`, I can get the URL from `git remote get-url`.
What did you expect to happen? (Expected behavior)
I expected `git-remote get-url` to give me the URL I added in /etc/gitconfig. 

What happened instead? (Actual behavior) `git remote get-url` did not recognize the report I added in /etc/gitconfig.

What's different between what you expected and what actually happened? I expected the URL from /etc/gitconfig from `git remote get-url` but got error.

Anything else you want to add: These give me the correct results `git config --get remote.xxx.url` `git ls-remote --get-url xxx`

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.34.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 3.10.0-1160.49.1.el7.x86_64 #1 SMP Tue Nov 30 15:51:32 UTC 2021 x86_64 compiler info: gnuc: 4.8 libc info: glibc: 2.17 $SHELL (typically, interactive shell): /bin/bash

This message contains information which may be confidential and privileged. Unless you are the intended recipient (or authorized to receive this message for the intended recipient), you may not use, copy, disseminate or disclose to anyone the message or any information contained in the message.  If you have received the message in error, please advise the sender by reply e-mail, and delete the message.  Thank you very much.
Taylor Blau· Jan 6, 2022, 00:22 UTC · re: Nanekrangsan, Sucheela (NYC-GIS) · lore

Re: Git bug report git remote get-url

On Wed, Jan 05, 2022 at 05:22:06PM +0000, Nanekrangsan, Sucheela (NYC-GIS) wrote:
Show 5 quoted lines
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)
> 1. I put [remote] entries in /etc/gitconfig
This is almost certainly the culprit.

`git remote get-url` doesn't output anything (except the error message included in your report) when `remote->configured_in_repo` is zero. Indeed, looking at remote.c:handle_config() where we actually add a new remote:

    remote = make_remote(remote_state, name, namelen);
    remote->origin = REMOTE_CONFIG;
    if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
        current_config_scope() == CONFIG_SCOPE_WORKTREE)
            remote->configured_in_repo = 1;

we only set configured_in_repo when we're looking at local or worktree configuration. Since $(prefix)/etc/gitconfig isn't either of those, we'll avoid setting configured_in_repo, hence we'll end up inside of this if-statement in builtin/remote.c:get_url():

    remote = remote_get(remotename);
    if (!remote_is_configured(remote, 1)) {
            error(_("No such remote '%s'"), remotename);
            exit(2);
    }
...producing the error message in your report.
> 4. After `git remote add xxx`, I can get the URL from `git remote get-url`.

This makes sense, since `git remote add` will configure the remote `xxx` in your repository-local configuration, not the system-wide one.

Thanks, Taylor

← back to recent threads