(folder: string, childName: string, expect: "FILE" | "DIRECTORY" | "ANY")
| 757 | } |
| 758 | |
| 759 | function findRootContaining(folder: string, childName: string, expect: "FILE" | "DIRECTORY" | "ANY"): string | undefined { |
| 760 | if (folder) { |
| 761 | // Walk up the directories from the workspace root, and see if there |
| 762 | // exists a directory which has `childName` file/directory as a child. |
| 763 | let child = folder; |
| 764 | while (child) { |
| 765 | try { |
| 766 | const fullPath = path.join(child, childName); |
| 767 | if (expect === "ANY" || (expect === "FILE" ? existsAndIsFileSync(fullPath) : existsAndIsDirectorySync(fullPath))) |
| 768 | return child; |
| 769 | } catch { } |
| 770 | |
| 771 | const parentDir = path.dirname(child); |
| 772 | if (child === parentDir) |
| 773 | break; |
| 774 | |
| 775 | child = parentDir; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | return undefined; |
| 780 | } |
| 781 | |
| 782 | enum GitOperationResult { success, error, cancelled }; |
no test coverage detected