| 179 |
179 |
|
|
| 180 |
180 |
|
/// Install the post-receive hook in a bare repository.
|
| 181 |
181 |
|
pub async fn install_post_receive_hook(
|
| 182 |
|
- |
git_user: &str,
|
|
182 |
+ |
_git_user: &str,
|
| 183 |
183 |
|
repo_path: &str,
|
| 184 |
184 |
|
token: &str,
|
| 185 |
185 |
|
) -> anyhow::Result<()> {
|
| 186 |
186 |
|
let hook_content = POST_RECEIVE_HOOK.replace("__TOKEN__", token);
|
| 187 |
|
- |
let hook_path = format!("{repo_path}/hooks/post-receive");
|
|
187 |
+ |
let hook_path = std::path::PathBuf::from(repo_path).join("hooks/post-receive");
|
| 188 |
188 |
|
|
| 189 |
|
- |
// Write hook content via sudo tee (runs as git user)
|
| 190 |
|
- |
let mut child = tokio::process::Command::new("sudo")
|
| 191 |
|
- |
.args(["-u", git_user, "tee", &hook_path])
|
| 192 |
|
- |
.stdin(std::process::Stdio::piped())
|
| 193 |
|
- |
.stdout(std::process::Stdio::null())
|
| 194 |
|
- |
.spawn()?;
|
|
189 |
+ |
// Write directly — mnw-cli is in the git group, setgid dir gives correct ownership
|
|
190 |
+ |
tokio::fs::write(&hook_path, hook_content.as_bytes()).await?;
|
| 195 |
191 |
|
|
| 196 |
|
- |
if let Some(mut stdin) = child.stdin.take() {
|
| 197 |
|
- |
use tokio::io::AsyncWriteExt;
|
| 198 |
|
- |
stdin.write_all(hook_content.as_bytes()).await?;
|
|
192 |
+ |
#[cfg(unix)]
|
|
193 |
+ |
{
|
|
194 |
+ |
use std::os::unix::fs::PermissionsExt;
|
|
195 |
+ |
tokio::fs::set_permissions(&hook_path, std::fs::Permissions::from_mode(0o755)).await?;
|
| 199 |
196 |
|
}
|
| 200 |
|
- |
child.wait().await?;
|
| 201 |
|
- |
|
| 202 |
|
- |
// Make executable
|
| 203 |
|
- |
let _ = tokio::process::Command::new("sudo")
|
| 204 |
|
- |
.args(["-u", git_user, "chmod", "+x", &hook_path])
|
| 205 |
|
- |
.status()
|
| 206 |
|
- |
.await;
|
| 207 |
197 |
|
|
| 208 |
|
- |
tracing::debug!(path = %hook_path, "installed post-receive hook");
|
|
198 |
+ |
tracing::debug!(path = %hook_path.display(), "installed post-receive hook");
|
| 209 |
199 |
|
Ok(())
|
| 210 |
200 |
|
}
|
| 211 |
201 |
|
|