Skip to content

Allow creating detached remotes #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,7 @@ extern "C" {
repo: *mut git_repository,
url: *const c_char,
) -> c_int;
pub fn git_remote_create_detached(out: *mut *mut git_remote, url: *const c_char) -> c_int;
pub fn git_remote_delete(repo: *mut git_repository, name: *const c_char) -> c_int;
pub fn git_remote_free(remote: *mut git_remote);
pub fn git_remote_name(remote: *const git_remote) -> *const c_char;
Expand Down
16 changes: 16 additions & 0 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ impl<'repo> Remote<'repo> {
unsafe { raw::git_remote_is_valid_name(remote_name.as_ptr()) == 1 }
}

/// Create a detached remote
///
/// Create a remote with the given url in-memory. You can use this
/// when you have a URL instead of a remote's name.
/// Contrasted with an anonymous remote, a detached remote will not
/// consider any repo configuration values.
pub fn create_detached(url: &str) -> Result<Remote<'_>, Error> {
crate::init();
let mut ret = ptr::null_mut();
let url = CString::new(url)?;
unsafe {
try_call!(raw::git_remote_create_detached(&mut ret, url));
Ok(Binding::from_raw(ret))
}
}

/// Get the remote's name.
///
/// Returns `None` if this remote has not yet been named or if the name is
Expand Down