Skip to content

feat(gitlabPrService): auto-remove source branch on MR creation #8222

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 1 commit into from
Apr 24, 2025

Conversation

nolith
Copy link
Contributor

@nolith nolith commented Apr 22, 2025

Add removeSourceBranch option when creating merge requests to ensure the source branch is deleted automatically after the MR is merged. This helps with PR Stacks because every time the bottom merge request is merged, the next one in the stack will automatically change its target branch to main/master.

🧢 Changes

Add the removeSourceBranch option when creating merge requests to ensure
the source branch is deleted automatically after merging MR. This
helps with PR Stacks because every time the bottom merge request is merged, the next one in the stack will automatically change its target branch to main/master.

☕️ Reasoning

📌 Todos

Unfortunately, I was not able to validate this change on my workstation. When I compile GitButler with pnpm dev:desktop, the "Create Pull Request" button is completely unresponsive with or without this PR applied.

Copy link

vercel bot commented Apr 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gitbutler-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 23, 2025 9:10am

Copy link

vercel bot commented Apr 22, 2025

@nolith is attempting to deploy a commit to the GitButler Team on Vercel.

A member of the Team first needs to authorize it.

@krlvi
Copy link
Member

krlvi commented Apr 22, 2025

@nolith I remember discussing this with somebody on discord - I think there was an API that we can use to query what the repository has been configured with on GitLab, this way we could use the configured value, instead of hard-coding to true.

@nolith
Copy link
Contributor Author

nolith commented Apr 23, 2025

@krlvi yes you can GET /projects/:id and look for remove_source_branch_after_merge to see the configured value (I'm not sure if you can see that if you are not a maintainer).

However, stacked MRs don't work without that setting, as you merge your first one (MR1), the second merge request (MR2) will be merged to the first branch instead of master/main.

Moreover, the diff on the second one is all messed because as soon as you update and force push on GitButler, your MR2 is now rebased on master, but the target branch (MR1) is not because Gitbutler thinks it is integrated and no longer touches it. At this point, your MR2 diff will show all the new developments in master and your code.

Add removeSourceBranch option when creating merge requests to ensure
the source branch is deleted automatically after the MR is merged. This
helps with PR Stacks because every time the bottom merge request is merged, the next one in the stack will automatically change its target branch to main/master.
@krlvi
Copy link
Member

krlvi commented Apr 24, 2025

@krlvi yes you can GET /projects/:id and look for remove_source_branch_after_merge to see the configured value (I'm not sure if you can see that if you are not a maintainer).

However, stacked MRs don't work without that setting, as you merge your first one (MR1), the second merge request (MR2) will be merged to the first branch instead of master/main.

Moreover, the diff on the second one is all messed because as soon as you update and force push on GitButler, your MR2 is now rebased on master, but the target branch (MR1) is not because Gitbutler thinks it is integrated and no longer touches it. At this point, your MR2 diff will show all the new developments in master and your code.

Okay this is reasonable.

Of course, it would have been nice if we could make the behavior be: "if there is no stacking, use the value from remove_source_branch_after_merge otherwise if there is more then one branch in the stack always set removeSourceBranch to true".

However... since this removeSourceBranch is set on branch creation, there is no way of knowing if the user intends to stack branches on top. So yeah, let's make this always be true.

@krlvi krlvi marked this pull request as ready for review April 24, 2025 18:13
@krlvi krlvi merged commit d87071c into gitbutlerapp:master Apr 24, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants