Skip to content

failed to add remote gh repo fork --remote #6975

Description

@jaraco

Recent releases of gh have stopped working for creating forks in Github:

 draft $ gh --version
gh version 2.22.1 (2023-01-27)
https://github.com/cli/cli/releases/tag/v2.22.1
 draft $ git clone gh://indygreg/PyOxidizer
Cloning into 'PyOxidizer'...
remote: Enumerating objects: 52248, done.
remote: Counting objects: 100% (2953/2953), done.
remote: Compressing objects: 100% (1135/1135), done.
remote: Total 52248 (delta 1901), reused 2649 (delta 1807), pack-reused 49295
Receiving objects: 100% (52248/52248), 12.13 MiB | 5.38 MiB/s, done.
Resolving deltas: 100% (38619/38619), done.
 draft $ cd PyOxidizer
 PyOxidizer main $ gh repo fork --remote
✓ Created fork jaraco/PyOxidizer
failed to add remote: failed to run git: fatal: remote error: access denied or repository not exported: /a/nw/a5/dc/17/196697507/598155908.git
error: Could not fetch origin

 PyOxidizer main $ gh repo fork --remote
X No default remote repository has been set for this directory.

unable to determine base repository: please run `gh repo set-default` to select a default remote repository.

The first attempt fails with access denied or repository not exported.

This command used to work on older gh versions.

Activity

  1. jaraco commented on Feb 6, 2023

    @jaraco
    Author

    If the fork already exists, the command runs fine on a clean checkout. I suspect there's a race between creating the fork and querying it.

  2. mislav commented on Feb 6, 2023

    @mislav
    Contributor

    Thanks for reporting! We have determined that this happens because we sometimes try to immediately fetch git objects when adding a git remote, but the objects might not be ready yet:

    cli/git/client.go

    Lines 460 to 465 in 79a1be4

    func (c *Client) AddRemote(ctx context.Context, name, urlStr string, trackingBranches []string, mods ...CommandModifier) (*Remote, error) {
    args := []string{"remote", "add"}
    for _, branch := range trackingBranches {
    args = append(args, "-t", branch)
    }
    args = append(args, "-f", name, urlStr)

    The solution would be to stop fetching implicitly on AddRemote and instead fetch only when needed. /cc @samcoe

  3. added
    priority-2Affects more than a few users but doesn't prevent core functions
    and removed on Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority-2Affects more than a few users but doesn't prevent core functions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions