| 184 | } |
| 185 | |
| 186 | fn checkout<'a>(repo: &'a Repository, commit_id: &'a str) -> Result<Object<'a>, Error> { |
| 187 | let obj = repo.revparse_single(commit_id).map_err(|err| { |
| 188 | let repo_url = repo |
| 189 | .find_remote("origin") |
| 190 | .map(|remote| remote.url().unwrap_or_default().to_string()) |
| 191 | .unwrap_or_default(); |
| 192 | let msg = format!( |
| 193 | "Unable to use git object commit ID {} on repository {}: {}", |
| 194 | &commit_id, &repo_url, &err |
| 195 | ); |
| 196 | Error::from_str(&msg) |
| 197 | })?; |
| 198 | |
| 199 | // Specify some options to be sure repository is in a clean state |
| 200 | let mut checkout_opts = CheckoutBuilder::new(); |
| 201 | checkout_opts.force().remove_ignored(true).remove_untracked(true); |
| 202 | |
| 203 | repo.reset(&obj, Hard, Some(&mut checkout_opts))?; |
| 204 | Ok(obj) |
| 205 | } |
| 206 | |
| 207 | fn file_content_at_commit(repo: &Repository, commit_id: &str, file_path: &Path) -> Result<Vec<u8>, Error> { |
| 208 | let obj = repo.revparse_single(commit_id).map_err(|err| { |