summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--readme.org2
-rw-r--r--tests/cli.rs71
2 files changed, 45 insertions, 28 deletions
diff --git a/readme.org b/readme.org
index 4a06cd0..de840d5 100644
--- a/readme.org
+++ b/readme.org
@@ -32,7 +32,7 @@ Pijul.
- [X] push
- [-] git init of shared repos
- [X] create the shared repo in the right place
- - [ ] use the right file permissions and config
+ - [X] use the right file permissions and config
- [ ] don't allow this to be a group the user isn't in
- [ ] listing of repos
- [ ] set repo descriptions
diff --git a/tests/cli.rs b/tests/cli.rs
index 85f9708..a4b36a9 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -1,6 +1,7 @@
use anyhow::Result;
use assert_cmd::{cargo::cargo_bin, Command};
use rexpect::session::{spawn_command, PtySession};
+use std::path::Path;
use tempfile::TempDir;
use user_info::{get_user_groups, get_username};
@@ -87,6 +88,31 @@ fn reports_error_with_nonsense_input() -> Result<()> {
Ok(())
}
+fn verify_repo_exists(repo_dir: &Path) {
+ Command::new("git")
+ .arg("rev-list")
+ .arg("--all")
+ .current_dir(repo_dir)
+ .assert()
+ .success()
+ .stdout("");
+}
+
+fn verify_repo_config_value(repo_dir: &Path, config_key: &str, config_value: Option<&str>) {
+ let assert = Command::new("git")
+ .args(["config", "--local", config_key])
+ .current_dir(repo_dir)
+ .assert();
+ match config_value {
+ Some(value) => {
+ assert.success().stdout(format!("{}\n", value));
+ }
+ None => {
+ assert.failure().code(1);
+ }
+ }
+}
+
#[test]
fn can_init_a_new_git_repo() -> Result<()> {
let mut c = spawn_interactive_process()?;
@@ -99,19 +125,15 @@ fn can_init_a_new_git_repo() -> Result<()> {
))?;
expect_prompt(&mut c.p)?;
- Command::new("git")
- .arg("rev-list")
- .arg("--all")
- .current_dir(
- c.workdir
- .as_ref()
- .join("git")
- .join(username)
- .join(&format!("{}.git", repo_name)),
- )
- .assert()
- .success()
- .stdout("");
+ let repo_dir = c
+ .workdir
+ .as_ref()
+ .join("git")
+ .join(username)
+ .join(&format!("{}.git", repo_name));
+ verify_repo_exists(&repo_dir);
+ verify_repo_config_value(&repo_dir, "core.sharedrepository", None);
+
Ok(())
}
@@ -127,20 +149,15 @@ fn can_init_a_new_shared_git_repo() -> Result<()> {
))?;
expect_prompt(&mut c.p)?;
- Command::new("git")
- .arg("rev-list")
- .arg("--all")
- .current_dir(
- c.workdir
- .as_ref()
- .join("git")
- .join(&group)
- .join(&format!("{}.git", repo_name)),
- )
- .assert()
- .success()
- .stdout("");
- // TODO: Check file permissions? Shared set in git config?
+ let repo_dir = c
+ .workdir
+ .as_ref()
+ .join("git")
+ .join(&group)
+ .join(&format!("{}.git", repo_name));
+ verify_repo_exists(&repo_dir);
+ verify_repo_config_value(&repo_dir, "core.sharedrepository", Some("1"));
+
Ok(())
}