summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--readme.org15
-rw-r--r--src/main.rs12
-rw-r--r--src/parser.rs8
-rw-r--r--tests/server_shell.rs51
4 files changed, 72 insertions, 14 deletions
diff --git a/readme.org b/readme.org
index fbfe7db..6d68020 100644
--- a/readme.org
+++ b/readme.org
@@ -19,16 +19,17 @@ Pijul.
- [X] git init of private repo
- [X] responds to unknown commands
- [X] Isolation of workdir between tests
-- [X] git fetch with git upload-pack <argument>
-- [ ] extra args for git upload-pack
-- [ ] git push with git receive-pack <argument>
-- [ ] git archive with git upload-archive <argument>
+- [X] git fetch with git upload-pack
+- [X] git push with git receive-pack
+- [ ] proper shell argument lexing, with quote stuff https://lib.rs/crates/shlex
+- [ ] restrict repos to only acceptable paths
- [ ] git init of shared repos
+- [ ] history (only within same session) https://lib.rs/crates/rustyline
- [ ] don't quit interactive shell sessions if there's an error
-- [ ] help command
-- [ ] restrict repos to only acceptable paths
+- [ ] git archive with git upload-archive
+- [X] help command
+- [ ] help docs on all the commands
- [ ] listing of repos
-- [ ] history (only within same session)
- [ ] set repo descriptions
- [ ] set the main branch of a repo
- [ ] move a repo to a different group
diff --git a/src/main.rs b/src/main.rs
index 6f8c1d9..50f5127 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -78,6 +78,18 @@ fn run_command(user_input: String) -> Result<ControlFlow<(), ()>, ShackleError>
command.spawn()?.wait()?;
}
+ Ok(ShackleCommand::GitReceivePack(receive_pack_args)) => {
+ let mut command = Command::new("git-receive-pack");
+
+ if receive_pack_args.http_backend_info_refs {
+ command.arg("--http-backend-info-refs");
+ }
+
+ // TODO: This should definitely be part of the arg parsing!
+ command.arg(&receive_pack_args.directory.trim_matches('\''));
+
+ command.spawn()?.wait()?;
+ }
}
Ok(ControlFlow::Continue(()))
}
diff --git a/src/parser.rs b/src/parser.rs
index ef7d5f8..59dc7d8 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -9,6 +9,7 @@ pub enum ShackleCommand {
Exit,
GitInit(GitInitArgs),
GitUploadPack(GitUploadPackArgs),
+ GitReceivePack(GitReceivePackArgs),
}
#[derive(Subcommand, Clone, Debug, PartialEq, Eq)]
@@ -36,6 +37,13 @@ pub struct GitUploadPackArgs {
pub directory: String,
}
+#[derive(Parser, Clone, Debug, PartialEq, Eq)]
+pub struct GitReceivePackArgs {
+ #[arg(long)]
+ pub http_backend_info_refs: bool,
+ pub directory: String,
+}
+
impl FromStr for ShackleCommand {
type Err = clap::error::Error;
diff --git a/tests/server_shell.rs b/tests/server_shell.rs
index 5028ac9..ff3e1a4 100644
--- a/tests/server_shell.rs
+++ b/tests/server_shell.rs
@@ -3,7 +3,7 @@ use assert_cmd::{cargo::cargo_bin, Command};
use get_port::{tcp::TcpPort, Ops, Range};
use once_cell::sync::Lazy;
use rexpect::session::{spawn_command, PtySession};
-use std::{io, path, sync::Mutex};
+use std::{fs, io, path, sync::Mutex};
use tempfile::TempDir;
use thiserror::Error;
@@ -149,12 +149,7 @@ fn shows_a_prompt() -> Result<()> {
Ok(())
}
-#[test]
-fn git_clone_works_with_an_empty_repo() -> Result<()> {
- let c = spawn_ssh_server()?;
- let repo_name = "my-new-repo";
- make_new_repo(&c, repo_name)?;
-
+fn clone_git_repo(c: &TestContext, repo_name: &str) {
Command::new("git")
.args([
"clone",
@@ -167,6 +162,48 @@ fn git_clone_works_with_an_empty_repo() -> Result<()> {
.timeout(std::time::Duration::from_secs(3))
.assert()
.success();
+}
+
+#[test]
+fn git_clone_works_with_an_empty_repo() -> Result<()> {
+ let c = spawn_ssh_server()?;
+ let repo_name = "my-new-clonable-repo";
+ make_new_repo(&c, repo_name)?;
+ clone_git_repo(&c, repo_name);
+
+ Ok(())
+}
+
+#[test]
+fn git_push_works() -> Result<()> {
+ let c = spawn_ssh_server()?;
+ let repo_name = "my-new-pushable-repo";
+ make_new_repo(&c, repo_name)?;
+ clone_git_repo(&c, repo_name);
+
+ let repo_dir = c.workdir.as_ref().join(repo_name);
+
+ let file_name = "yay-a-file";
+ let file_path = repo_dir.join(file_name);
+ fs::write(&file_path, "doesn't matter what this is")?;
+
+ Command::new("git")
+ .args(["add", "-A"])
+ .current_dir(&repo_dir)
+ .assert()
+ .success();
+ Command::new("git")
+ .args(["commit", "-m", "commitment"])
+ .current_dir(&repo_dir)
+ .assert()
+ .success();
+
+ Command::new("git")
+ .args(["push", "origin"])
+ .current_dir(&repo_dir)
+ .timeout(std::time::Duration::from_secs(3))
+ .assert()
+ .success();
Ok(())
}