Skip to content

Commit 80322f0

Browse files
stevenpollackclaude
andcommitted
fix(worktrees): always dirty-check before removal, even for non-utf8 paths
remove_worktree only ran the uncommitted/untracked-changes guard when the worktree path was valid UTF-8 (via path().to_str()). For a non-utf8 path the check was silently skipped and the working directory was pruned regardless of its contents — a data-loss window. RepoPath already implements From<PathBuf>, so pass the path directly and drop the to_str hop; behavior is identical for utf8 paths and the guard now always runs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1f8b38c commit 80322f0

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

asyncgit/src/sync/worktree.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,12 @@ pub fn remove_worktree(
214214
// changes (libgit2 does not refuse this itself). Only checkable
215215
// when the working dir still exists.
216216
if worktree.validate().is_ok() {
217-
if let Some(path) = worktree.path().to_str() {
218-
let wt_path: RepoPath = path.into();
219-
if !is_workdir_clean(&wt_path, None)? {
220-
return Err(Error::Generic(
221-
"worktree has uncommitted changes; commit or discard them first"
222-
.to_string(),
223-
));
224-
}
217+
let wt_path: RepoPath = worktree.path().to_path_buf().into();
218+
if !is_workdir_clean(&wt_path, None)? {
219+
return Err(Error::Generic(
220+
"worktree has uncommitted changes; commit or discard them first"
221+
.to_string(),
222+
));
225223
}
226224
}
227225

0 commit comments

Comments
 (0)