Skip to content

Commit fed4b48

Browse files
authored
git: Skip directories in git status output (#23300)
The output of `git status --porcelain=v1` includes untracked directories, i.e. directories that have no tracked files beneath. Since we have our own way of computing a "summary" status for each directory in a repo, this is not helpful for Zed; and it interferes with our handling of nested repos. So just skip these lines in the output. Closes #23133 Release Notes: - Fix project panel colors when one git repository is nested beneath another
1 parent 5f59536 commit fed4b48

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎crates/git/src/status.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,15 @@ impl GitStatus {
421421
.stdout(Stdio::piped())
422422
.stderr(Stdio::piped())
423423
.spawn()
424-
.map_err(|e| anyhow!("Failed to start git status process: {}", e))?;
424+
.map_err(|e| anyhow!("Failed to start git status process: {e}"))?;
425425

426426
let output = child
427427
.wait_with_output()
428-
.map_err(|e| anyhow!("Failed to read git blame output: {}", e))?;
428+
.map_err(|e| anyhow!("Failed to read git status output: {e}"))?;
429429

430430
if !output.status.success() {
431431
let stderr = String::from_utf8_lossy(&output.stderr);
432-
return Err(anyhow!("git status process failed: {}", stderr));
432+
return Err(anyhow!("git status process failed: {stderr}"));
433433
}
434434
let stdout = String::from_utf8_lossy(&output.stdout);
435435
let mut entries = stdout
@@ -440,6 +440,13 @@ impl GitStatus {
440440
return None;
441441
};
442442
let path = &entry[3..];
443+
// The git status output includes untracked directories as well as untracked files.
444+
// We do our own processing to compute the "summary" status of each directory,
445+
// so just skip any directories in the output, since they'll otherwise interfere
446+
// with our handling of nested repositories.
447+
if path.ends_with('/') {
448+
return None;
449+
}
443450
let status = entry[0..2].as_bytes().try_into().unwrap();
444451
let status = FileStatus::from_bytes(status).log_err()?;
445452
let path = RepoPath(Path::new(path).into());

0 commit comments

Comments
 (0)