Skip to content

Add run command#44

Merged
Pajn merged 1 commit into
mainfrom
run-command
Mar 25, 2026
Merged

Add run command#44
Pajn merged 1 commit into
mainfrom
run-command

Conversation

@Pajn
Copy link
Copy Markdown
Owner

@Pajn Pajn commented Mar 25, 2026

Stack

Summary by CodeRabbit

  • New Features

    • Added kin run to execute a shell command across stack branches in topological order with a --continue-on-failure option and summary reporting.
    • CLI continue, abort, and status now surface and control in-progress run operations (progress, resume, abort).
  • Documentation

    • Added CLI reference entry and README examples for the new run command.
  • Tests

    • Added integration tests validating traversal order, failure handling, and checkout restoration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 25, 2026

Warning

Rate limit exceeded

@Pajn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 31 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: e166d6f4-68e5-4f65-9298-cc546f836b16

📥 Commits

Reviewing files that changed from the base of the PR and between edeeaed and 6372a15.

📒 Files selected for processing (9)
  • README.md
  • docs/cli_reference.md
  • src/commands/abort_cmd.rs
  • src/commands/continue_cmd.rs
  • src/commands/mod.rs
  • src/commands/run.rs
  • src/commands/status_cmd.rs
  • src/main.rs
  • tests/integration_run.rs
📝 Walkthrough

Walkthrough

Adds a new run CLI command that discovers a stack of branches, topologically sorts them, checks out each branch in order, executes a provided shell command (sh -c), records progress in a persisted run-state, and exposes resume/abort/status behaviors. Documentation and integration tests were added.

Changes

Cohort / File(s) Summary
Documentation
README.md, docs/cli_reference.md
Documented new run command, usage (-c/--command, --continue-on-failure), execution semantics across stack branches, and added CLI reference entry and Quick Start example.
CLI Integration
src/main.rs, src/commands/mod.rs
Registered new Run(RunArgs) subcommand, wired imports and dispatch, and exported run module.
Run command implementation
src/commands/run.rs
New run command: RunArgs struct, branch discovery (merge-base → stack), topological sort, per-branch git checkout, execute sh -c <command>, capture stdout/stderr, persist kindra_run_state.json, track failures, and implement continue_run and abort_run.
Abort/Continue/Status control
src/commands/abort_cmd.rs, src/commands/continue_cmd.rs, src/commands/status_cmd.rs
Updated control flows to detect and handle the new run-state alongside existing rebase state: early conflict errors when both states exist, delegation to run helpers for abort/continue, and status reporting for run progress/failures.
Tests
tests/integration_run.rs
Added integration tests validating traversal order, behavior on failures, continue-on-failure semantics, and restoration of original checkout (including detached HEAD cases).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as "CLI Handler"
    participant Repo as "Repository"
    participant Git as "Git Ops"
    participant Shell as "Shell Executor"
    participant State as "Run State"

    User->>CLI: kin run -c "command" [--continue-on-failure]
    CLI->>Repo: open repository
    Repo->>Git: resolve upstream/base and merge-base
    Git->>Repo: derive stack branches and topologically sort

    loop for each branch (base → tips)
        Repo->>State: persist current index & original checkout
        Repo->>Git: checkout <branch>
        Git->>Shell: run sh -c "command"
        Shell->>CLI: stream stdout/stderr
        Shell->>State: report success/failure for branch
        alt failure & continue_on_failure == false
            State->>Git: checkout original branch
            Git->>CLI: return error (stop)
        end
    end

    State->>Git: restore original checkout
    CLI->>User: print summary (succeeded/failed branches)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hopped from base up to the tip so spry,
Running shells on each branch as I leapt by,
Saving my hops in a tiny JSON den,
Resume, abort, status — I'll hop back again!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The linked issue #46 concerns split checkout functionality unrelated to this PR's run command implementation. There is a mismatch between the PR's actual changes and the linked issue's objectives. Verify that the linked issue #46 is the correct reference for this PR. If the run command should be validated against different issue requirements, link those issues instead.
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add run command' is concise and directly describes the main change—introducing a new 'run' command to the codebase. It clearly summarizes the primary feature addition.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the 'run' command: documentation updates, new module, command implementation, CLI wiring, and integration with existing state management systems (abort/continue/status commands).

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Pajn
Copy link
Copy Markdown
Owner Author

Pajn commented Mar 25, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 25, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 3

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

Inline comments:
In `@src/commands/run.rs`:
- Around line 28-34: The cleanup currently assumes original_branch
(current_branch_name) is always present and ignores non-zero exits from external
checkouts; fix by capturing both the current branch name (current_branch_name)
and the original commit id (head_id = head.peel_to_commit()?.id()) and, in the
checkout_original_branch logic (and any checkout code around the 153-161
region), attempt to restore by: if original branch name Some(s) run `git
checkout s` and check Command::status().success(), else run `git checkout
<head_id>` to restore detached HEAD; always inspect the Command::status() return
and propagate an Err when status.success() is false so failed checkouts are not
silently ignored.
- Around line 21-23: The run function currently opens the repo and then checks
out/mutates branches without persisting resumable state; before any branch
checkout or mutation in run (and in the branch-processing block spanning the
section handling branch iteration), construct a RunState (or similar struct)
capturing the list of target branches, current index, args (RunArgs) and write
it to durable storage (e.g. via a new persist_run_state(repo, &run_state)
helper) so that interruption allows kin continue/abort; update the persisted
state after each successful branch completion (increment current index and
persist) and remove/mark finished on successful overall completion, and ensure
error paths call a persist_failure/mark_aborted helper so state reflects partial
progress for continue/abort handlers.

In `@src/main.rs`:
- Around line 67-68: Add integration tests for the new Run(RunArgs) subcommand:
create tests in the tests/ directory (e.g., tests/integration_run.rs) that
exercise the happy path (successful traversal of branches), the
--continue-on-failure behavior (ensure subsequent branches are processed when a
branch fails), and restoration of the original checkout after a failure (verify
the working branch is the same as before invoking kin run). Locate the
Run(RunArgs) handler in the CLI entry points and invoke the binary via the test
harness (or helper functions used by other integration tests) to mimic real git
repositories, asserting branch states and repository contents before and after
runs; include setup/teardown to create multi-branch repos and simulate a failure
on one branch to validate cleanup and continuation behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 27b71b79-92d0-48a4-93ce-e58b0cc3e7c1

📥 Commits

Reviewing files that changed from the base of the PR and between 4738d0d and a5e10fc.

📒 Files selected for processing (5)
  • README.md
  • docs/cli_reference.md
  • src/commands/mod.rs
  • src/commands/run.rs
  • src/main.rs

Comment thread src/commands/run.rs
Comment thread src/commands/run.rs
Comment thread src/main.rs
@Pajn
Copy link
Copy Markdown
Owner Author

Pajn commented Mar 25, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 25, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Pajn
Copy link
Copy Markdown
Owner Author

Pajn commented Mar 25, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 25, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 `@tests/integration_run.rs`:
- Around line 1-131: Add integration tests that exercise the run-state lifecycle
by creating new #[test] functions (e.g., run_status_after_failed_run,
run_abort_restores_state, run_continue_resumes_run) that reuse setup_run_repo(),
kin_cmd(), run_ok(), read_lines(), and current_branch() to: 1) invoke kin run
with a failing command that leaves .git/kindra_run_state.json, 2) call kin
status via kin_cmd() and assert its stdout reports the stored run state, 3) call
kin abort via kin_cmd() and assert the file .git/kindra_run_state.json is
removed and the original checkout (checked with current_branch() or git
rev-parse HEAD via git_stdout) is restored, and 4) optionally call kin continue
with --continue-on-failure semantics and assert remaining branches are processed
and state removed; ensure each test asserts expected exit status
(success/failure) and uses read_lines() to validate run.log where applicable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: db704d86-7e0d-4cd0-9df5-6e045c523d45

📥 Commits

Reviewing files that changed from the base of the PR and between a5e10fc and edeeaed.

📒 Files selected for processing (9)
  • README.md
  • docs/cli_reference.md
  • src/commands/abort_cmd.rs
  • src/commands/continue_cmd.rs
  • src/commands/mod.rs
  • src/commands/run.rs
  • src/commands/status_cmd.rs
  • src/main.rs
  • tests/integration_run.rs

Comment thread tests/integration_run.rs
@Pajn Pajn merged commit 2f69e23 into main Mar 25, 2026
1 check passed
@Pajn Pajn deleted the run-command branch March 25, 2026 23:46
@coderabbitai coderabbitai Bot mentioned this pull request May 21, 2026
@coderabbitai coderabbitai Bot mentioned this pull request May 30, 2026
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.

1 participant