Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle-cli: Test initializing from bare repos
Lorenz Leutgeb committed 7 months ago
commit 62a0b7a668c74d8847ad657a497ef22a6ec68ef3
parent 1b0fe19608e100024e6dc95c238bb64e7b683523
4 files changed +94 -3
added crates/radicle-cli/examples/git/git-is-bare-repository.md
@@ -0,0 +1,4 @@
+
```
+
$ git rev-parse --is-bare-repository
+
true
+
```

\ No newline at end of file
added crates/radicle-cli/examples/rad-init-existing-bare.md
@@ -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)
+
```
modified crates/radicle-cli/tests/commands.rs
@@ -177,6 +177,15 @@ fn 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();
    let mut profile = environment.node("alice");
@@ -199,6 +208,28 @@ fn rad_init_existing() {
}

#[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"]);
}
modified crates/radicle/src/test/fixtures.rs
@@ -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);