Skip to content

Comments

feat: support git -C <path> flag for cross-directory operations#171

Open
pcadet wants to merge 2 commits intortk-ai:masterfrom
pcadet:feat/git-c-flag-support
Open

feat: support git -C <path> flag for cross-directory operations#171
pcadet wants to merge 2 commits intortk-ai:masterfrom
pcadet:feat/git-c-flag-support

Conversation

@pcadet
Copy link

@pcadet pcadet commented Feb 17, 2026

Summary

  • Add -C <path> flag support to rtk git commands, enabling cross-directory git operations
  • Create git_command() helper that prepends -C <path> to all git invocations
  • Thread git_dir parameter through all 12 run_* functions in git.rs
  • Update hook to extract and preserve -C flags before subcommand matching via _rtk_git_rewrite() helper

Test plan

  • cargo fmt && cargo clippy && cargo test — 362/362 pass, no new warnings
  • Unit tests: test_git_command_with_dir and test_git_command_without_dir
  • Hook test: git -C /tmp/repo statusrtk git -C /tmp/repo status
  • Hook test: git -C /other/repo log --oneline -5rtk git -C /other/repo log --oneline -5
  • Hook regression: git statusrtk git status (unchanged)
  • Hook regression: git diff --cachedrtk git diff --cached (unchanged)
  • Hook regression: cargo testrtk cargo test (non-git unaffected)
  • Manual: rtk git -C /tmp status → "Not a git repository" (correct)
  • Manual: rtk git -C <real-repo> status → filtered status output
  • Manual: rtk git status / rtk git log → unchanged behavior (no regression)

Add support for the git global flag -C <path> which allows running git
commands in a different directory. This is commonly used by Claude Code
when working across multiple repositories.

Changes:
- main.rs: Add -C option to Git command variant, pass to git module
- git.rs: Add git_command() helper that prepends -C <path>, thread
  git_dir parameter through all run_* functions
- rtk-rewrite.sh: Extract -C flags before subcommand matching, inject
  them into rewritten commands via _rtk_git_rewrite() helper
Add PR rtk-ai#171 feature to CLAUDE.md (implementation details + fork-specific
features), README.md (usage example), and CHANGELOG.md (release entry).
@pszymkowiak
Copy link
Collaborator

Thanks for this clean PR! The approach is solid — git_command() helper + threading git_dir through all run_* functions is the right pattern.

A few notes:

Code looks good:

  • The Clap -C flag integration in main.rs is correct
  • The hook shell helper _rtk_git_rewrite() properly extracts and preserves -C flags
  • Unit tests cover git_command() with and without -C

Minor requests before merge:

  1. Please remove the CHANGELOG.md and CLAUDE.md changes — these are auto-managed by release-please and maintained by the project. Only src/, hooks/, and README.md changes should be in the PR.
  2. Could you add a quick integration test (even #[ignore]) that runs rtk git -C /tmp status against a real temp repo? This would catch edge cases like paths with spaces.

Question: Does this handle -C with no space (-C/path) or only -C /path? Git accepts both forms.

Overall this is mergeable with the doc changes removed. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: rtk git -C <path> ... is rejected (works only via separator form)

2 participants