Commit

Author:

Hash:

Timestamp:

+43 -8 +/-2 browse

Kevin Schoon [me@kevinschoon.com]

7e33e15b54e18b364b1d81cc68c24b4d6242d791

Mon, 04 Aug 2025 09:26:43 +0000 (3 months ago)

add git-upload-pack support
1diff --git a/ayllu-shell/src/main.rs b/ayllu-shell/src/main.rs
2index 993a8c9..7812a44 100644
3--- a/ayllu-shell/src/main.rs
4+++ b/ayllu-shell/src/main.rs
5 @@ -1,4 +1,4 @@
6- use std::path::{Path, PathBuf};
7+ use std::path::PathBuf;
8
9 use ayllu_git::Wrapper;
10 use clap::{Parser, Subcommand};
11 @@ -9,11 +9,16 @@ mod ui;
12
13 #[derive(Subcommand, Debug)]
14 enum Commands {
15- /// Invokes git-receive-pack with some particularities
16+ /// Invokes git-receive-pack
17 GitReceivePack {
18 /// Path to the git repository
19 path: PathBuf,
20 },
21+ /// Invokes git-upload-pack
22+ GitUploadPack {
23+ /// Path to the git repository
24+ path: PathBuf,
25+ },
26 }
27
28 #[derive(Parser, Debug)]
29 @@ -54,7 +59,6 @@ fn execute(args: Arguments) -> Result<(), Box<dyn std::error::Error>> {
30 .find(|identity| identity.username == username);
31 match args.command {
32 Some(Commands::GitReceivePack { ref path }) => {
33- eprintln!("The path is: {path:?}");
34 let resolved = if path.is_relative() {
35 if let Some(base_dir) = config.base_dir {
36 &base_dir.join(path)
37 @@ -64,8 +68,6 @@ fn execute(args: Arguments) -> Result<(), Box<dyn std::error::Error>> {
38 } else {
39 path
40 };
41- eprintln!("Resolved: {resolved:?}");
42- eprintln!("Collections: {:?}", config.collections);
43 match config
44 .collections
45 .iter()
46 @@ -74,16 +76,37 @@ fn execute(args: Arguments) -> Result<(), Box<dyn std::error::Error>> {
47 Some(_) => {
48 let repository =
49 if ayllu_git::git_dir(resolved).is_ok_and(|is_git_dir| is_git_dir) {
50- eprintln!("opening existing repository");
51 Wrapper::new(resolved)?
52 } else {
53- eprintln!("creating new repository");
54 Wrapper::create(resolved, true)?
55 };
56 repository.receive_pack()?;
57 }
58 None => {
59- eprintln!("never resolved the collection");
60+ return Err(format!("Cannot find repository: {resolved:?}").into());
61+ }
62+ }
63+ }
64+ Some(Commands::GitUploadPack { ref path }) => {
65+ let resolved = if path.is_relative() {
66+ if let Some(base_dir) = config.base_dir {
67+ &base_dir.join(path)
68+ } else {
69+ path
70+ }
71+ } else {
72+ path
73+ };
74+ match config
75+ .collections
76+ .iter()
77+ .find(|collection| collection.path == resolved.parent().unwrap())
78+ {
79+ Some(_) => {
80+ let repository = Wrapper::new(resolved)?;
81+ repository.upload_pack()?;
82+ }
83+ None => {
84 return Err(format!("Cannot find repository: {resolved:?}").into());
85 }
86 }
87 diff --git a/crates/git/src/wrapper.rs b/crates/git/src/wrapper.rs
88index f432463..ec7ffa4 100644
89--- a/crates/git/src/wrapper.rs
90+++ b/crates/git/src/wrapper.rs
91 @@ -998,6 +998,18 @@ impl Wrapper {
92 Ok(())
93 }
94
95+ /// Handle git-upload-pack on the repository
96+ pub fn upload_pack(&self) -> Result<(), Error> {
97+ let repository_path = Path::new(&self.path);
98+ let mut command = std::process::Command::new("git");
99+ command.args(["upload-pack", &repository_path.to_str().unwrap()]);
100+ command.stdin(Stdio::inherit());
101+ command.stdout(Stdio::inherit());
102+ let mut child = command.spawn()?;
103+ child.wait()?;
104+ Ok(())
105+ }
106+
107 /// verify the signature of the given commit
108 /// TODO: Can this be done with libgit2?
109 pub fn verify(&self, id: &str) -> Result<Option<bool>, Error> {