Skip to content

Commit d644db3

Browse files
committed
Don't use an outcome status for now
1 parent a26a591 commit d644db3

File tree

7 files changed

+53
-50
lines changed

7 files changed

+53
-50
lines changed

crates/but-rebase/src/graph_rebase/mutate.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Operations for mutation the editor
22
3+
use anyhow::{Result, anyhow};
34
use petgraph::{Direction, visit::EdgeRef};
45

56
use crate::graph_rebase::{Edge, Editor, Selector, Step};
@@ -18,7 +19,25 @@ pub enum InsertSide {
1819
/// Operations for mutating the commit graph
1920
impl Editor {
2021
/// Get a selector to a particular commit in the graph
21-
pub fn select_commit(&self, target: gix::ObjectId) -> Option<Selector> {
22+
pub fn select_commit(&self, target: gix::ObjectId) -> Result<Selector> {
23+
match self.try_select_commit(target) {
24+
Some(selector) => Ok(selector),
25+
None => Err(anyhow!("Failed to find commit {target} in rebase editor")),
26+
}
27+
}
28+
29+
/// Get a selector to a particular reference in the graph
30+
pub fn select_reference(&self, target: &gix::refs::FullNameRef) -> Result<Selector> {
31+
match self.try_select_reference(target) {
32+
Some(selector) => Ok(selector),
33+
None => Err(anyhow!(
34+
"Failed to find reference {target} in rebase editor"
35+
)),
36+
}
37+
}
38+
39+
/// Get a selector to a particular commit in the graph
40+
pub fn try_select_commit(&self, target: gix::ObjectId) -> Option<Selector> {
2241
for node_idx in self.graph.node_indices() {
2342
if let Step::Pick { id, .. } = self.graph[node_idx]
2443
&& id == target
@@ -31,7 +50,7 @@ impl Editor {
3150
}
3251

3352
/// Get a selector to a particular reference in the graph
34-
pub fn select_reference(&self, target: &gix::refs::FullNameRef) -> Option<Selector> {
53+
pub fn try_select_reference(&self, target: &gix::refs::FullNameRef) -> Option<Selector> {
3554
for node_idx in self.graph.node_indices() {
3655
if let Step::Reference { refname } = &self.graph[node_idx]
3756
&& target == refname.as_ref()

crates/but-rebase/src/graph_rebase/rebase.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,9 @@ pub struct SuccessfulRebase {
3131
pub(crate) checkouts: Vec<Checkouts>,
3232
}
3333

34-
/// Represents the rebase output and the varying degrees of success it had.
35-
#[derive(Debug, Clone)]
36-
#[expect(clippy::large_enum_variant)]
37-
#[must_use = "Rebase does nothing to affect the commit graph unless materialized"]
38-
pub enum RebaseOutcome {
39-
/// The rebase
40-
Success(SuccessfulRebase),
41-
/// The graph rebase failed because we encountered a situation where we
42-
/// couldn't merge bases.
43-
///
44-
/// Holds the gix::ObjectId of the commit it failed to pick
45-
MergePickFailed(gix::ObjectId),
46-
}
47-
4834
impl Editor {
4935
/// Perform the rebase
50-
pub fn rebase(self) -> Result<RebaseOutcome> {
36+
pub fn rebase(self) -> Result<SuccessfulRebase> {
5137
// First we want to get a list of nodes that can be reached by
5238
// traversing downwards from the heads that we care about.
5339
// Usually there would be just one "head" which is an index to access
@@ -115,7 +101,8 @@ impl Editor {
115101
}
116102
CherryPickOutcome::FailedToMergeBases => {
117103
// Exit early - the rebase failed because it encountered a commit it couldn't pick
118-
return Ok(RebaseOutcome::MergePickFailed(id));
104+
// TODO(CTO): Detect if this was the merge commit itself & signal that seperatly
105+
bail!("Failed to merge bases for commit {id}");
119106
}
120107
}
121108
}
@@ -214,14 +201,14 @@ impl Editor {
214201
}
215202
}
216203

217-
Ok(RebaseOutcome::Success(SuccessfulRebase {
204+
Ok(SuccessfulRebase {
218205
repo: self.repo,
219206
ref_edits,
220207
commit_mapping,
221208
graph_mapping,
222209
graph: output_graph,
223210
checkouts: self.checkouts.to_owned(),
224-
}))
211+
})
225212
}
226213
}
227214

crates/but-rebase/tests/rebase/graph_rebase/insert.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! These tests exercise the insert operation.
2-
use anyhow::{Context, Result, bail};
2+
use anyhow::{Context, Result};
33
use but_graph::Graph;
4-
use but_rebase::graph_rebase::{GraphExt, Step, mutate::InsertSide, rebase::RebaseOutcome};
4+
use but_rebase::graph_rebase::{GraphExt, Step, mutate::InsertSide};
55
use but_testsupport::{git_status, visualize_commit_graph_all};
66

77
use crate::{
@@ -54,9 +54,6 @@ fn insert_below_merge_commit() -> Result<()> {
5454
);
5555

5656
let outcome = editor.rebase()?;
57-
let RebaseOutcome::Success(outcome) = outcome else {
58-
bail!("Rebase failed");
59-
};
6057
outcome.materialize()?;
6158

6259
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r"
@@ -120,9 +117,6 @@ fn insert_above_commit_with_two_children() -> Result<()> {
120117
);
121118

122119
let outcome = editor.rebase()?;
123-
let RebaseOutcome::Success(outcome) = outcome else {
124-
bail!("Rebase failed");
125-
};
126120
outcome.materialize()?;
127121

128122
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r"
@@ -140,3 +134,9 @@ fn insert_above_commit_with_two_children() -> Result<()> {
140134

141135
Ok(())
142136
}
137+
138+
#[test]
139+
#[ignore]
140+
fn inserts_violating_fp_protection_should_cause_rebase_failure() -> Result<()> {
141+
panic!("Branch protection hasn't been implemented dyet");
142+
}

crates/but-rebase/tests/rebase/graph_rebase/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod cherry_pick;
22
mod editor_creation;
33
mod insert;
4+
mod multiple_operations;
45
mod rebase_identities;
56
mod replace;
67

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! These tests exercise the replace operation.
2+
use anyhow::Result;
3+
4+
#[test]
5+
#[ignore = "non-legacy reordering is not implemented, and should be considered a requirement for any operations that want to work in SBM"]
6+
fn reorder_two_references() -> Result<()> {
7+
panic!("Reference orders are not updated");
8+
}

crates/but-rebase/tests/rebase/graph_rebase/rebase_identities.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/// These tests demonstrate that if none of the steps are changed, the same
22
/// graphs are returned.
3-
use anyhow::{Result, bail};
3+
use anyhow::Result;
44
use but_graph::Graph;
5-
use but_rebase::graph_rebase::{GraphExt, rebase::RebaseOutcome};
5+
use but_rebase::graph_rebase::GraphExt;
66
use but_testsupport::{graph_workspace, visualize_commit_graph_all};
77

88
use crate::utils::{fixture_writable, standard_options};
@@ -23,9 +23,6 @@ fn four_commits() -> Result<()> {
2323

2424
let editor = graph.to_editor(&repo)?;
2525
let outcome = editor.rebase()?;
26-
let RebaseOutcome::Success(outcome) = outcome else {
27-
bail!("Rebase failed");
28-
};
2926
outcome.materialize()?;
3027

3128
assert_eq!(visualize_commit_graph_all(&repo)?, before);
@@ -59,9 +56,6 @@ fn four_commits_with_short_traversal() -> Result<()> {
5956

6057
let editor = graph.to_editor(&repo)?;
6158
let outcome = editor.rebase()?;
62-
let RebaseOutcome::Success(outcome) = outcome else {
63-
bail!("Rebase failed");
64-
};
6559
outcome.materialize()?;
6660

6761
assert_eq!(visualize_commit_graph_all(&repo)?, before);
@@ -88,9 +82,6 @@ fn merge_in_the_middle() -> Result<()> {
8882

8983
let editor = graph.to_editor(&repo)?;
9084
let outcome = editor.rebase()?;
91-
let RebaseOutcome::Success(outcome) = outcome else {
92-
bail!("Rebase failed");
93-
};
9485
outcome.materialize()?;
9586

9687
assert_eq!(visualize_commit_graph_all(&repo)?, before);
@@ -121,9 +112,6 @@ fn three_branches_merged() -> Result<()> {
121112

122113
let editor = graph.to_editor(&repo)?;
123114
let outcome = editor.rebase()?;
124-
let RebaseOutcome::Success(outcome) = outcome else {
125-
bail!("Rebase failed");
126-
};
127115
outcome.materialize()?;
128116

129117
assert_eq!(visualize_commit_graph_all(&repo)?, before);

crates/but-rebase/tests/rebase/graph_rebase/replace.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! These tests exercise the replace operation.
2-
use anyhow::{Context, Result, bail};
2+
use anyhow::{Context, Result};
33
use but_graph::Graph;
4-
use but_rebase::graph_rebase::{GraphExt, Step, rebase::RebaseOutcome};
4+
use but_rebase::graph_rebase::{GraphExt, Step};
55
use but_testsupport::{git_status, visualize_commit_graph_all, visualize_tree};
66

77
use crate::{
@@ -55,9 +55,6 @@ fn reword_a_commit() -> Result<()> {
5555
);
5656

5757
let outcome = editor.rebase()?;
58-
let RebaseOutcome::Success(outcome) = outcome else {
59-
bail!("Rebase failed");
60-
};
6158
outcome.materialize()?;
6259

6360
assert_eq!(head_tree, repo.head_tree()?.id);
@@ -139,9 +136,6 @@ fn ammend_a_commit() -> Result<()> {
139136
);
140137

141138
let outcome = editor.rebase()?;
142-
let RebaseOutcome::Success(outcome) = outcome else {
143-
bail!("Rebase failed");
144-
};
145139
outcome.materialize()?;
146140

147141
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r"
@@ -176,3 +170,9 @@ fn ammend_a_commit() -> Result<()> {
176170

177171
Ok(())
178172
}
173+
174+
#[test]
175+
#[ignore]
176+
fn replaces_violating_fp_protection_should_cause_rebase_failure() -> Result<()> {
177+
panic!("Branch protection hasn't been implemented dyet");
178+
}

0 commit comments

Comments
 (0)