Skip to content

Housekeep dry run#267

Merged
wanghailei merged 7 commits intomainfrom
housekeep-dry-run
Mar 12, 2026
Merged

Housekeep dry run#267
wanghailei merged 7 commits intomainfrom
housekeep-dry-run

Conversation

@wanghailei
Copy link
Owner

No description provided.

- carson housekeep --dry-run shows what would be reaped/deleted without
  making any changes. Each worktree and branch is listed with its status
  reason (merged PR, absorbed, held by current shell, open PR, etc.) and
  the action that would be taken (would reap / would delete / skip).
  Works with --all and --target too.

- Fix held_by_other_process? safety check: lsof exits non-zero on macOS
  when SIP blocks access to system processes, even though user-process
  output is valid. The previous `return false unless status.success?` guard
  caused the check to silently skip all results, allowing housekeep to
  remove worktrees that were held by another Terminal session. Now we parse
  whatever stdout lsof produces regardless of its exit code.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the carson housekeep command by integrating a --dry-run mode. This new feature empowers users to simulate housekeep operations, such as identifying dead worktrees and stale branches for removal, and view a comprehensive report of proposed changes before they are applied. This greatly improves operational safety and user confidence by allowing thorough review and verification of intended actions.

Highlights

  • Dry Run Functionality: Introduced a --dry-run option for the carson housekeep command, allowing users to preview the effects of housekeeping operations without making any actual changes.
  • Comprehensive Dry Run Planning: Implemented detailed dry-run logic for single, targeted, and all governed repositories, providing a plan for worktree reaping and branch pruning, including reasons for proposed actions.
  • Improved lsof Handling: Enhanced the Worktree module to more robustly handle lsof output, specifically addressing non-zero exit statuses on macOS due to System Integrity Protection (SIP) without invalidating valid user-process data.
Changelog
  • lib/carson/cli.rb
    • Added the --dry-run option to the housekeep command's parser.
    • Updated the command dispatch logic to pass the dry_run flag to the runtime housekeep methods.
  • lib/carson/runtime/housekeep.rb
    • Modified housekeep!, housekeep_target!, and housekeep_all! methods to accept and utilize a dry_run parameter.
    • Introduced housekeep_one_dry_run to generate and print a dry-run plan for a single repository.
    • Added reap_dead_worktrees_plan to create a plan of worktrees that would be reaped or skipped.
    • Implemented print_housekeep_dry_run, print_branch_plan_item, and pr_short_ref for formatted dry-run output.
  • lib/carson/runtime/local/prune.rb
    • Added the prune_plan method to generate a dry-run plan for branch pruning, detailing stale, orphan, and absorbed branches.
  • lib/carson/worktree.rb
    • Adjusted the held_by_other_process? method to not fail on non-zero lsof exit codes on macOS, instead checking for empty stdout.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a --dry-run option for the housekeep command, which is a valuable addition for previewing changes. The implementation is largely solid, adding planning logic and a new output formatter. My review includes a fix for a bug in the dry-run report's output formatting.

would_skip = all_items.count { |i| i[ :action ] == :skip }

# Column widths for aligned output.
name_width = [ ( worktree_plan + stale + orphan + absorbed ).map { |i| i[ :name ].to_s.length + i[ :branch ].to_s.length }.max || 0, 28 ].min + 2
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The calculation for name_width is incorrect and will lead to misaligned output in the dry-run report.

  • For worktree items, the label is "#{item[:name]} (#{item[:branch]})", but the width is calculated based on item[:name].length + item[:branch].length, which is off by 3 characters ( ()).
  • For branch items (stale, orphan, absorbed), the label is just item[:branch], but the width is calculated using item[:name].length + item[:branch].length. Since name is the same as branch for these items, this incorrectly results in 2 * item[:branch].length.

I've suggested a fix that correctly calculates the label lengths.

name_width = [ (worktree_plan.map { |i| "#{i[:name]} (#{i[:branch]})".length } + (stale + orphan + absorbed).map { |i| i[:branch].to_s.length }).max || 0, 28 ].min + 2

wanghailei and others added 4 commits March 12, 2026 17:19
The Carson template sync wiped the IndentationWidth and file exclusions
that PR #266 added. Re-apply them so CI passes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The cop triggers a tab-width calculation bug for these files — the
expected correction would require mixed tabs+spaces, which is
unfixable with pure-tab indentation. Use inline rubocop:disable
directives instead of rubocop.yml Exclude entries so that
Carson's managed-template sync cannot silently remove them.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@wanghailei wanghailei merged commit fb55647 into main Mar 12, 2026
1 of 2 checks passed
@wanghailei wanghailei deleted the housekeep-dry-run branch March 12, 2026 09:44
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