(
git: &GitRepository,
tree: &git2::Tree<'_>,
prefix: &str,
files: &mut BTreeMap<String, Vec<u8>>,
)
| 3211 | } |
| 3212 | |
| 3213 | fn collect_git_tree( |
| 3214 | git: &GitRepository, |
| 3215 | tree: &git2::Tree<'_>, |
| 3216 | prefix: &str, |
| 3217 | files: &mut BTreeMap<String, Vec<u8>>, |
| 3218 | ) -> CliResult<()> { |
| 3219 | for entry in tree.iter() { |
| 3220 | let name = entry |
| 3221 | .name() |
| 3222 | .map_err(|error| git_error(format!("Git tree contains a non-UTF-8 path: {error}")))?; |
| 3223 | let path = if prefix.is_empty() { |
| 3224 | name.to_string() |
| 3225 | } else { |
| 3226 | format!("{prefix}/{name}") |
| 3227 | }; |
| 3228 | if excluded_path(&path) { |
| 3229 | continue; |
| 3230 | } |
| 3231 | |
| 3232 | match (entry.kind(), entry.filemode()) { |
| 3233 | (Some(ObjectType::Tree), 0o040000) => { |
| 3234 | let child = git.find_tree(entry.id()).map_err(|error| { |
| 3235 | git_error(format!("cannot read Git tree '{path}': {error}")) |
| 3236 | })?; |
| 3237 | collect_git_tree(git, &child, &path, files)?; |
| 3238 | } |
| 3239 | (Some(ObjectType::Blob), 0o100644 | 0o100755) => { |
| 3240 | let blob = git.find_blob(entry.id()).map_err(|error| { |
| 3241 | git_error(format!("cannot read Git blob '{path}': {error}")) |
| 3242 | })?; |
| 3243 | files.insert(path, blob.content().to_vec()); |
| 3244 | } |
| 3245 | // A symlink is a path like any other for collision planning; its |
| 3246 | // blob holds the link target. The `.claude/skills/<name>` layout |
| 3247 | // made every switch refuse with "unsupported Git entry". |
| 3248 | (Some(ObjectType::Blob), 0o120000) => { |
| 3249 | let blob = git.find_blob(entry.id()).map_err(|error| { |
| 3250 | git_error(format!("cannot read Git symlink '{path}': {error}")) |
| 3251 | })?; |
| 3252 | files.insert(path, blob.content().to_vec()); |
| 3253 | } |
| 3254 | // A gitlink occupies its path without content of its own. |
| 3255 | (Some(ObjectType::Commit), 0o160000) => { |
| 3256 | files.insert(path, Vec::new()); |
| 3257 | } |
| 3258 | _ => { |
| 3259 | return Err(git_error(format!( |
| 3260 | "unsupported Git entry '{path}' with mode {:o}", |
| 3261 | entry.filemode() |
| 3262 | ))); |
| 3263 | } |
| 3264 | } |
| 3265 | } |
| 3266 | Ok(()) |
| 3267 | } |
| 3268 | |
| 3269 | fn excluded_path(path: &str) -> bool { |
| 3270 | path == ".git" |
no test coverage detected