Skip to content

Commit d52cbf2

Browse files
EliahKaganLuaKT
authored andcommitted
Test that symlinks to directories are usable
At least as `std::fs::metdata` currently works on Windows, this entails that symlinks to directories on Windows are created as directory symlinks rather than as file symlinks (since file symlinks cannot always be automatically dereferenced, and accessing metadata via the `stat`-like `std::fs::metadata` function is one situation where that cannot be done). This fixes GitoxideLabs#1422. Note that this issue pertains solely to what the test suite covers; the issue is not a bug in the code under test, and this commit does not modify the code under test.
1 parent 8e49aab commit d52cbf2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
target_oid=$(echo -n "." | git hash-object -w --stdin)
7+
8+
git update-index --index-info <<EOF
9+
120000 $target_oid symlink
10+
EOF
11+
12+
git commit -m "symlink in index, points to directory"

gix-worktree-state/tests/state/checkout.rs

+28
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,34 @@ fn symlinks_become_files_if_disabled() -> crate::Result {
267267
Ok(())
268268
}
269269

270+
#[test]
271+
fn symlinks_to_directories_are_usable() -> crate::Result {
272+
let opts = opts_from_probe();
273+
if !opts.fs.symlink {
274+
eprintln!("Skipping directory symlink test on filesystem that doesn't support it");
275+
return Ok(());
276+
}
277+
278+
let (_source_tree, destination, _index, outcome) =
279+
checkout_index_in_tmp_dir(opts.clone(), "make_dir_symlink", None)?;
280+
let worktree_files = dir_structure(&destination);
281+
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);
282+
283+
assert_eq!(worktree_files_stripped, paths(["symlink"]));
284+
let symlink_path = &worktree_files[0];
285+
assert!(symlink_path
286+
.symlink_metadata()
287+
.expect("symlink is on disk")
288+
.is_symlink());
289+
assert!(symlink_path
290+
.metadata()
291+
.expect("metadata accessible through symlink")
292+
.is_dir());
293+
assert_eq!(std::fs::read_link(symlink_path)?, Path::new("."));
294+
assert!(outcome.collisions.is_empty());
295+
Ok(())
296+
}
297+
270298
#[test]
271299
fn dangling_symlinks_can_be_created() -> crate::Result {
272300
let opts = opts_from_probe();

0 commit comments

Comments
 (0)