Fix repos being created with target machine as remote name master public/master
authorJacob Casper <dev@jacobcasper.com>
Sat, 12 Jun 2021 22:51:38 +0000 (17:51 -0500)
committerJacob Casper <dev@jacobcasper.com>
Sat, 12 Jun 2021 22:51:38 +0000 (17:51 -0500)
"public" is hard coded and not configurable in the default mirroring
script, so we should hard code it as well instead of using the name of
the public machine.

src/main.rs

index bc758e4..6a59113 100644 (file)
@@ -18,36 +18,32 @@ fn check_ip() -> Result<(), Box<dyn error::Error>> {
 }
 
 fn main() -> Result<(), Box<dyn error::Error>> {
-    match check_ip() {
-        Ok(()) => {
-            let mut repo_name = String::new();
-            io::stdin().read_line(&mut repo_name)?;
-            // remove trailing newline
-            repo_name.pop();
+    check_ip()?;
+    let mut repo_name = String::new();
+    io::stdin().read_line(&mut repo_name)?;
+    // remove trailing newline
+    repo_name.pop();
 
-            let mut opts = git2::RepositoryInitOptions::new();
-            git2::RepositoryInitOptions::bare(&mut opts, true)
-                .mode(git2::RepositoryInitMode::SHARED_GROUP)
-                .no_reinit(true)
-                .template_path(path::Path::new("./templates"));
+    let mut opts = git2::RepositoryInitOptions::new();
+    git2::RepositoryInitOptions::bare(&mut opts, true)
+        .mode(git2::RepositoryInitMode::SHARED_GROUP)
+        .no_reinit(true)
+        .template_path(path::Path::new("./templates"));
 
-            let repo = git2::Repository::init_opts(format!("{}.git", repo_name), &opts)?;
+    let repo = git2::Repository::init_opts(format!("{}.git", repo_name), &opts)?;
 
-            let public_user = env::var("USER")?;
-            let public_name = env::var("PUBLIC")?;
-            let public_path = env::var("PATH")?;
-            repo.remote(
-                &public_name,
-                &format!(
-                    "{user}@{public}:{path}/{repo}.git",
-                    user = public_user,
-                    public = public_name,
-                    path = public_path,
-                    repo = repo_name
-                ),
-            )?;
-            Ok(())
-        }
-        Err(e) => Err(e),
-    }
+    let public_user = env::var("USER")?;
+    let public_name = env::var("PUBLIC")?;
+    let public_path = env::var("PATH")?;
+    repo.remote(
+        "public",
+        &format!(
+            "{user}@{public}:{path}/{repo}.git",
+            user = public_user,
+            public = public_name,
+            path = public_path,
+            repo = repo_name
+        ),
+    )?;
+    Ok(())
 }