Fix missing diff hunks in single-file worktrees (#24377)
Release Notes: - Fixed diff hunks not appearing when opening a single file within a larger repository
This commit is contained in:
parent
592642fbfc
commit
01bcbf3b0d
2 changed files with 77 additions and 8 deletions
|
@ -372,15 +372,19 @@ impl WorkDirectory {
|
|||
/// of the project root folder, then the returned RepoPath is relative to the root
|
||||
/// of the repository and not a valid path inside the project.
|
||||
pub fn relativize(&self, path: &Path) -> Result<RepoPath> {
|
||||
if let Some(location_in_repo) = &self.location_in_repo {
|
||||
Ok(location_in_repo.join(path).into())
|
||||
let repo_path = if let Some(location_in_repo) = &self.location_in_repo {
|
||||
// Avoid joining a `/` to location_in_repo in the case of a single-file worktree.
|
||||
if path == Path::new("") {
|
||||
RepoPath(location_in_repo.clone())
|
||||
} else {
|
||||
location_in_repo.join(path).into()
|
||||
}
|
||||
} else {
|
||||
let relativized_path = path
|
||||
.strip_prefix(&self.path)
|
||||
.map_err(|_| anyhow!("could not relativize {:?} against {:?}", path, self.path))?;
|
||||
|
||||
Ok(relativized_path.into())
|
||||
}
|
||||
path.strip_prefix(&self.path)
|
||||
.map_err(|_| anyhow!("could not relativize {:?} against {:?}", path, self.path))?
|
||||
.into()
|
||||
};
|
||||
Ok(repo_path)
|
||||
}
|
||||
|
||||
/// This is the opposite operation to `relativize` above
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue