Skip to content

Add git worktree support actions and :x variants to rebase actions #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025

Conversation

lambdalisue
Copy link
Owner

@lambdalisue lambdalisue commented Jun 24, 2025

Summary by CodeRabbit

  • New Features
    • Added the ability to create new Git worktrees, including forced and orphan worktree creation, through new commands.
    • Introduced post-rebase command execution, allowing users to run custom commands immediately after rebase operations.
  • Enhancements
    • Improved branch deletion and move actions to handle branches associated with worktrees, offering more flexible management options.

Copy link

coderabbitai bot commented Jun 24, 2025

Walkthrough

The changes introduce new and extended support for Git worktree operations in the Denops Gin plugin. Branch deletion and move logic now conditionally handle worktrees, and a new module enables creating worktrees (including forced and orphaned variants). The branch edit command is updated to initialize the new worktree action. Additionally, rebase commands are extended to optionally execute a user-specified command after completion.

Changes

File(s) Change Summary
denops/gin/action/branch_delete.ts, denops/gin/action/branch_move.ts Extended Candidate type to support optional worktree property; modified logic to handle worktree-specific operations in delete and move actions.
denops/gin/action/worktree_new.ts Added new module to support creation of Git worktrees (normal, forced, orphan); exports init and supporting types/functions.
denops/gin/command/branch/edit.ts Imported and initialized the new worktree action in the branch edit command initialization sequence.
denops/gin/action/branch_new.ts Renamed variable from name to branchName in branch creation functions; reformatted orphan branch command arguments.
denops/gin/action/rebase.ts Added new rebase commands supporting post-rebase command execution; extended rebase functions to prompt and append execution commands.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Denops
    participant GinPlugin
    participant Git

    User->>Denops: Invoke branch delete/move command
    Denops->>GinPlugin: Dispatch action with Candidate
    alt Candidate has worktree
        GinPlugin->>Git: worktree remove/move <worktree>
    else Candidate has no worktree
        GinPlugin->>Git: branch -d/-D or branch --move <branch>
    end
Loading
sequenceDiagram
    participant User
    participant Denops
    participant GinPlugin
    participant Git

    User->>Denops: Invoke worktree new/force/orphan command
    Denops->>GinPlugin: Dispatch worktree_new action
    GinPlugin->>User: Prompt for worktree path
    User->>GinPlugin: Provide path (or cancel)
    alt User provides path
        GinPlugin->>Git: worktree add [--force|--orphan] <path>
    else User cancels
        GinPlugin->>User: Echo "Canceled"
    end
Loading
sequenceDiagram
    participant User
    participant Denops
    participant GinPlugin
    participant Git

    User->>Denops: Invoke rebase:x or rebase:i:x command
    Denops->>GinPlugin: Dispatch rebase action with execute flag
    GinPlugin->>User: Prompt for post-rebase command
    alt User provides command
        GinPlugin->>Git: rebase ... -x <command>
    else User cancels or empty
        GinPlugin->>User: Echo "Canceled"
    end
    GinPlugin->>Denops: silent checktime
Loading

Possibly related PRs

  • 👍 add rebase:instant-drop action #151: Also modifies denops/gin/action/rebase.ts by adding new rebase-related commands and extending rebase functionality with user interaction, related to the rebase enhancements here.

Poem

🐇✨
Branches hop, and worktrees grow,
Move or delete, with care we go.
New roots planted, orphaned too,
Rebase commands now ask "What to do?"
Gin’s garden blooms with every cue,
A rabbit’s joy in code anew!
🌿🌸

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jun 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.30%. Comparing base (48cc19c) to head (3d26c2c).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #158   +/-   ##
=======================================
  Coverage   60.30%   60.30%           
=======================================
  Files          17       17           
  Lines         912      912           
  Branches      120      120           
=======================================
  Hits          550      550           
  Misses        362      362           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@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

🧹 Nitpick comments (1)
denops/gin/action/worktree_new.ts (1)

66-87: Fix parameter type inconsistency.

The _gatherCandidates parameter uses GatherCandidates<unknown> instead of GatherCandidates<Candidate> for consistency with the other functions and the exported Candidate type.

-  _gatherCandidates: GatherCandidates<unknown>,
+  _gatherCandidates: GatherCandidates<Candidate>,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05a183c and c41c089.

📒 Files selected for processing (4)
  • denops/gin/action/branch_delete.ts (2 hunks)
  • denops/gin/action/branch_move.ts (2 hunks)
  • denops/gin/action/worktree_new.ts (1 hunks)
  • denops/gin/command/branch/edit.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
denops/gin/action/branch_move.ts (1)
denops/gin/action/branch_delete.ts (1)
  • Candidate (5-7)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test (windows-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (ubuntu-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (windows-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (ubuntu-latest, 1.x, v9.1.0448, v0.10.0)
🔇 Additional comments (7)
denops/gin/action/worktree_new.ts (2)

1-36: LGTM! Well-structured worktree action initialization.

The implementation follows Denops patterns correctly with proper batch operations, command registration, and clean separation of concerns for different worktree creation modes.


38-64: LGTM! Proper implementation of worktree creation logic.

The function correctly handles candidate gathering, user input with sensible defaults, cancellation handling, and Git command dispatch with conditional force flag support.

denops/gin/command/branch/edit.ts (2)

22-22: LGTM! Clean import addition.

The import follows the established pattern and naming conventions.


75-75: LGTM! Proper integration of worktree action.

The initialization call is correctly placed within the batch operation and uses consistent parameters with other action initializations.

denops/gin/action/branch_delete.ts (2)

7-7: LGTM! Appropriate type extension for worktree support.

The optional worktree property correctly extends the local/alias branch candidate type to support worktree operations.


53-65: LGTM! Correct worktree-aware deletion logic.

The conditional logic properly handles worktree removal vs branch deletion, with appropriate Git command construction for both scenarios.

denops/gin/action/branch_move.ts (1)

6-6: LGTM! Clean type definition for worktree support.

The Candidate type appropriately includes the optional worktree property for move operations.

Repository owner deleted a comment from coderabbitai bot Jun 24, 2025
@lambdalisue lambdalisue changed the title Add git worktree support Add git worktree support actions and :x variants to rebase actions Jun 24, 2025
Copy link

@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: 0

🧹 Nitpick comments (2)
denops/gin/action/rebase.ts (2)

57-57: Consider extracting duplicate logic into a helper function.

The execute command logic is duplicated between doRebase and doRebaseInteractive. While the implementation is correct, extracting this into a shared helper function would improve maintainability.

+async function getExecuteCommand(denops: Denops): Promise<string | null> {
+  const cmd = await helper.input(denops, {
+    prompt: "Execute command after rebase: ",
+  }) ?? "";
+  await denops.cmd('redraw | echo ""');
+  if (!cmd) {
+    await helper.echoerr(denops, "Cancelled");
+    return null;
+  }
+  return cmd;
+}

 async function doRebase(
   denops: Denops,
   bufnr: number,
   range: Range,
   gatherCandidates: GatherCandidates<Candidate>,
   execute?: boolean,
 ): Promise<void> {
   const xs = await gatherCandidates(denops, bufnr, range);
   const x = xs.at(0);
   if (!x) {
     return;
   }
   const args = ["rebase", x.commit];
   if (execute) {
-    const cmd = await helper.input(denops, {
-      prompt: "Execute command after rebase: ",
-    }) ?? "";
-    await denops.cmd('redraw | echo ""');
-    if (!cmd) {
-      await helper.echoerr(denops, "Cancelled");
+    const cmd = await getExecuteCommand(denops);
+    if (!cmd) {
       return;
     }
     args.push("-x", cmd);
   }
   await denops.dispatch("gin", "command", "", args);

Also applies to: 64-76


87-87: Same duplication issue applies here.

The interactive rebase function has the same duplicated execute command logic. The implementation is correct but would benefit from the same helper function extraction suggested for doRebase.

 async function doRebaseInteractive(
   denops: Denops,
   bufnr: number,
   range: Range,
   gatherCandidates: GatherCandidates<Candidate>,
   execute?: boolean,
 ): Promise<void> {
   const xs = await gatherCandidates(denops, bufnr, range);
   const x = xs.at(0);
   if (!x) {
     return;
   }
   const args = [
     "rebase",
     "--interactive",
     x.commit,
   ];
   if (execute) {
-    const cmd = await helper.input(denops, {
-      prompt: "Execute command after rebase: ",
-    }) ?? "";
-    await denops.cmd('redraw | echo ""');
-    if (!cmd) {
-      await helper.echoerr(denops, "Cancelled");
+    const cmd = await getExecuteCommand(denops);
+    if (!cmd) {
       return;
     }
     args.push("-x", cmd);
   }

Also applies to: 94-109

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c41c089 and 3d26c2c.

📒 Files selected for processing (6)
  • denops/gin/action/branch_delete.ts (2 hunks)
  • denops/gin/action/branch_move.ts (2 hunks)
  • denops/gin/action/branch_new.ts (2 hunks)
  • denops/gin/action/rebase.ts (3 hunks)
  • denops/gin/action/worktree_new.ts (1 hunks)
  • denops/gin/command/branch/edit.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • denops/gin/action/branch_new.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • denops/gin/command/branch/edit.ts
  • denops/gin/action/branch_delete.ts
  • denops/gin/action/branch_move.ts
  • denops/gin/action/worktree_new.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
denops/gin/action/rebase.ts (3)
denops/gin/action/core.ts (1)
  • define (89-114)
denops/gin/git/executor.ts (1)
  • execute (43-109)
denops/gin/git/process.ts (1)
  • execute (42-56)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (macos-latest, 1.x, v9.1.0448, v0.10.0)
🔇 Additional comments (3)
denops/gin/action/rebase.ts (3)

21-27: LGTM! New rebase action with command execution.

The new "rebase:x" action definition correctly passes the execute flag to enable command execution after rebase.


35-41: LGTM! New interactive rebase action with command execution.

The new "rebase:i:x" action definition correctly passes the execute flag to enable command execution after interactive rebase.


110-119: Good handling of async dispatch for interactive rebase.

The implementation correctly avoids awaiting the dispatch call to prevent Vim from freezing, and properly handles errors and cleanup. The comment explains the reasoning well.

@lambdalisue lambdalisue merged commit 620f56a into main Jun 24, 2025
9 checks passed
@lambdalisue lambdalisue deleted the support-worktree branch June 24, 2025 07:06
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