(root: &Path)
| 109 | } |
| 110 | |
| 111 | fn exclude_path(root: &Path) -> Result<std::path::PathBuf, IgnoreMirrorError> { |
| 112 | let repository = git2::Repository::discover(root) |
| 113 | .map_err(|error| IgnoreMirrorError::GitDirectory(format!("{}: {error}", root.display())))?; |
| 114 | // `.git/info/exclude` lives in the common administrative directory so |
| 115 | // linked worktrees share one managed block. git2 0.19 does not expose |
| 116 | // `commondir()`, so resolve the `commondir` pointer file explicitly. |
| 117 | let git_dir = repository.path(); |
| 118 | let common_dir = match fs::read_to_string(git_dir.join("commondir")) { |
| 119 | Ok(pointer) => { |
| 120 | let pointer = pointer.trim_end_matches(['\n', '\r']); |
| 121 | let absolute = if Path::new(pointer).is_absolute() { |
| 122 | std::path::PathBuf::from(pointer) |
| 123 | } else { |
| 124 | git_dir.join(pointer) |
| 125 | }; |
| 126 | fs::canonicalize(&absolute).unwrap_or(absolute) |
| 127 | } |
| 128 | Err(_) => git_dir.to_path_buf(), |
| 129 | }; |
| 130 | Ok(common_dir.join("info").join("exclude")) |
| 131 | } |
| 132 | |
| 133 | fn read_exclude_patterns(path: &Path) -> Result<Vec<String>, IgnoreMirrorError> { |
| 134 | match fs::read(path) { |
no test coverage detected