summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2022-01-23 08:21:01 +0100
committerCanop <cano.petrole@gmail.com>2022-01-23 08:21:01 +0100
commit746d33946bcdde7ae552f9ed040ef284e0769c5a (patch)
tree6edb82335a04e6058d1f58c3bd360e69515f0ce7 /src
parentd8c943716fb02185c66d8d821cabf872e2ef67f6 (diff)
fix git statuses not working for worktrees
Fix #428
Diffstat (limited to 'src')
-rw-r--r--src/git/status.rs25
-rw-r--r--src/tree_build/builder.rs2
2 files changed, 11 insertions, 16 deletions
diff --git a/src/git/status.rs b/src/git/status.rs
index efbce45..0e9e866 100644
--- a/src/git/status.rs
+++ b/src/git/status.rs
@@ -34,25 +34,20 @@ pub struct LineStatusComputer {
interesting_statuses: AHashMap<PathBuf, Status>,
}
impl LineStatusComputer {
- pub fn from(repo: Repository) -> Self {
- let repo_path = repo.path().parent().unwrap().to_path_buf();
+ pub fn from(repo: Repository) -> Option<Self> {
+ let workdir = repo.workdir()?;
let mut interesting_statuses = AHashMap::default();
- if let Ok(statuses) = &repo.statuses(None) {
- for entry in statuses.iter() {
- let status = entry.status();
- if status.intersects(INTERESTING) {
- if let Some(path) = entry.path() {
- let path = repo_path.join(path);
- interesting_statuses.insert(path, status);
- }
+ let statuses = repo.statuses(None).ok()?;
+ for entry in statuses.iter() {
+ let status = entry.status();
+ if status.intersects(INTERESTING) {
+ if let Some(path) = entry.path() {
+ let path = workdir.join(path);
+ interesting_statuses.insert(path, status);
}
}
- } else {
- debug!("get statuses failed");
- }
- Self {
- interesting_statuses,
}
+ Some(Self { interesting_statuses })
}
pub fn line_status(&self, path: &Path) -> Option<LineGitStatus> {
self.interesting_statuses
diff --git a/src/tree_build/builder.rs b/src/tree_build/builder.rs
index c091879..14113d7 100644
--- a/src/tree_build/builder.rs
+++ b/src/tree_build/builder.rs
@@ -81,7 +81,7 @@ impl<'c> TreeBuilder<'c> {
"init line_status_computer",
Repository::discover(&path)
.ok()
- .map(LineStatusComputer::from),
+ .and_then(LineStatusComputer::from),
)
} else {
None