Skip to content

Commit 3a85308

Browse files
authored
Allow creating detached remotes (#641)
* Add git_remote_create_detached fn definition * Add Remote::create_detached associated fn * Run cargo fmt * Init crate on detached remote create
1 parent e42d595 commit 3a85308

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

libgit2-sys/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,7 @@ extern "C" {
20412041
repo: *mut git_repository,
20422042
url: *const c_char,
20432043
) -> c_int;
2044+
pub fn git_remote_create_detached(out: *mut *mut git_remote, url: *const c_char) -> c_int;
20442045
pub fn git_remote_delete(repo: *mut git_repository, name: *const c_char) -> c_int;
20452046
pub fn git_remote_free(remote: *mut git_remote);
20462047
pub fn git_remote_name(remote: *const git_remote) -> *const c_char;

src/remote.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ impl<'repo> Remote<'repo> {
7373
unsafe { raw::git_remote_is_valid_name(remote_name.as_ptr()) == 1 }
7474
}
7575

76+
/// Create a detached remote
77+
///
78+
/// Create a remote with the given url in-memory. You can use this
79+
/// when you have a URL instead of a remote's name.
80+
/// Contrasted with an anonymous remote, a detached remote will not
81+
/// consider any repo configuration values.
82+
pub fn create_detached(url: &str) -> Result<Remote<'_>, Error> {
83+
crate::init();
84+
let mut ret = ptr::null_mut();
85+
let url = CString::new(url)?;
86+
unsafe {
87+
try_call!(raw::git_remote_create_detached(&mut ret, url));
88+
Ok(Binding::from_raw(ret))
89+
}
90+
}
91+
7692
/// Get the remote's name.
7793
///
7894
/// Returns `None` if this remote has not yet been named or if the name is

0 commit comments

Comments
 (0)