Bug 14841 - support/download/git fails with "fatal: No such remote 'origin'" due to incorrect check for origin remote
Summary: support/download/git fails with "fatal: No such remote 'origin'" due to incor...
Status: RESOLVED FIXED
Alias: None
Product: buildroot
Classification: Unclassified
Component: Other (show other bugs)
Version: 2020.02.10
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-10 23:57 UTC by bmurdock
Modified: 2024-06-15 15:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bmurdock 2022-06-10 23:57:55 UTC
The git script does the following:

- initializes a git repo
- checks if the remote named origin exists
- if it exists, it call git remote set-url to set the correct url for the origin remote

The problem is, it uses the command 'git remote | grep '^origin$'' to check if origin exists.  This command always prints the word origin, even if the origin remote doesn't actually exist in the repo.  It's unfortunate, but that's how git works.  On a brand new git repo, origin does not exist, but this part of the script believes it does exist, so it calls git remote set-url which then fails because origin doesn't exist.

In my project I noticed two packages, flashbench and mmc_utils that use the git download method and it fails for both of them.  The packages still succeed because they fallback to a different download method.  I can imagine that's one reason why this has not been noticed.

You will also not see this error if the git repo already exists with an actual origin remote that has been configured.

The proper way to check if origin exists is to do this:

if ! git config remote.origin.url | /dev/null; then...

I have a patch for this and I will work on sending it to the mailing list.
Comment 1 bmurdock 2022-06-10 23:59:07 UTC
I checked latest master in the buildroot git repo and it appears this bug is still present there too.
Comment 2 Yann E. MORIN 2022-06-14 19:55:59 UTC
Hello,

Thanks for the report.

I'll be quoting what Edgar explained on the mailing list [0]:

---
I cannot reproduce this. My copy of git does not print “origin” if there
is no remote named such:

    $ git --version
    git version 2.25.1
    $ git init foo
    Initialized empty Git repository in /home/edgar/foo/.git/
    $ cd foo/
    $ git remote | grep '^origin$'
    $     # <- empty output

I also tried with both a quite old and a fairly recent version of git
(2.11.0 from Debian Stretch and 2.35.1 from Debian Testing) with the
same result.
---

I also tried the same as Edgar, and I too can't reproduce.

Can you provide more information, please?

[0] https://lore.kernel.org/buildroot/acae6f60-f71c-76fe-b9fe-0779d758c1c0@grenoble.cnrs.fr/T/#t

Regards,
Yann E. MORIN.
Comment 3 Yann E. MORIN 2022-07-30 19:55:28 UTC
Hello,

We did not get feedback, or more explanations about your issue, and
there are two people that reported that the case you described did
in fact work as expected.

So we're clodsing this issue report. Feel free to reopen with more
information if you still have the issue.

Regards,
Yann E. MORIN.
Comment 4 Emil Medve 2022-10-24 20:09:42 UTC
Newer versions of `git` will expose this issue:

```bash
$ git --version
git version 2.37.2
$ git init
Initialized empty Git repository in .../.git/
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
$ git remote -v
origin
```
Comment 5 Yann E. MORIN 2024-06-15 15:03:12 UTC
Thank you for your report.

The issue tracker for the Buildroot project has been moved to
the Gitlab.com issue tracker:
    https://gitlab.com/buildroot.org/buildroot/-/issues

We are taking this opportunity to close old issues in this old
tracker. If you believe your issue is still relevant, please
open one in the new issue tracker.

Thank you!