Skip to content

Commit 0ec0fb3

Browse files
committed
Don't allow Bounds::Commits to contain non-hashes.
There was only ever one case of it containing a non-hash, and that was when `--start` was a hash, and `--end` was not specified. In that case, it was "origin/master", and then converted to a hash later on. To simplify things, this converts `origin/master` to master's actual commit early when the `Bounds` is created.
1 parent bb4b61f commit 0ec0fb3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Diff for: src/bounds.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub enum Bounds {
6161
/// date where the regression does not occur.
6262
SearchNightlyBackwards { end: GitDate },
6363
/// Search between two commits.
64+
///
65+
/// `start` and `end` must be SHA1 hashes of the commit object.
6466
Commits { start: String, end: String },
6567
/// Search between two dates.
6668
Dates { start: GitDate, end: GitDate },
@@ -91,7 +93,7 @@ impl Bounds {
9193
}
9294
(Some(Bound::Commit(start)), None) => Bounds::Commits {
9395
start,
94-
end: "origin/master".to_string(),
96+
end: args.access.repo().commit("origin/master")?.sha,
9597
},
9698
(None, Some(Bound::Commit(end))) => Bounds::Commits {
9799
start: EPOCH_COMMIT.to_string(),

Diff for: src/main.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -947,10 +947,10 @@ impl Config {
947947
self.bisect_ci_via(start, end)
948948
}
949949

950-
fn bisect_ci_via(&self, start_sha: &str, end_ref: &str) -> anyhow::Result<BisectionResult> {
950+
fn bisect_ci_via(&self, start_sha: &str, end_sha: &str) -> anyhow::Result<BisectionResult> {
951951
let access = self.args.access.repo();
952952
let start = access.commit(start_sha)?;
953-
let end = access.commit(end_ref)?;
953+
let end = access.commit(end_sha)?;
954954
let assert_by_bors = |c: &Commit| -> anyhow::Result<()> {
955955
if c.committer.name != BORS_AUTHOR {
956956
bail!(
@@ -967,7 +967,15 @@ impl Config {
967967
assert_by_bors(&end)?;
968968
let commits = access.commits(start_sha, &end.sha)?;
969969

970-
assert_eq!(commits.last().expect("at least one commit").sha, end.sha);
970+
let Some(last) = commits.last() else {
971+
bail!("expected at least one commit");
972+
};
973+
if !last.sha.starts_with(&end.sha) {
974+
bail!(
975+
"expected the last commit to be {end_sha}, but got {}",
976+
last.sha
977+
);
978+
}
971979

972980
commits.iter().zip(commits.iter().skip(1)).all(|(a, b)| {
973981
let sorted_by_date = a.date <= b.date;
@@ -1010,7 +1018,7 @@ impl Config {
10101018
}
10111019

10121020
if let Some(c) = commits.last() {
1013-
if end != "origin/master" && !c.sha.starts_with(end) {
1021+
if !c.sha.starts_with(end) {
10141022
bail!("expected to end with {}, but ended with {}", end, c.sha);
10151023
}
10161024
}

0 commit comments

Comments
 (0)