diff options
Diffstat (limited to 'src/git')
| -rw-r--r-- | src/git/handlers.rs | 10 | ||||
| -rw-r--r-- | src/git/subprocess.rs | 12 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/git/handlers.rs b/src/git/handlers.rs index ff55e34..017eee4 100644 --- a/src/git/handlers.rs +++ b/src/git/handlers.rs | |||
| @@ -26,6 +26,7 @@ use crate::purgatory::Purgatory; | |||
| 26 | pub async fn handle_info_refs( | 26 | pub async fn handle_info_refs( |
| 27 | repo_path: PathBuf, | 27 | repo_path: PathBuf, |
| 28 | service: GitService, | 28 | service: GitService, |
| 29 | git_protocol: Option<&str>, | ||
| 29 | ) -> Result<Response<Full<Bytes>>, GitError> { | 30 | ) -> Result<Response<Full<Bytes>>, GitError> { |
| 30 | debug!( | 31 | debug!( |
| 31 | "Handling info/refs for {:?} with service {:?}", | 32 | "Handling info/refs for {:?} with service {:?}", |
| @@ -39,7 +40,7 @@ pub async fn handle_info_refs( | |||
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | // Spawn git with --advertise-refs | 42 | // Spawn git with --advertise-refs |
| 42 | let mut git = GitSubprocess::spawn(service, &repo_path, true).map_err(|e| { | 43 | let mut git = GitSubprocess::spawn(service, &repo_path, true, git_protocol).map_err(|e| { |
| 43 | error!("Failed to spawn git process: {}", e); | 44 | error!("Failed to spawn git process: {}", e); |
| 44 | GitError::ProcessSpawnFailed(e) | 45 | GitError::ProcessSpawnFailed(e) |
| 45 | })?; | 46 | })?; |
| @@ -102,6 +103,7 @@ pub async fn handle_info_refs( | |||
| 102 | pub async fn handle_upload_pack( | 103 | pub async fn handle_upload_pack( |
| 103 | repo_path: PathBuf, | 104 | repo_path: PathBuf, |
| 104 | request_body: Bytes, | 105 | request_body: Bytes, |
| 106 | git_protocol: Option<&str>, | ||
| 105 | ) -> Result<Response<Full<Bytes>>, GitError> { | 107 | ) -> Result<Response<Full<Bytes>>, GitError> { |
| 106 | debug!("Handling upload-pack for {:?}", repo_path); | 108 | debug!("Handling upload-pack for {:?}", repo_path); |
| 107 | 109 | ||
| @@ -110,7 +112,7 @@ pub async fn handle_upload_pack( | |||
| 110 | } | 112 | } |
| 111 | 113 | ||
| 112 | // Spawn git upload-pack | 114 | // Spawn git upload-pack |
| 113 | let mut git = GitSubprocess::spawn(GitService::UploadPack, &repo_path, false) | 115 | let mut git = GitSubprocess::spawn(GitService::UploadPack, &repo_path, false, git_protocol) |
| 114 | .map_err(GitError::ProcessSpawnFailed)?; | 116 | .map_err(GitError::ProcessSpawnFailed)?; |
| 115 | 117 | ||
| 116 | // Write request to git's stdin | 118 | // Write request to git's stdin |
| @@ -181,6 +183,7 @@ pub async fn handle_upload_pack( | |||
| 181 | /// * `identifier` - The repository identifier (d tag) for authorization lookup | 183 | /// * `identifier` - The repository identifier (d tag) for authorization lookup |
| 182 | /// * `owner_pubkey` - The owner's public key (hex) from the URL path, scoping authorization | 184 | /// * `owner_pubkey` - The owner's public key (hex) from the URL path, scoping authorization |
| 183 | /// * `git_data_path` - Base path for git repositories (for syncing to other owner repos) | 185 | /// * `git_data_path` - Base path for git repositories (for syncing to other owner repos) |
| 186 | /// * `git_protocol` - Optional Git protocol version (e.g., "version=2") | ||
| 184 | #[allow(clippy::too_many_arguments)] | 187 | #[allow(clippy::too_many_arguments)] |
| 185 | pub async fn handle_receive_pack( | 188 | pub async fn handle_receive_pack( |
| 186 | repo_path: PathBuf, | 189 | repo_path: PathBuf, |
| @@ -191,6 +194,7 @@ pub async fn handle_receive_pack( | |||
| 191 | owner_pubkey: &str, | 194 | owner_pubkey: &str, |
| 192 | purgatory: Arc<Purgatory>, | 195 | purgatory: Arc<Purgatory>, |
| 193 | git_data_path: &str, | 196 | git_data_path: &str, |
| 197 | git_protocol: Option<&str>, | ||
| 194 | ) -> Result<Response<Full<Bytes>>, GitError> { | 198 | ) -> Result<Response<Full<Bytes>>, GitError> { |
| 195 | debug!("Handling receive-pack for {:?}", repo_path); | 199 | debug!("Handling receive-pack for {:?}", repo_path); |
| 196 | 200 | ||
| @@ -236,7 +240,7 @@ pub async fn handle_receive_pack( | |||
| 236 | }; | 240 | }; |
| 237 | 241 | ||
| 238 | // Spawn git receive-pack | 242 | // Spawn git receive-pack |
| 239 | let mut git = GitSubprocess::spawn(GitService::ReceivePack, &repo_path, false) | 243 | let mut git = GitSubprocess::spawn(GitService::ReceivePack, &repo_path, false, git_protocol) |
| 240 | .map_err(GitError::ProcessSpawnFailed)?; | 244 | .map_err(GitError::ProcessSpawnFailed)?; |
| 241 | 245 | ||
| 242 | // Write request to git's stdin | 246 | // Write request to git's stdin |
diff --git a/src/git/subprocess.rs b/src/git/subprocess.rs index 2d9a981..acee726 100644 --- a/src/git/subprocess.rs +++ b/src/git/subprocess.rs | |||
| @@ -22,10 +22,12 @@ impl GitSubprocess { | |||
| 22 | /// * `service` - The Git service (upload-pack or receive-pack) | 22 | /// * `service` - The Git service (upload-pack or receive-pack) |
| 23 | /// * `repo_path` - Path to the bare Git repository | 23 | /// * `repo_path` - Path to the bare Git repository |
| 24 | /// * `advertise` - If true, run with --advertise-refs flag | 24 | /// * `advertise` - If true, run with --advertise-refs flag |
| 25 | /// * `git_protocol` - Optional Git protocol version (e.g., "version=2") | ||
| 25 | pub fn spawn( | 26 | pub fn spawn( |
| 26 | service: GitService, | 27 | service: GitService, |
| 27 | repo_path: impl AsRef<Path>, | 28 | repo_path: impl AsRef<Path>, |
| 28 | advertise: bool, | 29 | advertise: bool, |
| 30 | git_protocol: Option<&str>, | ||
| 29 | ) -> std::io::Result<Self> { | 31 | ) -> std::io::Result<Self> { |
| 30 | let repo_path = repo_path.as_ref(); | 32 | let repo_path = repo_path.as_ref(); |
| 31 | 33 | ||
| @@ -52,6 +54,12 @@ impl GitSubprocess { | |||
| 52 | cmd.stdout(Stdio::piped()); | 54 | cmd.stdout(Stdio::piped()); |
| 53 | cmd.stderr(Stdio::piped()); | 55 | cmd.stderr(Stdio::piped()); |
| 54 | 56 | ||
| 57 | // Set GIT_PROTOCOL environment variable if provided | ||
| 58 | // This enables Git protocol v2 support for modern git clients | ||
| 59 | if let Some(protocol) = git_protocol { | ||
| 60 | cmd.env("GIT_PROTOCOL", protocol); | ||
| 61 | } | ||
| 62 | |||
| 55 | let child = cmd.spawn()?; | 63 | let child = cmd.spawn()?; |
| 56 | 64 | ||
| 57 | Ok(Self { child }) | 65 | Ok(Self { child }) |
| @@ -118,7 +126,7 @@ mod tests { | |||
| 118 | #[tokio::test] | 126 | #[tokio::test] |
| 119 | async fn test_spawn_upload_pack_advertise() { | 127 | async fn test_spawn_upload_pack_advertise() { |
| 120 | let repo = create_bare_repo(); | 128 | let repo = create_bare_repo(); |
| 121 | let mut proc = GitSubprocess::spawn(GitService::UploadPack, repo.path(), true) | 129 | let mut proc = GitSubprocess::spawn(GitService::UploadPack, repo.path(), true, None) |
| 122 | .expect("Failed to spawn git"); | 130 | .expect("Failed to spawn git"); |
| 123 | 131 | ||
| 124 | // Should have spawned successfully | 132 | // Should have spawned successfully |
| @@ -132,7 +140,7 @@ mod tests { | |||
| 132 | #[tokio::test] | 140 | #[tokio::test] |
| 133 | async fn test_spawn_receive_pack() { | 141 | async fn test_spawn_receive_pack() { |
| 134 | let repo = create_bare_repo(); | 142 | let repo = create_bare_repo(); |
| 135 | let mut proc = GitSubprocess::spawn(GitService::ReceivePack, repo.path(), false) | 143 | let mut proc = GitSubprocess::spawn(GitService::ReceivePack, repo.path(), false, None) |
| 136 | .expect("Failed to spawn git"); | 144 | .expect("Failed to spawn git"); |
| 137 | 145 | ||
| 138 | assert!(proc.stdout().is_some()); | 146 | assert!(proc.stdout().is_some()); |