Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tests: exercise more commit swapping with arrange
  • Loading branch information
higgsd committed Mar 14, 2026
commit 6eecb81f71c3bcb62f68008f30f2e129a18c512f
125 changes: 114 additions & 11 deletions cli/src/commands/arrange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,16 +723,16 @@ mod tests {
let store = test_repo.repo.store();
let empty_tree = store.empty_merged_tree();

// Swap C and D:
// f f
// | |
// D e C e
// |\| |\|
// B C => B D
// |/ |/
// A A
// | |
// root root
// Construct the graph:
// f
// |
// D e
// |\|
// B C
// |/
// A
// |
// root
//
// Lowercase nodes are external to the set
let mut tx = test_repo.repo.start_transaction();
Expand Down Expand Up @@ -770,7 +770,17 @@ mod tests {
]
);

// Swap C and D and check result
// Swap D and C:
// f f
// | |
// D e C e
// |\| |\|
// B C => B D
// |/ |/
// A A
// | |
// root root
//
state.swap_commits(0, 2);
assert_eq!(state.head_order, vec![commit_c.id().clone()]);
assert_eq!(
Expand Down Expand Up @@ -799,6 +809,99 @@ mod tests {
*state.commits.get(commit_f.id()).unwrap().parents,
vec![commit_c.id().clone()],
);

// Swap B and D:
// f f
// | |
// C e C e
// |\| |\|
// B D => D B
// |/ |/
// A A
// | |
// root root
//
state.swap_commits(1, 2);
assert_eq!(state.head_order, vec![commit_c.id().clone()]);
assert_eq!(
state.current_order,
vec![
commit_c.id().clone(),
commit_d.id().clone(),
commit_b.id().clone(),
commit_a.id().clone()
]
);
assert_eq!(state.current_selection, 1);
assert_eq!(
*state.commits.get(commit_c.id()).unwrap().parents,
vec![commit_d.id().clone(), commit_b.id().clone()],
);
assert_eq!(
*state.commits.get(commit_d.id()).unwrap().parents,
vec![commit_a.id().clone()],
);
assert_eq!(
*state.commits.get(commit_b.id()).unwrap().parents,
vec![commit_a.id().clone()],
);
assert_eq!(
*state.commits.get(commit_e.id()).unwrap().parents,
vec![commit_b.id().clone()],
);

// Swap A and C:
// f f
// | |
// C e A e
// |\| |\|
// D B => D B
// |/ |/
// A C
// | |
// root root
//
state.swap_commits(3, 0);
assert_eq!(state.head_order, vec![commit_a.id().clone()]);
assert_eq!(
state.current_order,
vec![
commit_a.id().clone(),
commit_d.id().clone(),
commit_b.id().clone(),
commit_c.id().clone()
]
);
assert_eq!(state.current_selection, 1);
assert_eq!(
*state.commits.get(commit_a.id()).unwrap().parents,
vec![commit_d.id().clone(), commit_b.id().clone()],
);
assert_eq!(
*state.commits.get(commit_d.id()).unwrap().parents,
vec![commit_c.id().clone()],
);
assert_eq!(
*state.commits.get(commit_b.id()).unwrap().parents,
vec![commit_c.id().clone()],
);
assert_eq!(
*state.commits.get(commit_f.id()).unwrap().parents,
vec![commit_a.id().clone()],
);

// No-op swap
state.swap_commits(0, 0);
assert_eq!(state.current_selection, 1);
assert_eq!(
state.current_order,
vec![
commit_a.id().clone(),
commit_d.id().clone(),
commit_b.id().clone(),
commit_c.id().clone()
]
);
}

#[test]
Expand Down