stalecontext/forgejo-cli-plus
2
4
Fork
You've already forked forgejo-cli-plus
1

Fix multi-remote auto-detection and untracked branch handling #45

Merged
stalecontext merged 6 commits from fix/multi-remote-fallback into main 2026年03月31日 02:59:54 +02:00

Summary

Two related bugs when working with multiple git remotes, plus a CI improvement:

  1. #44 : When a repo has multiple remotes (e.g., origin + upstream) and the current branch doesn't track any remote, fj errors with "no repo info specified" instead of falling back to origin.

  2. #46 : pr create crashes with a git2 config error when the current branch has no tracking remote, even after repo detection succeeds.

Changes

Remote auto-detection fallback (src/repo.rs)

  • After checking for branch tracking and --host host-matching, try the origin remote as a last-resort fallback
  • --host matching takes priority over the origin fallback (explicit user directive wins)
  • Includes verbose_log! message so users can see the fallback in action

PR create tracking remote fallback (src/prs.rs)

  • When branch.<name>.remote config is missing, fall back to the remote resolved by RepoInfo (or origin)
  • When branch.<name>.merge config is missing, use the local branch name as the head branch
  • Includes verbose_log! message for the fallback

CI (.forgejo/workflows/test.yml)

  • Switch from codeberg-medium to codeberg-small runner -- the build doesn't need the extra resources

Tests

  • tests/repo_info.rs: 3 new tests -- origin fallback works, --host matching takes priority over fallback, no-origin still errors. Refactored helper to support multiple remotes.
  • tests/api_pr.rs: 1 new test -- PR create from untracked branch with multiple remotes succeeds. Uses body_partial_json to verify the correct head branch name is sent to the API.

Test plan

  • cargo test --all-targets passes (236 tests)
  • cargo fmt -- --check clean
  • cargo clippy --all-targets -- -D warnings clean
  • Manual: checkout untracked branch with origin + upstream remotes, verify fj repo view and fj pr create work without --remote

Closes #44
Closes #46

## Summary Two related bugs when working with multiple git remotes, plus a CI improvement: 1. **#44**: When a repo has multiple remotes (e.g., `origin` + `upstream`) and the current branch doesn't track any remote, `fj` errors with "no repo info specified" instead of falling back to `origin`. 2. **#46**: `pr create` crashes with a git2 config error when the current branch has no tracking remote, even after repo detection succeeds. ## Changes ### Remote auto-detection fallback (`src/repo.rs`) - After checking for branch tracking and `--host` host-matching, try the `origin` remote as a last-resort fallback - `--host` matching takes priority over the origin fallback (explicit user directive wins) - Includes `verbose_log!` message so users can see the fallback in action ### PR create tracking remote fallback (`src/prs.rs`) - When `branch.<name>.remote` config is missing, fall back to the remote resolved by `RepoInfo` (or `origin`) - When `branch.<name>.merge` config is missing, use the local branch name as the head branch - Includes `verbose_log!` message for the fallback ### CI (`.forgejo/workflows/test.yml`) - Switch from `codeberg-medium` to `codeberg-small` runner -- the build doesn't need the extra resources ### Tests - **`tests/repo_info.rs`**: 3 new tests -- origin fallback works, `--host` matching takes priority over fallback, no-origin still errors. Refactored helper to support multiple remotes. - **`tests/api_pr.rs`**: 1 new test -- PR create from untracked branch with multiple remotes succeeds. Uses `body_partial_json` to verify the correct head branch name is sent to the API. ## Test plan - [x] `cargo test --all-targets` passes (236 tests) - [x] `cargo fmt -- --check` clean - [x] `cargo clippy --all-targets -- -D warnings` clean - [x] Manual: checkout untracked branch with origin + upstream remotes, verify `fj repo view` and `fj pr create` work without `--remote` Closes #44 Closes #46
fix: fall back to origin remote when multiple remotes exist
Some checks failed
Test / test (pull_request) Failing after 1m25s
96c6e62133
When a repo has multiple remotes and the current branch doesn't track
any of them, fj now falls back to the "origin" remote instead of
erroring with "no repo info specified". This matches the convention
used by git push, gh, and other CLI tools.
Closes #44 
fix: handle missing tracking remote in pr create
Some checks are pending
Test / test (pull_request) Waiting to run
60120c7d6d
When the current branch has no tracking remote configured, pr create
crashed with a git2 config error. Now falls back to the resolved
remote from RepoInfo (or origin) and uses the local branch name as
the head branch.
Closes #46 
stalecontext changed title from (削除) Fix multi-remote auto-detection fallback to origin (削除ここまで) to Fix multi-remote auto-detection and untracked branch handling 2026年03月31日 02:21:27 +02:00
fix: reorder origin fallback after --host matching, add body assertion
Some checks are pending
Test / test (pull_request) Waiting to run
e12f21c04e
Move the origin fallback in repo.rs to after the --host host-matching
block so that explicit --host directives take priority. Add
body_partial_json assertion to the pr create test to verify the correct
head branch name is sent to the API.
style: fix rustfmt formatting
Some checks are pending
Test / test (pull_request) Waiting to run
d711086893
ci: switch to codeberg-small runner
Some checks failed
Test / test (pull_request) Failing after 1m1s
88b1d5d172
ci: revert to codeberg-medium, drop target from cache
All checks were successful
Test / test (pull_request) Successful in 4m36s
c5b98be043
stalecontext deleted branch fix/multi-remote-fallback 2026年03月31日 02:59:55 +02:00
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
stalecontext/forgejo-cli-plus!45
Reference in a new issue
stalecontext/forgejo-cli-plus
No description provided.
Delete branch "fix/multi-remote-fallback"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?