Repository navigation
Add repo_default_remote config option - #12044
friederbluemle wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new configuration option repo_default_remote that allows users to specify a default remote name for repository operations. When no per-repo resolution is already present (via --repo, GH_REPO, or gh repo set-default), the system will fall back to using the configured default remote name.
Key Changes:
- Added
repo_default_remoteconfiguration key that accepts a remote name as its value - Modified
SmartBaseRepoFuncto check for this configuration and use the named remote when no other resolution exists - Added comprehensive test coverage for the new fallback behavior
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/config/config.go | Adds the repoDefaultRemote configuration key constant and implements the RepoDefaultRemote method to retrieve it |
| internal/gh/gh.go | Defines the RepoDefaultRemote interface method for the Config interface |
| internal/gh/mock/config.go | Adds mock implementation of RepoDefaultRemote method for testing |
| pkg/cmd/factory/default.go | Implements the logic to use repo_default_remote as a fallback when no per-repo resolution exists |
| pkg/cmd/factory/default_test.go | Adds comprehensive test cases covering the new fallback behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| key := entry.Value | ||
| if key != "" { | ||
| if named, nerr := remotes.FindByName(key); nerr == nil && named != nil { | ||
| return named.Repo, nil |
There was a problem hiding this comment.
The code silently ignores errors when looking up the configured remote name. If a user explicitly configures repo_default_remote to a non-existent remote, they receive no feedback that their configuration is being ignored. Consider logging a warning or returning an error when the configured remote name cannot be found, so users are aware their configuration is not taking effect.
| return named.Repo, nil | |
| return named.Repo, nil | |
| } else { | |
| fmt.Fprintf(f.IOStreams.ErrOut, "warning: configured repo_default_remote %q not found among git remotes; falling back to default resolution\n", key) |
| }, | ||
| { | ||
| Key: repoDefaultRemote, | ||
| Description: "the default remote name to use for gh repo/pr/issue/workflow/etc.", |
There was a problem hiding this comment.
The description mentions 'gh repo/pr/issue/workflow/etc.' but this configuration only affects base repo resolution in SmartBaseRepoFunc. Commands that don't use this function won't be affected. The description should be more precise about its scope, e.g., 'the default remote name to use when resolving the base repository for commands'.
| Description: "the default remote name to use for gh repo/pr/issue/workflow/etc.", | |
| Description: "the default remote name to use when resolving the base repository for commands", |
| var hasResolved bool | ||
| for _, r := range remotes { | ||
| if r.Resolved != "" { | ||
| hasResolved = true | ||
| break | ||
| } | ||
| } |
There was a problem hiding this comment.
This loop iterates through all remotes to check if any have a Resolved field set. Since context.Remotes already has a ResolvedRemote() method that performs this exact check (see context/remote.go lines 51-58), you should use that method instead: _, err := remotes.ResolvedRemote(); hasResolved := err == nil. This eliminates code duplication and improves maintainability.
| var hasResolved bool | |
| for _, r := range remotes { | |
| if r.Resolved != "" { | |
| hasResolved = true | |
| break | |
| } | |
| } | |
| _, err := remotes.ResolvedRemote() | |
| hasResolved := err == nil |
9cbc3a8 to
c1c0fa4
Compare
|
Rebased onto latest default branch. |
c1c0fa4 to
0e27e6c
Compare
|
Rebased again. Can @babakks (or someone else) take a look please? |
|
Thanks for this, @friederbluemle! 🙏 I have already explained on the issue why we're closing this PR. See #9399 (comment). |
Problem
At the moment, it’s a bit cumbersome having to explicitly set the default remote in every single local Git repository just to be able to use commands like
gh repo,gh pr,gh issue,gh workflow, etc.I constantly run into the following error:
Context
For my workflow, the canonical default remote name
originalways points to the source repository.Fork remotes typically have short two-character initials (for user forks) or the organization name (for org forks).
In other words,
originis universally the correct default for my setup.Solution
To avoid having to manually run
gh repo set-default origin, I added a simple, optional global override:gh config set repo_default_remote originOnce set, I no longer see the “No default repository” error —
ghautomatically uses the specified remote (e.g.,origin) when no explicit repo is configured.Behavior / Precedence
The new
repo_default_remoteconfig key is an opt-in global setting.When unset (the default), existing behavior remains unchanged.
When set, repository resolution follows this precedence (highest → lowest):
-R/--repoflagGH_REPOenvironment variablegh repo set-defaultrepo_default_remoteDirectly relates to #9399 (while it does not auto-default to any name, it provides a simple one-time way to solve the issue).
Also related:
#9398
#9149
#8659