Skip to content

Commit

Permalink
💩 add workaround for a bug in git2 0.14
Browse files Browse the repository at this point in the history
- see rust-lang/git2-rs#819
- else segfault on `cargo run -- test-samples --source https://github.com/ffizer/template_sample.git --rev "3ab3bc67b5fab58ceecc031f7ed0eb29c0e0fff8" `
  • Loading branch information
davidB committed Mar 13, 2022
1 parent 7b52db1 commit 5664d16
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,20 @@ where
let repository = Repository::discover(dst.as_ref())?;

// fetch
let revref = rev.as_ref();
let mut revref = rev.as_ref().to_string();
//FIXME workaround see https://github.com/rust-lang/git2-rs/issues/819
if revref.len() == 40
&& revref
.chars()
.all(|c| (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'))
{
revref = format!("+{}:{}", rev.as_ref(), rev.as_ref());
}
let mut remote = repository.find_remote("origin")?;
remote.fetch(&[revref], Some(fo), None)?;
let reference = repository.find_reference("FETCH_HEAD")?;
let fetch_head_commit = repository.reference_to_annotated_commit(&reference)?;
do_merge(&repository, "master", fetch_head_commit)?;
do_merge(&repository, rev.as_ref(), fetch_head_commit)?;
Ok(())
}

Expand Down Expand Up @@ -257,6 +265,7 @@ pub fn find_cmd_tool(kind: &str) -> Result<String, git2::Error> {
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use run_script;
use std::fs;
use tempfile::tempdir;
Expand Down

0 comments on commit 5664d16

Please sign in to comment.