Skip to content

Commit 8513b94

Browse files
committed
fix: typo in comment and sorting logic for parent directories
1 parent 5e9082d commit 8513b94

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • apps/native/src-tauri/src/git

apps/native/src-tauri/src/git/exec.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub fn checkout_files_at_commit(dir: &str, commit_hash: &str) -> Result<()> {
270270
/// - Reported untracked files and any now-empty tracked parent directories are
271271
/// removed; ignored files are preserved. This requires a bit more sophisticated
272272
/// approach (in the helper than `git clean -fd` alone because git2 does not expose
273-
/// that command with those semantices.
273+
/// that command with those semantics.
274274
pub fn restore_all(dir: &str) -> Result<()> {
275275
let repo = git2::Repository::discover(dir)?;
276276
let head = repo
@@ -334,7 +334,14 @@ fn remove_untracked(repo: &git2::Repository) -> Result<()> {
334334
}
335335
}
336336

337-
parent_dirs.sort_by_key(|path| std::cmp::Reverse(path.components().count()));
337+
// Sort by deeper paths first, then sort lexically so that duplicates
338+
// are adjacent and can be deduped while preserving the correct order.
339+
parent_dirs.sort_by(|a, b| {
340+
b.components()
341+
.count()
342+
.cmp(&a.components().count())
343+
.then_with(|| a.cmp(b))
344+
});
338345
parent_dirs.dedup();
339346
for dir in parent_dirs {
340347
// Failure usually means the directory contains a tracked or ignored

0 commit comments

Comments
 (0)