Skip to content

Commit 3a90055

Browse files
committed
Allow tests to work with symlinks on Windows
1 parent 03a4545 commit 3a90055

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

gix-status/src/index_as_worktree/function.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,19 @@ impl<'index> State<'_, 'index> {
424424

425425
self.buf.clear();
426426
self.buf2.clear();
427+
let file_size_bytes = if cfg!(windows) && metadata.is_symlink() {
428+
// symlinks on Windows seem to have a length of zero, so just pretend
429+
// they have the correct length to avoid short-cutting, and enforce a full buffer check.
430+
entry.stat.size as u64
431+
} else {
432+
metadata.len()
433+
};
427434
let fetch_data = ReadDataImpl {
428435
buf: &mut self.buf,
429436
path: worktree_path,
430437
rela_path,
431438
entry,
432-
file_len: metadata.len(),
439+
file_len: file_size_bytes,
433440
filter: &mut self.filter,
434441
attr_stack: &mut self.attr_stack,
435442
options: self.options,
@@ -440,7 +447,7 @@ impl<'index> State<'_, 'index> {
440447
odb_reads: self.odb_reads,
441448
odb_bytes: self.odb_bytes,
442449
};
443-
let content_change = diff.compare_blobs(entry, metadata.len(), fetch_data, &mut self.buf2)?;
450+
let content_change = diff.compare_blobs(entry, file_size_bytes, fetch_data, &mut self.buf2)?;
444451
// This file is racy clean! Set the size to 0 so we keep detecting this as the file is updated.
445452
if content_change.is_some() || executable_bit_changed {
446453
let set_entry_stat_size_zero = content_change.is_some() && racy_clean;
@@ -531,7 +538,8 @@ where
531538
let out = if is_symlink && self.options.fs.symlink {
532539
// conversion to bstr can never fail because symlinks are only used
533540
// on unix (by git) so no reason to use the try version here
534-
let symlink_path = gix_path::into_bstr(std::fs::read_link(self.path)?);
541+
let symlink_path =
542+
gix_path::to_unix_separators_on_windows(gix_path::into_bstr(std::fs::read_link(self.path)?));
535543
self.buf.extend_from_slice(&symlink_path);
536544
self.worktree_bytes.fetch_add(self.buf.len() as u64, Ordering::Relaxed);
537545
Stream {

gix-status/tests/stack/mod.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,11 @@ fn paths_leading_through_symlinks_are_rejected() {
8383
}
8484

8585
fn is_symlink(m: &std::fs::Metadata) -> bool {
86-
if cfg!(windows) {
87-
// On windows, symlinks can't be seen, at least not through std
88-
m.is_file()
89-
} else {
90-
m.is_symlink()
91-
}
86+
m.is_symlink()
9287
}
9388

9489
fn is_symlinked_dir(m: &std::fs::Metadata) -> bool {
95-
if cfg!(windows) {
96-
// On windows, symlinks can't be seen, at least not through std
97-
m.is_dir()
98-
} else {
99-
m.is_symlink()
100-
}
90+
m.is_symlink()
10191
}
10292
fn is_file(m: &std::fs::Metadata) -> bool {
10393
m.is_file()

gix-status/tests/status/index_as_worktree.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,7 @@ fn refresh() {
469469
}
470470
.into(),
471471
),
472-
(
473-
BStr::new("empty"),
474-
3,
475-
Change::Modification {
476-
executable_bit_changed: false,
477-
content_change: Some(()),
478-
set_entry_stat_size_zero: false
479-
}
480-
.into(),
481-
),
472+
(BStr::new("empty"), 3, Change::Type.into()),
482473
(
483474
BStr::new("executable"),
484475
4,
@@ -551,16 +542,7 @@ fn modified() {
551542
}
552543
.into(),
553544
),
554-
(
555-
BStr::new("empty"),
556-
3,
557-
Change::Modification {
558-
executable_bit_changed: false,
559-
content_change: Some(()),
560-
set_entry_stat_size_zero: false,
561-
}
562-
.into(),
563-
),
545+
(BStr::new("empty"), 3, Change::Type.into()),
564546
(
565547
BStr::new("executable"),
566548
4,

0 commit comments

Comments
 (0)