Skip to content

Use target branch tip as base for new independent branches#13626

Open
mtsgrd wants to merge 1 commit intomasterfrom
newest-base-for-new-branches
Open

Use target branch tip as base for new independent branches#13626
mtsgrd wants to merge 1 commit intomasterfrom
newest-base-for-new-branches

Conversation

@mtsgrd
Copy link
Copy Markdown
Contributor

@mtsgrd mtsgrd commented May 5, 2026

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:

                    target tip
                      ↓
M1 ← M2 ← M3 ← M4   (origin/main)
      ↑    ↑
  Stack A  Stack B

lower_bound = M2   ← new branch landed here (old!)

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.

new branch base = M4   ← now uses target commit ✓

Key changes

  • but-graph/.../workspace/api.rs
    • target_tip_commit_id() — returns the stored target_commit ID, falling back to the target_ref segment tip
    • target_segment_index() — extracted shared helper to deduplicate target resolution with merge_base_with_target_branch()
  • but-workspace/.../create_reference.rs — use target_tip_commit_id() instead of lower_bound (no fallback)

Test plan

Four new tests 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)

@github-actions github-actions Bot added the rust Pull requests that update Rust code label May 5, 2026
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch 3 times, most recently from dcef811 to 31a10a1 Compare May 5, 2026 00:34
@mtsgrd mtsgrd marked this pull request as ready for review May 5, 2026 00:53
@mtsgrd mtsgrd requested a review from krlvi as a code owner May 5, 2026 00:53
Copilot AI review requested due to automatic review settings May 5, 2026 00:53
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

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 to lower_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.

Comment thread crates/but-graph/src/projection/workspace/api.rs Outdated
Comment thread crates/but-graph/tests/graph/workspace/newest_base_among_stacks.rs Outdated
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch from 31a10a1 to 0590302 Compare May 5, 2026 17:52
Copy link
Copy Markdown
Contributor

@Caleb-T-Owens Caleb-T-Owens left a comment

Choose a reason for hiding this comment

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

@mtsgrd mtsgrd changed the title Use newest stack merge base when creating independent branches Use target branch tip as base for new independent branches May 5, 2026
Copilot AI review requested due to automatic review settings May 5, 2026 21:06
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch from 0590302 to 6e87b22 Compare May 5, 2026 21:06
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread crates/but-workspace/src/branch/create_reference.rs Outdated
Comment thread crates/but-graph/src/projection/workspace/api.rs Outdated
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch from 6e87b22 to b6dd81e Compare May 6, 2026 06:41
Copilot AI review requested due to automatic review settings May 6, 2026 07:08
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch from b6dd81e to cc3bb1f Compare May 6, 2026 07:08
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread crates/but-workspace/src/branch/create_reference.rs
Comment thread crates/but-graph/src/projection/workspace/api.rs
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch 2 times, most recently from 6cac6cd to 4718902 Compare May 6, 2026 12:21
Copilot AI review requested due to automatic review settings May 6, 2026 13:04
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch from 4718902 to 06366aa Compare May 6, 2026 13:04
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread crates/but-graph/src/projection/workspace/api.rs
Comment thread crates/but-graph/src/projection/workspace/api.rs
Comment thread crates/but-graph/tests/graph/workspace/target_tip_commit_id.rs
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch from 06366aa to 620682c Compare May 6, 2026 13:13
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)
@mtsgrd mtsgrd force-pushed the newest-base-for-new-branches branch from 620682c to b9be514 Compare May 6, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants