Skip to content

Move commit to new branch when dropping onto NewStackDropzone#13191

Open
cbjeukendrup wants to merge 1 commit intogitbutlerapp:masterfrom
cbjeukendrup:drop-commit-on-new-stack-zone
Open

Move commit to new branch when dropping onto NewStackDropzone#13191
cbjeukendrup wants to merge 1 commit intogitbutlerapp:masterfrom
cbjeukendrup:drop-commit-on-new-stack-zone

Conversation

@cbjeukendrup
Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings April 6, 2026 11:10
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
gitbutler-web Skipped Skipped Apr 6, 2026 11:10am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enables dropping a commit onto the “outside lanes” / NewStackDropzone to create a new stack (branch) and move the commit there, aligning commit drag-and-drop behavior with the new-stack workflow in the Desktop app.

Changes:

  • Add support for CommitDropData in OutsideLaneDzHandler.accepts() and ondrop().
  • Implement ondropCommitData() to create a new stack and call stackService.moveCommit(), showing a warning toast for illegal moves.

Comment on lines +226 to +246
async ondropCommitData(data: CommitDropData) {
const stack = await this.stackService.newStackMutation({
projectId: this.projectId,
branch: { name: undefined },
});

const illegalAction = await this.stackService.moveCommit({
projectId: this.projectId,
targetStackId: ensureValue(stack.id),
commitId: data.commit.id,
sourceStackId: data.stackId,
});

if (illegalAction) {
const message = getMoveCommitIllegalActionMessage(illegalAction);
showToast({
style: "warning",
title: "Cannot move commit",
message,
});
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

ondropCommitData() creates a new stack before attempting moveCommit(). If moveCommit() returns an illegalAction, the commit is not moved but the newly created stack remains, which can leave users with an unintended empty stack. Consider preflighting the move before creating the stack, or cleaning up the newly created stack/branch when illegalAction is returned.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is also true, but more complicated.

We cannot 'preflight' it as suggested, but we can delete the branch if the move operation fails.

Let's do that please

Comment on lines +226 to +237
async ondropCommitData(data: CommitDropData) {
const stack = await this.stackService.newStackMutation({
projectId: this.projectId,
branch: { name: undefined },
});

const illegalAction = await this.stackService.moveCommit({
projectId: this.projectId,
targetStackId: ensureValue(stack.id),
commitId: data.commit.id,
sourceStackId: data.stackId,
});
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

When moving a commit to a new stack, the UI selection for the source lane can still reference data.commit.id (and the new stack isn’t selected), since moveCommit has no StackService side-effect here. This can leave the preview/selection pointing at a commit that no longer exists in the source stack. Consider clearing the source lane selection if it matches the moved commit (as MoveCommitDzHandler does) and/or selecting the moved commit in the newly created stack.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not a bad note.

I think we should at the very least unselect the commit.
Move commit doesn't return a commit map with the new commit ID, but in the meantime, we should clear the stale selection

@estib-vega estib-vega self-assigned this Apr 6, 2026
Copy link
Copy Markdown
Contributor

@estib-vega estib-vega left a comment

Choose a reason for hiding this comment

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

I reeeeally want this. 'tearing off' commits would be super cool.

Only echoed the copilot commits with some extra context.

Future steps from my side

It probably makes sense to add a first-class API for this operation, so that it's atomically handled and can be rolled-back in a single op. Plus the added benefit of having this in the CLI & TUI as well

Comment on lines +226 to +237
async ondropCommitData(data: CommitDropData) {
const stack = await this.stackService.newStackMutation({
projectId: this.projectId,
branch: { name: undefined },
});

const illegalAction = await this.stackService.moveCommit({
projectId: this.projectId,
targetStackId: ensureValue(stack.id),
commitId: data.commit.id,
sourceStackId: data.stackId,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not a bad note.

I think we should at the very least unselect the commit.
Move commit doesn't return a commit map with the new commit ID, but in the meantime, we should clear the stale selection

Comment on lines +226 to +246
async ondropCommitData(data: CommitDropData) {
const stack = await this.stackService.newStackMutation({
projectId: this.projectId,
branch: { name: undefined },
});

const illegalAction = await this.stackService.moveCommit({
projectId: this.projectId,
targetStackId: ensureValue(stack.id),
commitId: data.commit.id,
sourceStackId: data.stackId,
});

if (illegalAction) {
const message = getMoveCommitIllegalActionMessage(illegalAction);
showToast({
style: "warning",
title: "Cannot move commit",
message,
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is also true, but more complicated.

We cannot 'preflight' it as suggested, but we can delete the branch if the move operation fails.

Let's do that please

@cbjeukendrup
Copy link
Copy Markdown
Contributor Author

Thanks for the review! I will work on these suggestions, but might not get to it until the end of the week or so, so please bear with me :)

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.

3 participants