Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Command for token (e.g. rbw get github.com): rbw get github-token

Check what's configured with `forge auth status`.

Tokens are resolved in this order: CLI flags, environment variables (`FORGE_TOKEN`, `GITHUB_TOKEN`/`GH_TOKEN`, `GITLAB_TOKEN`, `FORGEJO_TOKEN`/`GITEA_TOKEN`, `BITBUCKET_TOKEN`, `TANGLED_TOKEN`), then the config file at `~/.config/forge/config`. The target host is inferred from the current directory's git remote; use `--host` or `FORGE_HOST` to override it (for example `forge --host gitea.com repo list someone`).
Tokens are resolved in this order: CLI flags, environment variables (`FORGE_TOKEN`, `GITHUB_TOKEN`/`GH_TOKEN`, `GITLAB_TOKEN`, `FORGEJO_TOKEN`/`GITEA_TOKEN`, `BITBUCKET_TOKEN`, `TANGLED_TOKEN`), then the config file at `~/.config/forge/config`. The target host is inferred from the current directory's git remote; use `--host` to override it (for example `forge --host gitea.com repo list someone`). `FORGE_HOST` sets the host for `-R OWNER/REPO` and for commands that don't act on the current repo, but doesn't override the current repo's remote.

### Configuration

Expand Down
5 changes: 5 additions & 0 deletions internal/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ func repoFromGitRemote(_ string) (forges.Forge, string, string, string, error) {
if err != nil {
return nil, "", "", "", err
}
// --host picks the forge to talk to; the remote still supplies owner/repo,
// e.g. for a repo mirrored from a self-hosted forge to github.com.
if hostOverride != "" {
domain = hostOverride
}

client := newClient(domain)
f, err := forgeForDomainMaybeConfig(context.Background(), client, domain)
Expand Down
31 changes: 31 additions & 0 deletions internal/resolve/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,37 @@ func TestDomainHostOverride(t *testing.T) {
}
}

func TestRepoFromGitRemoteHostOverride(t *testing.T) {
if _, err := exec.LookPath("git"); err != nil {
t.Skip("git not installed")
}
config.ResetCache()
defer config.ResetCache()
t.Setenv("XDG_CONFIG_HOME", t.TempDir())

t.Chdir(t.TempDir())
mustGit(t, "init", "-q")
mustGit(t, "remote", "add", "origin", "https://git.selfhosted.test/someone/project.git")

oldH, oldS := hostOverride, schemeOverride
defer func() { hostOverride, schemeOverride = oldH, oldS }()
SetHost("github.com")

f, owner, repo, domain, err := Repo("", "")
if err != nil {
t.Fatalf("Repo: %v", err)
}
if domain != "github.com" {
t.Errorf("domain = %q, want --host to override the remote's domain", domain)
}
if owner != "someone" || repo != "project" {
t.Errorf("owner/repo = %s/%s, want someone/project from the remote", owner, repo)
}
if f == nil {
t.Fatal("expected a forge instance")
}
}

func TestForgeTypeOverrideSkipsDetection(t *testing.T) {
config.ResetCache()
defer config.ResetCache()
Expand Down
Loading