Get file content from a git tree.
(git_repo: &GitRepository, tree: &Tree, path: &str)
| 4147 | |
| 4148 | /// Get file content from a git tree. |
| 4149 | fn get_file_content(git_repo: &GitRepository, tree: &Tree, path: &str) -> CliResult<Vec<u8>> { |
| 4150 | let entry = tree |
| 4151 | .get_path(Path::new(path)) |
| 4152 | .map_err(|e| CliError::GitError { |
| 4153 | message: format!("Path not found in tree: {}", e), |
| 4154 | })?; |
| 4155 | |
| 4156 | if entry.kind() != Some(ObjectType::Blob) { |
| 4157 | return Err(CliError::GitError { |
| 4158 | message: "Not a file".to_string(), |
| 4159 | }); |
| 4160 | } |
| 4161 | |
| 4162 | let blob = git_repo |
| 4163 | .find_blob(entry.id()) |
| 4164 | .map_err(|e| CliError::GitError { |
| 4165 | message: format!("Failed to find blob: {}", e), |
| 4166 | })?; |
| 4167 | |
| 4168 | Ok(blob.content().to_vec()) |
| 4169 | } |
| 4170 | |
| 4171 | /// Parse a git commit message into subject and description. |
| 4172 | fn parse_commit_message(message: &str) -> (String, Option<String>) { |
no test coverage detected