| 203 | |
| 204 | |
| 205 | def get_common_ancestor( |
| 206 | invocation_dir: Path, |
| 207 | paths: Iterable[Path], |
| 208 | ) -> Path: |
| 209 | common_ancestor: Path | None = None |
| 210 | for path in paths: |
| 211 | if not path.exists(): |
| 212 | continue |
| 213 | if common_ancestor is None: |
| 214 | common_ancestor = path |
| 215 | else: |
| 216 | if common_ancestor in path.parents or path == common_ancestor: |
| 217 | continue |
| 218 | elif path in common_ancestor.parents: |
| 219 | common_ancestor = path |
| 220 | else: |
| 221 | shared = commonpath(path, common_ancestor) |
| 222 | if shared is not None: |
| 223 | common_ancestor = shared |
| 224 | if common_ancestor is None: |
| 225 | common_ancestor = invocation_dir |
| 226 | elif common_ancestor.is_file(): |
| 227 | common_ancestor = common_ancestor.parent |
| 228 | return common_ancestor |
| 229 | |
| 230 | |
| 231 | def get_dirs_from_args(args: Iterable[str]) -> list[Path]: |