Every repository path the materialization writes.
(&self, git_repo: &GitRepository)
| 1935 | |
| 1936 | /// Every repository path the materialization writes. |
| 1937 | fn paths(&self, git_repo: &GitRepository) -> CliResult<HashSet<String>> { |
| 1938 | let mut paths = HashSet::new(); |
| 1939 | match self { |
| 1940 | Self::Branch(branch) => { |
| 1941 | // A view imported ahead of its Git branch (a switch that |
| 1942 | // stopped before creating the branch) has no tree to collide |
| 1943 | // with; the tracked-changes requirement above still holds. |
| 1944 | let branch_ref = match git_repo.find_branch(branch, git2::BranchType::Local) { |
| 1945 | Ok(found) => found, |
| 1946 | Err(error) if error.code() == git2::ErrorCode::NotFound => return Ok(paths), |
| 1947 | Err(error) => { |
| 1948 | return Err(CliError::GitError { |
| 1949 | message: format!("cannot read branch '{branch}': {error}"), |
| 1950 | }) |
| 1951 | } |
| 1952 | }; |
| 1953 | let tree = branch_ref |
| 1954 | .get() |
| 1955 | .peel_to_tree() |
| 1956 | .map_err(|error| CliError::GitError { |
| 1957 | message: format!("cannot read the tree of branch '{branch}': {error}"), |
| 1958 | })?; |
| 1959 | tree.walk(git2::TreeWalkMode::PreOrder, |directory, entry| { |
| 1960 | if let Ok(name) = entry.name() { |
| 1961 | paths.insert(format!("{directory}{name}")); |
| 1962 | } |
| 1963 | git2::TreeWalkResult::Ok |
| 1964 | }) |
| 1965 | .map_err(|error| CliError::GitError { |
| 1966 | message: format!("cannot walk the tree of branch '{branch}': {error}"), |
| 1967 | })?; |
| 1968 | } |
| 1969 | Self::CurrentView(repo) => { |
| 1970 | for file in repo |
| 1971 | .list_tracked_files() |
| 1972 | .map_err(|error| CliError::Internal(error.into()))? |
| 1973 | { |
| 1974 | let canonical = file.path.to_string_lossy(); |
| 1975 | paths.insert( |
| 1976 | super::parallel::canonical_tree_path(&canonical) |
| 1977 | .to_string_lossy() |
| 1978 | .into_owned(), |
| 1979 | ); |
| 1980 | } |
| 1981 | } |
| 1982 | } |
| 1983 | Ok(paths) |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | /// Refuse to materialize over a worktree holding work Git has not recorded: |
no test coverage detected