Skip to content

fix: support configurable default remote#171

Merged
helizaga merged 2 commits intocoderabbitai:mainfrom
scarf005:fix/default-remote-base-ref
Apr 27, 2026
Merged

fix: support configurable default remote#171
helizaga merged 2 commits intocoderabbitai:mainfrom
scarf005:fix/default-remote-base-ref

Conversation

@scarf005
Copy link
Copy Markdown
Contributor

@scarf005 scarf005 commented Apr 25, 2026

Pull Request

Description

  • Adds gtr.defaultRemote / GTR_DEFAULT_REMOTE and git gtr new --remote.
  • Uses the selected remote for default branch detection, fetch, remote tracking, and remote-only ref fallback.

Motivation

Fixes #170.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Documentation update

Testing

  • distrobox enter fedora -- bash -lc 'bats tests/'
  • distrobox enter fedora -- bash -lc 'shellcheck lib/core.sh lib/commands/create.sh lib/config.sh scripts/generate-completions.sh'
  • ./scripts/generate-completions.sh --check
  • git diff --check
  • PATH="$PWD/bin:$PATH" git gtr help new
  • ./bin/gtr help new

Manual Testing Checklist

Tested on:

  • Linux (Fedora distrobox)

Core functionality tested:

  • git gtr new <branch> - Create worktree
  • git gtr config - Configuration commands
  • Other commands affected by this change: git gtr new --remote

Test Steps

  1. Added BATS coverage for cmd_create --remote using a selected remote default branch.
  2. Added BATS coverage for create_worktree tracking a branch from the selected remote.

Expected behavior:

--remote upstream and gtr.defaultRemote=upstream use upstream/<default-branch>.

Actual behavior:

Matches expected.

Breaking Changes

  • This PR introduces breaking changes
  • I have discussed this in an issue first
  • Migration guide is included in documentation

Checklist

  • I have read CONTRIBUTING.md
  • My code follows the project's style guidelines
  • I have performed manual testing on at least one platform
  • I have updated documentation (README.md, CLAUDE.md, etc.) if needed
  • My changes work on multiple platforms (or I've noted platform-specific behavior)
  • I have added/updated shell completions (if adding new commands or flags)
  • I have tested with both git gtr (production) and ./bin/gtr (development)
  • No new external dependencies are introduced (Bash + git only)
  • All existing functionality still works

License Acknowledgment

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0.

PR opened by gpt-5.5 on opencode

Summary by CodeRabbit

  • New Features

    • Added --remote flag to git gtr new to choose which remote supplies default base refs.
    • Added gtr.defaultRemote configuration option (defaults to origin).
  • Documentation

    • Updated help and configuration docs and README to describe the --remote flag and gtr.defaultRemote.
  • Chores

    • Updated shell completions (bash, zsh, fish) to support the new flag and config key.
  • Tests

    • Added integration tests covering remote-based default resolution.

Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Assisted-by: opencode:gpt-5.5
@scarf005 scarf005 requested a review from NatoBoram as a code owner April 25, 2026 02:13
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 37ae69d2-7a7a-4594-bfbe-1b992048d9d9

📥 Commits

Reviewing files that changed from the base of the PR and between 923876f and 542f64e.

📒 Files selected for processing (1)
  • lib/core.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/core.sh

Walkthrough

Adds a selectable remote for resolving default base refs: introduces a --remote flag for git gtr new, a gtr.defaultRemote config key (mapped to .gtrconfig), propagates the remote through branch resolution and worktree creation, updates completions, docs, and tests.

Changes

Cohort / File(s) Summary
Docs & Help
README.md, docs/configuration.md, lib/commands/help.sh
Document --remote <name> flag, add gtr.defaultRemote examples and environment variable reference; update help text to mention the flag and config.
Core logic
lib/core.sh, lib/commands/create.sh
Add resolve_default_remote(); pass remote through resolve_default_branch, _check_branch_refs, _worktree_add_tracked, and create_worktree; replace hardcoded origin refs with remote-parameterized refs and git commands.
Config mapping
lib/config.sh
Map gtr.defaultRemote to .gtrconfig defaults.remote in _CFG_KEY_MAP.
Completions
completions/_git-gtr, completions/git-gtr.fish, completions/gtr.bash, scripts/generate-completions.sh
Add --remote/:remote:/-r option completions for git gtr new; include gtr.defaultRemote in config-key completion suggestions.
Tests
tests/cmd_create_integration.bats, tests/core_create_worktree.bats
New/extended Bats tests to verify --remote handling, default-remote resolution, remote-only branch detection, and track=auto behavior.
Completion generator
scripts/generate-completions.sh
Update generation to include new remote flag and config-key description for Fish completions.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as git gtr new
    participant Core as lib/core.sh
    participant Git as Git

    User->>CLI: git gtr new --remote upstream
    alt remote provided
        CLI->>Core: remote = "upstream"
    else remote omitted
        CLI->>Core: resolve_default_remote()
        Core-->>CLI: remote (from config/env/default)
    end

    CLI->>Core: resolve_default_branch(remote)
    Core->>Git: read refs/remotes/remote/HEAD
    Git-->>Core: default branch name
    Core->>Git: git fetch remote
    Core->>Git: git branch --track <branch> remote/<default_branch>
    Core->>Git: git worktree add -b <branch> remote/<default_branch>
    Git-->>Core: worktree created
    Core-->>CLI: success
    CLI-->>User: Worktree created from remote/<default_branch>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 I hopped from origin to upstream bright and new,
A flag, a config, a chosen view,
Branches follow where my whiskers point,
Worktrees sprout from the selected joint,
Cheers—now remotes are mine to choose!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding support for configurable default remote, which directly addresses the linked issue #170.
Linked Issues check ✅ Passed The PR fully implements the objective from issue #170 by adding --remote flag, gtr.defaultRemote config option, and GTR_DEFAULT_REMOTE env var for explicit remote selection.
Out of Scope Changes check ✅ Passed All changes are directly related to supporting configurable default remote: config mappings, help text, completions, core logic updates, and integration tests—no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/core.sh`:
- Around line 141-143: The parameter-expansion line using default_branch and
$remote can misinterpret special characters in the remote name; update the
pattern to treat the remote name as a literal by using the braced variable form
inside the expansion (i.e., change the use of
"${default_branch#refs/remotes/$remote/}" to use
"${default_branch#refs/remotes/${remote}/}") so the variable is expanded
literally; locate the assignment to default_branch and the parameter-expansion
that strips "refs/remotes/…" and replace the unbraced $remote with ${remote}.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6d4967db-15c2-45da-acf8-ad025dc38dd8

📥 Commits

Reviewing files that changed from the base of the PR and between 025de7f and 923876f.

📒 Files selected for processing (12)
  • README.md
  • completions/_git-gtr
  • completions/git-gtr.fish
  • completions/gtr.bash
  • docs/configuration.md
  • lib/commands/create.sh
  • lib/commands/help.sh
  • lib/config.sh
  • lib/core.sh
  • scripts/generate-completions.sh
  • tests/cmd_create_integration.bats
  • tests/core_create_worktree.bats

Comment thread lib/core.sh
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Assisted-by: opencode:gpt-5.5
@helizaga helizaga merged commit 6d1f465 into coderabbitai:main Apr 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git gtr new hardcodes origin for default base ref

2 participants