From fb614e00ab933b34eeaf9a302dd68cbc53394964 Mon Sep 17 00:00:00 2001 From: vlad-anger Date: Thu, 27 Feb 2025 22:32:57 -0300 Subject: [PATCH 1/2] expose libgit2 `git_branch_upstream_merge` --- libgit2-sys/lib.rs | 5 +++++ src/repo.rs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index bf0f107755..06b75cbc4d 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -3018,6 +3018,11 @@ extern "C" { repo: *mut git_repository, refname: *const c_char, ) -> c_int; + pub fn git_branch_upstream_merge( + out: *mut git_buf, + repo: *mut git_repository, + refname: *const c_char, + ) -> c_int; // index pub fn git_index_version(index: *mut git_index) -> c_uint; diff --git a/src/repo.rs b/src/repo.rs index 074955f623..dd8ae50d0f 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -3136,6 +3136,23 @@ impl Repository { } } + /// Retrieve the upstream merge of a local branch, + /// configured in "branch.*.merge" + /// + /// `refname` must be in the form `refs/heads/{branch_name}` + pub fn branch_upstream_merge(&self, refname: &str) -> Result { + let refname = CString::new(refname)?; + unsafe { + let buf = Buf::new(); + try_call!(raw::git_branch_upstream_merge( + buf.raw(), + self.raw, + refname + )); + Ok(buf) + } + } + /// Apply a Diff to the given repo, making changes directly in the working directory, the index, or both. pub fn apply( &self, From 84e39e49d9ca2f7a65f58a94aec60f5568640ff4 Mon Sep 17 00:00:00 2001 From: vlad-anger Date: Thu, 27 Feb 2025 22:40:35 -0300 Subject: [PATCH 2/2] fix formatting --- src/repo.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/repo.rs b/src/repo.rs index dd8ae50d0f..19f8c1f511 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -3138,17 +3138,13 @@ impl Repository { /// Retrieve the upstream merge of a local branch, /// configured in "branch.*.merge" - /// + /// /// `refname` must be in the form `refs/heads/{branch_name}` pub fn branch_upstream_merge(&self, refname: &str) -> Result { let refname = CString::new(refname)?; unsafe { let buf = Buf::new(); - try_call!(raw::git_branch_upstream_merge( - buf.raw(), - self.raw, - refname - )); + try_call!(raw::git_branch_upstream_merge(buf.raw(), self.raw, refname)); Ok(buf) } }