node: Use default branch
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
parent
6830a044d7
commit
6e86218c36
|
|
@ -7,7 +7,7 @@ use thiserror::Error;
|
||||||
use crate::git;
|
use crate::git;
|
||||||
use crate::identity::ProjId;
|
use crate::identity::ProjId;
|
||||||
use crate::storage::git::RADICLE_ID_REF;
|
use crate::storage::git::RADICLE_ID_REF;
|
||||||
use crate::storage::ReadRepository as _;
|
use crate::storage::{BranchName, ReadRepository as _};
|
||||||
use crate::{identity, storage};
|
use crate::{identity, storage};
|
||||||
|
|
||||||
pub const REMOTE_NAME: &str = "rad";
|
pub const REMOTE_NAME: &str = "rad";
|
||||||
|
|
@ -35,6 +35,7 @@ pub fn init<S: storage::WriteStorage>(
|
||||||
repo: &git2::Repository,
|
repo: &git2::Repository,
|
||||||
name: &str,
|
name: &str,
|
||||||
description: &str,
|
description: &str,
|
||||||
|
default_branch: BranchName,
|
||||||
storage: S,
|
storage: S,
|
||||||
) -> Result<ProjId, InitError> {
|
) -> Result<ProjId, InitError> {
|
||||||
let user_id = storage.user_id();
|
let user_id = storage.user_id();
|
||||||
|
|
@ -43,18 +44,10 @@ pub fn init<S: storage::WriteStorage>(
|
||||||
name: String::from("anonymous"),
|
name: String::from("anonymous"),
|
||||||
id: identity::Did::from(*user_id),
|
id: identity::Did::from(*user_id),
|
||||||
};
|
};
|
||||||
|
|
||||||
let head = repo.head()?;
|
|
||||||
let default_branch = if head.is_branch() {
|
|
||||||
head.shorthand().ok_or(InitError::InvalidHead)?.to_owned()
|
|
||||||
} else {
|
|
||||||
return Err(InitError::DetachedHead);
|
|
||||||
};
|
|
||||||
|
|
||||||
let doc = identity::Doc {
|
let doc = identity::Doc {
|
||||||
name: name.to_owned(),
|
name: name.to_owned(),
|
||||||
description: description.to_owned(),
|
description: description.to_owned(),
|
||||||
default_branch,
|
default_branch: default_branch.clone(),
|
||||||
version: 1,
|
version: 1,
|
||||||
parent: None,
|
parent: None,
|
||||||
delegate: NonEmpty::new(delegate),
|
delegate: NonEmpty::new(delegate),
|
||||||
|
|
@ -107,9 +100,8 @@ pub fn init<S: storage::WriteStorage>(
|
||||||
git::set_upstream(
|
git::set_upstream(
|
||||||
repo,
|
repo,
|
||||||
REMOTE_NAME,
|
REMOTE_NAME,
|
||||||
// FIXME: Should use default branch here.
|
&default_branch,
|
||||||
"master",
|
&format!("refs/remotes/{user_id}/heads/{default_branch}"),
|
||||||
&format!("refs/remotes/{user_id}/heads/master"),
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// TODO: Note that you'll likely want to use `RemoteCallbacks` and set
|
// TODO: Note that you'll likely want to use `RemoteCallbacks` and set
|
||||||
|
|
@ -117,7 +109,7 @@ pub fn init<S: storage::WriteStorage>(
|
||||||
// successfully.
|
// successfully.
|
||||||
remote.push::<&str>(
|
remote.push::<&str>(
|
||||||
&[
|
&[
|
||||||
&format!("refs/heads/master:refs/remotes/{user_id}/heads/master"),
|
&format!("refs/heads/{default_branch}:refs/remotes/{user_id}/heads/{default_branch}"),
|
||||||
&format!("{rad_id_ref}:refs/remotes/{user_id}/heads/rad/id"),
|
&format!("{rad_id_ref}:refs/remotes/{user_id}/heads/rad/id"),
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
|
|
@ -144,6 +136,13 @@ mod tests {
|
||||||
let head = git::commit(&repo, &head, "Second commit", "anonymous").unwrap();
|
let head = git::commit(&repo, &head, "Second commit", "anonymous").unwrap();
|
||||||
let _branch = repo.branch("master", &head, false).unwrap();
|
let _branch = repo.branch("master", &head, false).unwrap();
|
||||||
|
|
||||||
init(&repo, "acme", "Acme's repo", &mut storage).unwrap();
|
init(
|
||||||
|
&repo,
|
||||||
|
"acme",
|
||||||
|
"Acme's repo",
|
||||||
|
BranchName::from("master"),
|
||||||
|
&mut storage,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue