Skip to content

Commit 4645429

Browse files
committed
Use libgit bindings to merge-base instead of running a subcommand
1 parent a1db20e commit 4645429

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/main.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,14 @@ fn get_upstream<'a>(
138138
}
139139
};
140140

141-
let result = Command::new("git")
142-
.args(&[
143-
"merge-base",
144-
head_branch.name().unwrap().unwrap(),
145-
&upstream.id().to_string(),
146-
])
147-
.output()?
148-
.stdout;
149-
let oid = Oid::from_str(std::str::from_utf8(&result)?.trim())?;
150-
let commit = repo.find_object(oid, None).unwrap();
141+
let mb = repo.merge_base(
142+
head_branch
143+
.get()
144+
.target()
145+
.expect("all branches should ahve a target"),
146+
upstream.id(),
147+
)?;
148+
let commit = repo.find_object(mb, None).unwrap();
151149

152150
Ok(Some(commit))
153151
}

0 commit comments

Comments
 (0)