diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-28 12:40:31 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-28 12:40:31 +0000 |
| commit | b94262161df99966fbb8aa6861fb46603039111f (patch) | |
| tree | f0194656783d05263be2d940f4e182b1bec75070 /grasp-audit/src/fixtures.rs | |
| parent | bf51a082ad54815f108bb255cf258fcae4a9bb4f (diff) | |
allow push to ref/nostr/<event-id>
Diffstat (limited to 'grasp-audit/src/fixtures.rs')
| -rw-r--r-- | grasp-audit/src/fixtures.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/grasp-audit/src/fixtures.rs b/grasp-audit/src/fixtures.rs index 8cee964..b6fbc79 100644 --- a/grasp-audit/src/fixtures.rs +++ b/grasp-audit/src/fixtures.rs | |||
| @@ -1208,6 +1208,44 @@ pub fn try_push(clone_path: &Path) -> Result<bool, String> { | |||
| 1208 | Ok(output.status.success()) | 1208 | Ok(output.status.success()) |
| 1209 | } | 1209 | } |
| 1210 | 1210 | ||
| 1211 | /// Attempt a git push to a specific ref and return success/failure | ||
| 1212 | /// | ||
| 1213 | /// This is used for testing refs/nostr/<event-id> push validation. | ||
| 1214 | /// | ||
| 1215 | /// # Arguments | ||
| 1216 | /// * `clone_path` - Path to the git repository | ||
| 1217 | /// * `ref_name` - The ref to push to (e.g., "refs/nostr/<event-id>") | ||
| 1218 | /// | ||
| 1219 | /// # Returns | ||
| 1220 | /// * `Ok(true)` - Push succeeded | ||
| 1221 | /// * `Ok(false)` - Push was rejected | ||
| 1222 | /// * `Err(String)` - Error executing git push | ||
| 1223 | /// | ||
| 1224 | /// # Example | ||
| 1225 | /// ```no_run | ||
| 1226 | /// # use grasp_audit::*; | ||
| 1227 | /// # use std::path::Path; | ||
| 1228 | /// # fn example() -> Result<(), String> { | ||
| 1229 | /// let success = try_push_to_ref(Path::new("/tmp/my-repo"), "refs/nostr/abc123")?; | ||
| 1230 | /// if success { | ||
| 1231 | /// println!("Push to refs/nostr/abc123 succeeded"); | ||
| 1232 | /// } else { | ||
| 1233 | /// println!("Push was rejected"); | ||
| 1234 | /// } | ||
| 1235 | /// # Ok(()) | ||
| 1236 | /// # } | ||
| 1237 | /// ``` | ||
| 1238 | pub fn try_push_to_ref(clone_path: &Path, ref_name: &str) -> Result<bool, String> { | ||
| 1239 | let output = Command::new("git") | ||
| 1240 | .args(["push", "origin", &format!("HEAD:{}", ref_name)]) | ||
| 1241 | .current_dir(clone_path) | ||
| 1242 | .env("GIT_TERMINAL_PROMPT", "0") | ||
| 1243 | .output() | ||
| 1244 | .map_err(|e| format!("Failed to execute git push: {}", e))?; | ||
| 1245 | |||
| 1246 | Ok(output.status.success()) | ||
| 1247 | } | ||
| 1248 | |||
| 1211 | #[cfg(test)] | 1249 | #[cfg(test)] |
| 1212 | mod tests { | 1250 | mod tests { |
| 1213 | use super::*; | 1251 | use super::*; |