Use target branch tip as base for new independent branches#13626
Open
Use target branch tip as base for new independent branches#13626
Conversation
dcef811 to
31a10a1
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts how “independent” branches are based in a workspace by preferring the newest (closest-to-target) merge base among all stacks, instead of always using the workspace lower bound. This better aligns new independent branches with the most recent common history when stacks diverge at different points from the target.
Changes:
- Added
Workspace::newest_base_among_stacks()to compute a newer merge base across stacks vs. the target. - Updated independent-branch creation to prefer
newest_base_among_stacks()and fall back tolower_bound. - Added workspace tests covering expected “newest base” selection and target configuration edge cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/but-workspace/src/branch/create_reference.rs | Uses the new workspace API to choose a more recent base for independent branches. |
| crates/but-graph/src/projection/workspace/api.rs | Introduces newest_base_among_stacks() to compute a newer merge base among stacks and the target. |
| crates/but-graph/tests/graph/workspace/newest_base_among_stacks.rs | Adds tests validating newest-base selection and behavior without a configured target. |
| crates/but-graph/tests/graph/workspace/mod.rs | Registers the new test module. |
31a10a1 to
0590302
Compare
Caleb-T-Owens
requested changes
May 5, 2026
0590302 to
6e87b22
Compare
6e87b22 to
b6dd81e
Compare
b6dd81e to
cc3bb1f
Compare
6cac6cd to
4718902
Compare
4718902 to
06366aa
Compare
06366aa to
620682c
Compare
Previously, new independent branches were based on the workspace's lower bound (the lowest common ancestor of all stacks). When stacks have different merge bases with the target, this placed the new branch on an unnecessarily old commit. Now we use the stored target commit (target.sha) directly, via a new `Workspace::target_tip_commit_id()` helper, preferring `target_commit` over `target_ref`. Creating an independent branch without a configured target is now an error rather than silently falling back to the lower bound. Also extracts `target_segment_index()` to deduplicate the target resolution logic shared with `merge_base_with_target_branch()`. Tested with four cases in `target_tip_commit_id.rs`: - Two stacks with different bases — returns the target tip - One stack above the target — still returns the target tip - No target configured — returns None - Only extra_target set — returns None (not sufficient)
620682c to
b9be514
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When creating a new independent branch, we used the workspace's lower bound — the lowest common ancestor of all stacks. If stacks have different merge bases with the target, this places the new branch on an unnecessarily old commit:
Solution
Use the stored target commit (
target.sha) as the base for new independent branches. If unavailable, fall back to the target ref tip. Creating an independent branch without any target is now an error.Key changes
but-graph/.../workspace/api.rstarget_tip_commit_id()— returns the storedtarget_commitID, falling back to thetarget_refsegment tiptarget_segment_index()— extracted shared helper to deduplicate target resolution withmerge_base_with_target_branch()but-workspace/.../create_reference.rs— usetarget_tip_commit_id()instead oflower_bound(no fallback)Test plan
Four new tests in
target_tip_commit_id.rs:Noneextra_targetset — returnsNone(not sufficient)