Skip to content

Commit c28f492

Browse files
committed
also validate symlink collisions (#301)
1 parent 58145bc commit c28f492

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

git-worktree/tests/fixtures/make_ignorecase_collisions.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ git init -q
55
git config commit.gpgsign false
66

77
empty_oid=$(git hash-object -w --stdin </dev/null)
8+
symlink_target=$(echo -n 'X' | git hash-object -w --stdin)
89

910
git update-index --index-info <<-EOF
1011
100644 $empty_oid FILE_X
@@ -14,6 +15,9 @@ git update-index --index-info <<-EOF
1415
100644 $empty_oid D/B
1516
100644 $empty_oid D/C
1617
100644 $empty_oid d
18+
100644 $empty_oid X
19+
120000 $symlink_target x
20+
120000 $symlink_target link-to-X
1721
EOF
1822

1923
git commit -m "init"

git-worktree/tests/index/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ mod checkout {
3131
}
3232
}
3333

34+
fn paths<'a>(p: impl IntoIterator<Item = &'a str>) -> Vec<PathBuf> {
35+
p.into_iter().map(PathBuf::from).collect()
36+
}
37+
3438
#[test]
3539
fn symlinks_become_files_if_disabled() -> crate::Result {
3640
let opts = opts_with_symlink(false);
@@ -76,11 +80,12 @@ mod checkout {
7680

7781
#[test]
7882
fn collisions_are_detected_on_a_case_sensitive_filesystem() {
79-
if !probe_gitoxide_dir().unwrap().ignore_case {
83+
let fs_caps = probe_gitoxide_dir().unwrap();
84+
if !fs_caps.ignore_case {
8085
eprintln!("Skipping case-insensitive testing on what would be a case-senstive file system");
8186
return;
8287
}
83-
let opts = opts_with_symlink(true);
88+
let opts = opts_with_symlink(fs_caps.symlink);
8489
let (source_tree, destination, _index, outcome) =
8590
checkout_index_in_tmp_dir(opts, "make_ignorecase_collisions").unwrap();
8691

@@ -109,21 +114,25 @@ mod checkout {
109114
path: "file_x".into(),
110115
error_kind,
111116
},
117+
Collision {
118+
path: "x".into(),
119+
error_kind,
120+
},
112121
],
113122
"these files couldn't be checked out"
114123
);
115124

116125
let source_files = dir_structure(&source_tree);
117126
assert_eq!(
118127
stripped_prefix(&source_tree, &source_files),
119-
vec![PathBuf::from("d"), PathBuf::from("file_x")],
128+
paths(["d", "file_x", "link-to-X", "x"]),
120129
"plenty of collisions prevent a checkout"
121130
);
122131

123132
let dest_files = dir_structure(&destination);
124133
assert_eq!(
125134
stripped_prefix(&destination, &dest_files),
126-
vec![PathBuf::from("D/B"), PathBuf::from("D/C"), PathBuf::from("FILE_X")],
135+
paths(["D/B", "D/C", "FILE_X", "X", "link-to-X"]),
127136
"we checkout files in order and generally handle collision detection differently, hence the difference"
128137
);
129138
}

0 commit comments

Comments
 (0)