From 08114526f83fb64c1620161891a0339da3929b15 Mon Sep 17 00:00:00 2001 From: Andrew Hickman Date: Mon, 2 Mar 2020 14:42:47 +0000 Subject: [PATCH] Add Repository::fetchhead_to_annotated_commit (#524) --- libgit2-sys/lib.rs | 7 +++++++ src/repo.rs | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index b6ad79ab4c..b3f281c648 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -2828,6 +2828,13 @@ extern "C" { repo: *mut git_repository, reference: *const git_reference, ) -> c_int; + pub fn git_annotated_commit_from_fetchhead( + out: *mut *mut git_annotated_commit, + repo: *mut git_repository, + branch_name: *const c_char, + remote_url: *const c_char, + oid: *const git_oid, + ) -> c_int; pub fn git_annotated_commit_free(commit: *mut git_annotated_commit); pub fn git_merge_init_options(opts: *mut git_merge_options, version: c_uint) -> c_int; pub fn git_merge( diff --git a/src/repo.rs b/src/repo.rs index 29ca2b37f9..89a40b53a1 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1442,6 +1442,29 @@ impl Repository { } } + /// Creates a git_annotated_commit from FETCH_HEAD. + pub fn annotated_commit_from_fetchhead( + &self, + branch_name: &str, + remote_url: &str, + id: &Oid, + ) -> Result, Error> { + let branch_name = CString::new(branch_name)?; + let remote_url = CString::new(remote_url)?; + + let mut ret = ptr::null_mut(); + unsafe { + try_call!(raw::git_annotated_commit_from_fetchhead( + &mut ret, + self.raw(), + branch_name, + remote_url, + id.raw() + )); + Ok(AnnotatedCommit::from_raw(ret)) + } + } + /// Create a new action signature with default user and now timestamp. /// /// This looks up the user.name and user.email from the configuration and