Created
December 28, 2023 11:49
-
-
Save JEnoch/36750b89d7f40dec90afbed076f76736 to your computer and use it in GitHub Desktop.
Test `git2::Repository::revparse_single()`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::path::Path; | |
fn main() { | |
use git2::Repository; | |
let url = "https://github.com/not-an-aardvark/every-git-commit-shorthash.git"; | |
let repo_dir = Path::new("./target/every-git-commit-shorthash"); | |
let repo = if repo_dir.exists() { | |
if repo_dir.is_dir() { | |
match Repository::open(repo_dir.to_string_lossy().as_ref()) { | |
Ok(repo) => repo, | |
Err(e) => panic!("failed to open: {}", e), | |
} | |
} else { | |
panic!( | |
"{} exists but is not a directory", | |
repo_dir.to_string_lossy() | |
); | |
} | |
} else { | |
match Repository::clone(url, repo_dir.to_string_lossy().as_ref()) { | |
Ok(repo) => repo, | |
Err(e) => panic!("failed to clone: {}", e), | |
} | |
}; | |
let id = "0000000"; | |
println!(r#"revparse_single("{}") => {:?}"#, id, repo.revparse_single(id)); | |
// output: revparse_single("0000000") => Err(Error { code: -5, klass: 9, message: "ambiguous OID prefix - found multiple offsets for pack entry" }) | |
let id = "00000002b"; | |
println!(r#"revparse_single("{}") => {:?}"#, id, repo.revparse_single(id)); | |
// output: revparse_single("00000002b") => Ok(Object { kind: Commit, id: 00000002bdd056473559d2bd0eb835561b3c874b }) | |
let id = "00000002f"; | |
println!(r#"revparse_single("{}") => {:?}"#, id, repo.revparse_single(id)); | |
// output: revparse_single("00000002f") => Ok(Object { kind: Commit, id: 00000002f7c605501165ee5e3c2db20ffe178848 }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment