node: Implement project checkout

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-09-13 10:16:05 +02:00
parent 09265eb3da
commit 4e9b60dee0
6 changed files with 154 additions and 23 deletions
+26
View File
@@ -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