Every repository path the materialization writes.
(&self, git_repo: &GitRepository)
| 1875 | |
| 1876 | /// Every repository path the materialization writes. |
| 1877 | fn paths(&self, git_repo: &GitRepository) -> CliResult<HashSet<String>> { |
| 1878 | let mut paths = HashSet::new(); |
| 1879 | match self { |
| 1880 | Self::Branch(branch) => { |
| 1881 | // A view imported ahead of its Git branch (a switch that |
| 1882 | // stopped before creating the branch) has no tree to collide |
| 1883 | // with; the tracked-changes requirement above still holds. |
| 1884 | let branch_ref = match git_repo.find_branch(branch, git2::BranchType::Local) { |
| 1885 | Ok(found) => found, |
| 1886 | Err(error) if error.code() == git2::ErrorCode::NotFound => return Ok(paths), |
| 1887 | Err(error) => { |
| 1888 | return Err(CliError::GitError { |
| 1889 | message: format!("cannot read branch '{branch}': {error}"), |
| 1890 | }) |
| 1891 | } |
| 1892 | }; |
| 1893 | let tree = branch_ref |
| 1894 | .get() |
| 1895 | .peel_to_tree() |
| 1896 | .map_err(|error| CliError::GitError { |
| 1897 | message: format!("cannot read the tree of branch '{branch}': {error}"), |
| 1898 | })?; |
| 1899 | tree.walk(git2::TreeWalkMode::PreOrder, |directory, entry| { |
| 1900 | if let Ok(name) = entry.name() { |
| 1901 | paths.insert(format!("{directory}{name}")); |
| 1902 | } |
| 1903 | git2::TreeWalkResult::Ok |
| 1904 | }) |
| 1905 | .map_err(|error| CliError::GitError { |
| 1906 | message: format!("cannot walk the tree of branch '{branch}': {error}"), |
| 1907 | })?; |
| 1908 | } |
| 1909 | Self::CurrentView(repo) => { |
| 1910 | for file in repo |
| 1911 | .list_tracked_files() |
| 1912 | .map_err(|error| CliError::Internal(error.into()))? |
| 1913 | { |
| 1914 | let canonical = file.path.to_string_lossy(); |
| 1915 | paths.insert( |
| 1916 | super::parallel::canonical_tree_path(&canonical) |
| 1917 | .to_string_lossy() |
| 1918 | .into_owned(), |
| 1919 | ); |
| 1920 | } |
| 1921 | } |
| 1922 | } |
| 1923 | Ok(paths) |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | /// Refuse to materialize over a worktree holding work Git has not recorded: |
no test coverage detected