Skip to content

insert segment: Insert as first parents#14167

Merged
estib-vega merged 1 commit into
masterfrom
insert-segment-improvement
Jun 12, 2026
Merged

insert segment: Insert as first parents#14167
estib-vega merged 1 commit into
masterfrom
insert-segment-improvement

Conversation

@estib-vega

@estib-vega estib-vega commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

By default, insert the segments as first parents when inserting below. If
insertng above, inserts the target as the first parent.

Fixes GB-1525

Implementation notes:

  • Added ParentReparentingOrder so advanced callers can choose whether reparented parents are prepended or appended.
  • insert_segment keeps the default behavior simple by using Prepend.
  • Added parent-order regression coverage for the GB-1525 merge-commit reorder case and explicit append-policy coverage.

@github-actions github-actions Bot added the rust Pull requests that update Rust code label Jun 10, 2026
@estib-vega estib-vega requested a review from Copilot June 10, 2026 15:50
@linear-code

linear-code Bot commented Jun 10, 2026

Copy link
Copy Markdown

GB-1525

Copilot AI left a comment

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.

Pull request overview

This PR adjusts graph_rebase segment insertion to consistently place inserted segments on the first-parent lane (and, when inserting above, to make the target the first parent), addressing merge-lane visibility issues (GB-1525). It also adds/updates regression tests and a dedicated workspace scenario fixture to validate merge commit reordering behavior.

Changes:

  • Update Editor::insert_segment_into() to prepend insertion-location parents as first parents, preserving existing parents as merge-side parents.
  • Add workspace commit-move regression tests for reordering a merge commit above/below while keeping child commits visible.
  • Update insert_segment snapshots and add a new scenario fixture for GB-1525.

Reviewed changes

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

File Description
crates/but-rebase/src/graph_rebase/mutate.rs Introduces prepend_edges_to_parents() and changes parent-edge ordering semantics during segment insertion.
crates/but-rebase/tests/rebase/graph_rebase/insert_segment.rs Updates snapshots to reflect the new parent ordering behavior in segment insertion tests.
crates/but-workspace/tests/workspace/commit/move_commit.rs Adds regression tests verifying merge commit reordering preserves the visible first-parent lane.
crates/but-workspace/tests/fixtures/scenario/gb-1525-reorder-merge-commit.sh Adds a new fixture repo topology used by the workspace regression tests.

Comment thread crates/but-rebase/src/graph_rebase/mutate.rs
Comment thread crates/but-workspace/tests/fixtures/scenario/gb-1525-reorder-merge-commit.sh Outdated

Copilot AI left a comment

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.

Pull request overview

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

Comment thread crates/but-rebase/src/graph_rebase/mutate.rs Outdated

Copilot AI left a comment

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.

Pull request overview

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

Comment thread crates/but-workspace/tests/fixtures/scenario/gb-1525-reorder-merge-commit.sh Outdated
@estib-vega estib-vega force-pushed the insert-segment-improvement branch from 7030a8e to 4160e2b Compare June 11, 2026 08:58
@estib-vega estib-vega marked this pull request as ready for review June 11, 2026 10:08
@estib-vega estib-vega requested a review from krlvi as a code owner June 11, 2026 10:08
Copilot AI review requested due to automatic review settings June 11, 2026 10:08

Copilot AI left a comment

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.

Pull request overview

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

Comment thread crates/but-workspace/tests/fixtures/scenario/gb-1525-reorder-merge-commit.sh Outdated
@estib-vega estib-vega force-pushed the insert-segment-improvement branch from 4160e2b to 1e231cb Compare June 11, 2026 10:13
Comment on lines +511 to +516
fn add_edges_to_parents(
&mut self,
child_node: petgraph::prelude::NodeIndex,
new_parent_nodes: impl IntoIterator<Item = petgraph::prelude::NodeIndex>,
parent_reparenting_order: ParentReparentingOrder,
) {

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.

It seems like this function both deduplicates the list of new parents, and the list of old parents, as well as removing duplicate existing parents if they now show up in the new parents.

git doesn't allow you to create duplicate parents through the CLI, but it does support it in it's data model, and the stance from the git discord server was that it's probably fine to make such a monstrosity.

I'm wondering if the de-duplication is really needed, or if it might end up causing more confusion in the future

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interesting, I didn't know that the data model could handle duplicated parents.

I can take it out

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

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.

LGTM.

Always insert the segments as first parents when inserting below. If
insertng above, inserts the target as the first parent
Copilot AI review requested due to automatic review settings June 12, 2026 16:37
@estib-vega estib-vega force-pushed the insert-segment-improvement branch from 1e231cb to 8bc345e Compare June 12, 2026 16:37
@estib-vega estib-vega enabled auto-merge June 12, 2026 16:37

Copilot AI left a comment

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.

Pull request overview

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

Comment on lines +33 to +41
/// Controls where reparented insertion-location parents are ordered relative to
/// existing parents on the segment.
#[derive(Debug, Clone)]
pub enum ParentReparentingOrder {
/// Put reparented insertion-location parents before existing segment parents.
Prepend,
/// Put reparented insertion-location parents after existing segment parents.
Append,
}
assert_eq!(
parent_subjects(&repo, "HEAD~3")?,
vec!["base".to_string(), "update parent.txt (2)".to_string()],
"moving the merge commit below main should make main's first parent the merge commit's first parent"
@estib-vega estib-vega merged commit 0f772d2 into master Jun 12, 2026
40 checks passed
@estib-vega estib-vega deleted the insert-segment-improvement branch June 12, 2026 16:56
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