| - |
use std::collections::BTreeSet;
|
| - |
use std::str::FromStr;
|
| - |
|
| |
use radicle::git;
|
| - |
use radicle::identity::project::ProjectName;
|
| - |
use radicle::identity::{doc, Project, RepoId, Visibility};
|
| - |
use radicle::rad::InitError;
|
| - |
use radicle::storage::git::Repository;
|
| - |
use radicle::storage::refs::branch_of;
|
| - |
use radicle::storage::{SignRepository, WriteRepository};
|
| + |
use radicle::identity::RepoId;
|
| |
use radicle_types as types;
|
| |
use radicle_types::error::Error;
|
| |
use radicle_types::traits::repo::{Repo, Show};
|
| |
}
|
| |
|
| |
#[tauri::command]
|
| - |
pub(crate) async fn create_repo(
|
| - |
ctx: tauri::State<'_, AppState>,
|
| - |
name: String,
|
| - |
description: String,
|
| - |
) -> Result<(), Error> {
|
| - |
let profile = &ctx.profile;
|
| - |
let storage = &profile.storage;
|
| - |
let signer = ctx.profile.signer()?;
|
| - |
let config = git2::Config::open_default()?;
|
| - |
// SAFETY: "master" is always a valid RefString
|
| - |
let default_branch = git::fmt::RefString::try_from(
|
| - |
config
|
| - |
.get_string("init.defaultBranch")
|
| - |
.unwrap_or("master".to_owned()),
|
| - |
)
|
| - |
.unwrap();
|
| - |
|
| - |
let name = ProjectName::from_str(&name)?;
|
| - |
if description.len() > doc::MAX_STRING_LENGTH {
|
| - |
return Err(Error::ProjectError(
|
| - |
radicle::identity::project::ProjectError::Description("Cannot exceed 255 characters."),
|
| - |
));
|
| - |
}
|
| - |
|
| - |
let visibility = Visibility::Private {
|
| - |
allow: BTreeSet::default(),
|
| - |
};
|
| - |
|
| - |
let proj = Project::new(name, description, default_branch.clone()).map_err(|errs| {
|
| - |
InitError::ProjectPayload(
|
| - |
errs.into_iter()
|
| - |
.map(|err| err.to_string())
|
| - |
.collect::<Vec<_>>()
|
| - |
.join(", "),
|
| - |
)
|
| - |
})?;
|
| - |
let doc = radicle::identity::Doc::initial(proj, profile.public_key.into(), visibility);
|
| - |
let (project, identity) = Repository::init(&doc, &storage, &signer)?;
|
| - |
|
| - |
let tree_id = {
|
| - |
let mut index = project.backend.index()?;
|
| - |
|
| - |
index.write_tree()
|
| - |
}?;
|
| - |
let sig = project.backend.signature()?;
|
| - |
let tree = project.backend.find_tree(tree_id)?;
|
| - |
|
| - |
project.set_remote_identity_root_to(signer.public_key(), identity)?;
|
| - |
project.set_identity_head_to(identity)?;
|
| - |
|
| - |
let base = project
|
| - |
.backend
|
| - |
.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[])?;
|
| - |
|
| - |
let ns_head = branch_of(&ctx.profile.public_key, &default_branch);
|
| - |
project
|
| - |
.backend
|
| - |
.reference(ns_head.as_str(), base, false, "Created namespace ref")?;
|
| - |
|
| - |
project.set_canonical_symbolic_refs("set-canonical from create_repo")?;
|
| - |
project.set_default_branch_to_canonical_head()?;
|
| - |
project.sign_refs(&signer)?;
|
| - |
|
| - |
Ok(())
|
| - |
}
|
| - |
|
| - |
#[tauri::command]
|
| |
pub fn seed(ctx: tauri::State<AppState>, rid: RepoId) -> Result<(), Error> {
|
| |
ctx.seed(rid)
|
| |
}
|