mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-09 05:10:28 +08:00
node: Implement project checkout
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
|
||||
use git_ref_format as format;
|
||||
@@ -9,6 +10,7 @@ use crate::storage::RemoteId;
|
||||
|
||||
pub use ext::Oid;
|
||||
pub use git_ref_format::{refname, RefStr, RefString};
|
||||
pub use git_url as url;
|
||||
pub use git_url::Url;
|
||||
pub use radicle_git_ext as ext;
|
||||
|
||||
@@ -97,6 +99,30 @@ pub fn commit<'a>(
|
||||
Ok(commit)
|
||||
}
|
||||
|
||||
/// Configure a repository's radicle remote.
|
||||
///
|
||||
/// Takes the repository in which to configure the remote, the name of the remote, the public
|
||||
/// key of the remote, and the path to the remote repository on the filesystem.
|
||||
pub fn configure_remote<'r>(
|
||||
repo: &'r git2::Repository,
|
||||
remote_name: &str,
|
||||
remote_id: &RemoteId,
|
||||
remote_path: &Path,
|
||||
) -> Result<git2::Remote<'r>, git2::Error> {
|
||||
let url = Url {
|
||||
scheme: git_url::Scheme::File,
|
||||
path: remote_path.to_string_lossy().to_string().into(),
|
||||
|
||||
..Url::default()
|
||||
};
|
||||
let fetch = format!("+refs/remotes/{remote_id}/heads/*:refs/remotes/rad/*");
|
||||
let push = format!("refs/heads/*:refs/remotes/{remote_id}/heads/*");
|
||||
let remote = repo.remote_with_fetch(remote_name, url.to_string().as_str(), &fetch)?;
|
||||
repo.remote_add_push(remote_name, &push)?;
|
||||
|
||||
Ok(remote)
|
||||
}
|
||||
|
||||
/// Set the upstream of the given branch to the given remote.
|
||||
///
|
||||
/// This writes to the `config` directly. The entry will look like the
|
||||
|
||||
Reference in New Issue
Block a user