(&self, conn: &Connection, repo: &mut GitRepo)
| 15 | } |
| 16 | |
| 17 | fn populate(&self, conn: &Connection, repo: &mut GitRepo) -> Result<()> { |
| 18 | let mut stmt = conn.prepare( |
| 19 | r#" |
| 20 | INSERT INTO hooks ( |
| 21 | name, path, is_executable, is_sample, size, repo |
| 22 | ) VALUES (?1, ?2, ?3, ?4, ?5, ?6) |
| 23 | "#, |
| 24 | )?; |
| 25 | |
| 26 | let repo_path = repo.path().to_string(); |
| 27 | let git_repo = repo.inner(); |
| 28 | |
| 29 | let hooks_dir = git_repo.path().join("hooks"); |
| 30 | |
| 31 | if hooks_dir.exists() && hooks_dir.is_dir() { |
| 32 | if let Ok(entries) = fs::read_dir(&hooks_dir) { |
| 33 | for entry in entries.flatten() { |
| 34 | let file_path = entry.path(); |
| 35 | if file_path.is_file() { |
| 36 | let file_name = entry.file_name().to_string_lossy().to_string(); |
| 37 | |
| 38 | // Extract hook name (remove .sample suffix if present) |
| 39 | let is_sample = file_name.ends_with(".sample"); |
| 40 | let hook_name = if is_sample { |
| 41 | file_name.strip_suffix(".sample").unwrap_or(&file_name) |
| 42 | } else { |
| 43 | &file_name |
| 44 | }; |
| 45 | |
| 46 | // Check if it's a recognized hook name |
| 47 | if !is_valid_hook_name(hook_name) && !is_sample { |
| 48 | continue; |
| 49 | } |
| 50 | |
| 51 | let metadata = fs::metadata(&file_path)?; |
| 52 | #[cfg(unix)] |
| 53 | let is_executable = metadata.permissions().mode() & 0o111 != 0; |
| 54 | #[cfg(not(unix))] |
| 55 | let is_executable = !is_sample; // On Windows, assume non-sample hooks are executable |
| 56 | let size = metadata.len() as i64; |
| 57 | |
| 58 | stmt.execute(( |
| 59 | hook_name, |
| 60 | file_path.to_string_lossy().to_string(), |
| 61 | if is_executable { 1 } else { 0 }, |
| 62 | if is_sample { 1 } else { 0 }, |
| 63 | size, |
| 64 | &repo_path, |
| 65 | ))?; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | Ok(()) |
| 72 | } |
| 73 | } |
| 74 |
nothing calls this directly
no test coverage detected