Skip to content
Open
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
69 changes: 47 additions & 22 deletions .claude/hooks/rtk-rewrite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,54 @@ fi

REWRITTEN=""

# --- Extract git global flags (-C <path>) before subcommand matching ---
GIT_GLOBAL_FLAGS=""
GIT_SUBCMD="$MATCH_CMD"
GIT_SUBCMD_BODY="$CMD_BODY"
if echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+-C[[:space:]]'; then
# Extract all -C <path> flags (may be repeated)
GIT_GLOBAL_FLAGS=$(echo "$MATCH_CMD" | sed -E 's/^git[[:space:]]+((-C[[:space:]]+[^[:space:]]+[[:space:]]+)+).*/\1/')
# Rebuild MATCH_CMD/CMD_BODY without the global flags for subcommand matching
GIT_SUBCMD="git $(echo "$MATCH_CMD" | sed -E 's/^git[[:space:]]+(-C[[:space:]]+[^[:space:]]+[[:space:]]+)+//')"
GIT_SUBCMD_BODY="git $(echo "$CMD_BODY" | sed -E 's/^git[[:space:]]+(-C[[:space:]]+[^[:space:]]+[[:space:]]+)+//')"
fi

# Helper: rewrite git command preserving -C flags
# Usage: _rtk_git_rewrite <subcmd>
# Reads GIT_SUBCMD_BODY, GIT_GLOBAL_FLAGS, ENV_PREFIX from outer scope
_rtk_git_rewrite() {
local subcmd="$1"
local rest="${GIT_SUBCMD_BODY#git ${subcmd}}"
if [ -n "$GIT_GLOBAL_FLAGS" ]; then
REWRITTEN="${ENV_PREFIX}rtk git ${GIT_GLOBAL_FLAGS}${subcmd}${rest}"
else
REWRITTEN="${ENV_PREFIX}rtk git ${subcmd}${rest}"
fi
}

# --- Git commands ---
if echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+status([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git status/rtk git status/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+diff([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git diff/rtk git diff/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+log([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git log/rtk git log/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+add([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git add/rtk git add/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+commit([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git commit/rtk git commit/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+push([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git push/rtk git push/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+pull([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git pull/rtk git pull/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+branch([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git branch/rtk git branch/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+fetch([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git fetch/rtk git fetch/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+stash([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git stash/rtk git stash/')"
elif echo "$MATCH_CMD" | grep -qE '^git[[:space:]]+show([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^git show/rtk git show/')"
if echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+status([[:space:]]|$)'; then
_rtk_git_rewrite "status"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+diff([[:space:]]|$)'; then
_rtk_git_rewrite "diff"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+log([[:space:]]|$)'; then
_rtk_git_rewrite "log"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+add([[:space:]]|$)'; then
_rtk_git_rewrite "add"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+commit([[:space:]]|$)'; then
_rtk_git_rewrite "commit"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+push([[:space:]]|$)'; then
_rtk_git_rewrite "push"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+pull([[:space:]]|$)'; then
_rtk_git_rewrite "pull"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+branch([[:space:]]|$)'; then
_rtk_git_rewrite "branch"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+fetch([[:space:]]|$)'; then
_rtk_git_rewrite "fetch"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+stash([[:space:]]|$)'; then
_rtk_git_rewrite "stash"
elif echo "$GIT_SUBCMD" | grep -qE '^git[[:space:]]+show([[:space:]]|$)'; then
_rtk_git_rewrite "show"

# --- GitHub CLI (added: api, release) ---
elif echo "$MATCH_CMD" | grep -qE '^gh[[:space:]]+(pr|issue|run|api|release)([[:space:]]|$)'; then
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

* add hook audit mode for verifiable rewrite metrics ([#151](https://github.com/rtk-ai/rtk/issues/151)) ([70c3786](https://github.com/rtk-ai/rtk/commit/70c37867e7282ee0ccf200022ecef8c6e4ab52f4))
* support git `-C <path>` flag for cross-directory operations ([#171](https://github.com/rtk-ai/rtk/pull/171)) ([e9b02fe](https://github.com/rtk-ai/rtk/commit/e9b02fe))

## [0.19.0](https://github.com/rtk-ai/rtk/compare/v0.18.1...v0.19.0) (2026-02-16)

Expand Down
8 changes: 8 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ rtk gain --history | grep proxy
- Uses `trailing_var_arg = true` + `allow_hyphen_values = true` to properly handle git flags
- Auto-detects `--merges` flag to avoid conflicting with `--no-merges` injection
- Propagates git exit codes for CI/CD reliability (PR #5 fix)
- Supports `git -C <path>` for cross-directory operations via `git_command()` helper
- `git_dir` parameter threaded through all `run_*` functions to prepend `-C <path>` to git invocations

**Output Filtering Strategy**
- Compact mode: Show only summary/failures
Expand Down Expand Up @@ -378,6 +380,12 @@ pub fn execute_with_filter(cmd: &str, args: &[&str]) -> Result<()> {
- **Features**: Exit code preservation, error grouping, consistent formatting
- **Testing**: Validated on production T3 Stack project (methode-aristote/app)

### PR #171: Git `-C <path>` Flag Support (2026-02-17)
- **Feature**: Support `git -C <path>` flag for cross-directory git operations
- **Implementation**: `git_command()` helper prepends `-C <path>` to all git invocations, `git_dir` threaded through all 12 `run_*` functions
- **Hook**: `_rtk_git_rewrite()` helper extracts and preserves `-C` flags before subcommand matching
- **Impact**: All git commands can now operate on repos outside the current directory (e.g., `rtk git -C /other/repo status`)

### Python & Go Support (2026-02-12)
- **Python Commands**: 3 commands for Python development workflows
- `rtk ruff check/format`: Ruff linter/formatter with JSON (check) and text (format) parsing (80%+ reduction)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ rtk git add # → "ok ✓"
rtk git commit -m "msg" # → "ok ✓ abc1234"
rtk git push # → "ok ✓ main"
rtk git pull # → "ok ✓ 3 files +10 -2"
rtk git -C /path/to/repo status # Cross-directory operations
```

### Commands
Expand Down
Loading
Loading