Skip to content

Commit 8d14d2e

Browse files
committed
try to fix windows once again (#301)
1 parent f3bcf62 commit 8d14d2e

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

git-worktree/src/os.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ pub fn remove_symlink(path: &Path) -> io::Result<()> {
1212
std::fs::remove_file(path)
1313
}
1414

15+
// TODO: use the `symlink` crate once it can delete directory symlinks
1516
#[cfg(windows)]
1617
pub fn remove_symlink(path: &Path) -> io::Result<()> {
1718
dbg!(path, std::fs::symlink_metadata(path), std::fs::metadata(path));
18-
symlink::remove_symlink_auto(path)
19+
if let Ok(meta) = std::fs::metadata(path) {
20+
if meta.is_file() {
21+
std::fs::remove_file(path) // this removes the link itself
22+
} else {
23+
std::fs::remove_dir(path) // however, this sees the destination directory, which isn't the right thing actually
24+
}
25+
} else {
26+
std::fs::remove_file(path).or_else(|_| std::fs::remove_dir(path))
27+
}
1928
}
2029

2130
#[cfg(windows)]

git-worktree/tests/index/checkout.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod cache {
5858
symlink::symlink_dir(&forbidden, tmp.path().join("link-to-dir")).unwrap();
5959
std::fs::write(tmp.path().join("file-in-dir"), &[]).unwrap();
6060

61-
for dirname in &["link-to-dir", "file-in-dir"] {
61+
for dirname in &["file-in-dir", "link-to-dir"] {
6262
cache.unlink_on_collision = false;
6363
let relative_path = format!("{}/file", dirname);
6464
assert_eq!(
@@ -284,35 +284,26 @@ fn keep_going_collects_results() {
284284
)
285285
.unwrap();
286286

287-
assert_eq!(
288-
outcome
289-
.errors
290-
.iter()
291-
.map(
292-
|r| r.error.to_string()[.."object 4f41554f6e0045ef53848fc0c3f33b6a9abc24a9 for checkout at ".len()]
293-
.to_owned()
294-
)
295-
.collect::<Vec<_>>(),
296-
[
297-
"4f41554f6e0045ef53848fc0c3f33b6a9abc24a9",
298-
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
299-
]
300-
.iter()
301-
.map(|id| format!("object {} for checkout at ", id))
302-
.collect::<Vec<_>>()
303-
);
304287
assert_eq!(
305288
outcome
306289
.errors
307290
.iter()
308291
.map(|r| r.path.to_path_lossy().into_owned())
309292
.collect::<Vec<_>>(),
310-
paths(["dir/content", "empty"])
293+
paths(if opts.fs.symlink {
294+
["dir/content", "empty"]
295+
} else {
296+
["dir/content", "dir/sub-dir/symlink"] // not actually a symlink anymore
297+
})
311298
);
312299

313300
assert_eq!(
314301
stripped_prefix(&destination, &dir_structure(&destination)),
315-
paths(["dir/sub-dir/symlink", "executable"]),
302+
paths(if opts.fs.symlink {
303+
["dir/sub-dir/symlink", "executable"]
304+
} else {
305+
["empty", "executable"]
306+
}),
316307
"some files could not be created"
317308
);
318309

0 commit comments

Comments
 (0)