Skip to content

Commit 9d4c32b

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 648fb0a commit 9d4c32b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/bounds.rs

Lines changed: 3 additions & 1 deletion
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(),

src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,14 @@ impl Config {
916916
self.bisect_ci_via(start, end)
917917
}
918918

919-
fn bisect_ci_via(&self, start_sha: &str, end_ref: &str) -> anyhow::Result<BisectionResult> {
919+
fn bisect_ci_via(&self, start_sha: &str, end_sha: &str) -> anyhow::Result<BisectionResult> {
920920
let access = self.args.access.repo();
921-
let end_sha = access.commit(end_ref)?.sha;
922921
let commits = access.commits(start_sha, &end_sha)?;
923922

924-
assert_eq!(commits.last().expect("at least one commit").sha, end_sha);
923+
let Some(last) = commits.last() else { bail!("expected at least one commit") };
924+
if !last.sha.starts_with(end_sha) {
925+
bail!("expected the last commit to be {end_sha}, but got {}", last.sha);
926+
}
925927

926928
commits.iter().zip(commits.iter().skip(1)).all(|(a, b)| {
927929
let sorted_by_date = a.date <= b.date;
@@ -964,7 +966,7 @@ impl Config {
964966
}
965967

966968
if let Some(c) = commits.last() {
967-
if end != "origin/master" && !c.sha.starts_with(end) {
969+
if !c.sha.starts_with(end) {
968970
bail!("expected to end with {}, but ended with {}", end, c.sha);
969971
}
970972
}

0 commit comments

Comments
 (0)