radicle-cli: Test initializing from bare repos
This commit is contained in:
parent
606882f01f
commit
e528c40a07
|
|
@ -0,0 +1,4 @@
|
|||
```
|
||||
$ git rev-parse --is-bare-repository
|
||||
true
|
||||
```
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
Let's clone a regular repository via plain Git:
|
||||
```
|
||||
$ git clone --bare $URL heartwood
|
||||
$ cd heartwood
|
||||
$ git rev-parse HEAD
|
||||
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354
|
||||
```
|
||||
|
||||
We can see it's not a Radicle working copy:
|
||||
``` (fail)
|
||||
$ rad .
|
||||
✗ Error: Current directory is not a Radicle repository
|
||||
```
|
||||
|
||||
Let's pick an existing repository:
|
||||
```
|
||||
$ rad inspect rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||
```
|
||||
|
||||
And initialize this working copy as that existing repository:
|
||||
```
|
||||
$ rad init --existing rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||
✓ Initialized existing repository rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji in [..]/heartwood/..
|
||||
```
|
||||
|
||||
We can confirm that the working copy is initialized:
|
||||
```
|
||||
$ rad .
|
||||
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||
$ git remote show rad
|
||||
* remote rad
|
||||
Fetch URL: rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji
|
||||
Push URL: rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
HEAD branch: (unknown)
|
||||
Remote branch:
|
||||
master new (next fetch will store in remotes/rad)
|
||||
Local ref configured for 'git push':
|
||||
master pushes to master (up to date)
|
||||
```
|
||||
|
|
@ -176,6 +176,15 @@ fn rad_init() {
|
|||
Environment::alice(["rad-init"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rad_init_bare() {
|
||||
let mut env = Environment::new();
|
||||
let alice = env.profile("alice");
|
||||
radicle::test::fixtures::bare_repository(env.work(&alice).as_path());
|
||||
env.tests(["git/git-is-bare-repository", "rad-init"], &alice)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rad_init_existing() {
|
||||
let mut environment = Environment::new();
|
||||
|
|
@ -198,6 +207,28 @@ fn rad_init_existing() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rad_init_existing_bare() {
|
||||
let mut environment = Environment::new();
|
||||
let mut profile = environment.node("alice");
|
||||
let working = tempfile::tempdir().unwrap();
|
||||
let rid = profile.project("heartwood", "Radicle Heartwood Protocol & Stack");
|
||||
|
||||
test(
|
||||
"examples/rad-init-existing-bare.md",
|
||||
working.path(),
|
||||
Some(&profile.home),
|
||||
[(
|
||||
"URL",
|
||||
git::url::File::new(profile.storage.path())
|
||||
.rid(rid)
|
||||
.to_string()
|
||||
.as_str(),
|
||||
)],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rad_init_no_seed() {
|
||||
Environment::alice(["rad-init-no-seed"]);
|
||||
|
|
|
|||
|
|
@ -95,11 +95,28 @@ where
|
|||
|
||||
/// Creates a regular repository at the given path with a couple of commits.
|
||||
pub fn repository<P: AsRef<Path>>(path: P) -> (git2::Repository, git2::Oid) {
|
||||
let repo = git2::Repository::init_opts(
|
||||
let (repo, oid) = repository_with(
|
||||
path,
|
||||
git2::RepositoryInitOptions::new().external_template(false),
|
||||
);
|
||||
repo.checkout_head(None).unwrap();
|
||||
(repo, oid)
|
||||
}
|
||||
|
||||
pub fn bare_repository<P: AsRef<Path>>(path: P) -> (git2::Repository, git2::Oid) {
|
||||
repository_with(
|
||||
path,
|
||||
git2::RepositoryInitOptions::new()
|
||||
.external_template(false)
|
||||
.bare(true),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn repository_with<P: AsRef<Path>>(
|
||||
path: P,
|
||||
opts: &mut git2::RepositoryInitOptions,
|
||||
) -> (git2::Repository, git2::Oid) {
|
||||
let repo = git2::Repository::init_opts(path, opts).unwrap();
|
||||
|
||||
{
|
||||
let mut config = repo.config().unwrap();
|
||||
|
|
@ -124,7 +141,6 @@ pub fn repository<P: AsRef<Path>>(path: P) -> (git2::Repository, git2::Oid) {
|
|||
commit.id()
|
||||
};
|
||||
repo.set_head("refs/heads/master").unwrap();
|
||||
repo.checkout_head(None).unwrap();
|
||||
|
||||
drop(tree);
|
||||
drop(head);
|
||||
|
|
|
|||
Loading…
Reference in New Issue