Skip to content

Commit c2753b8

Browse files
committed
Merge branch 'fix-windows-tests'
2 parents f87322e + f48ed0c commit c2753b8

File tree

8 files changed

+43
-90
lines changed

8 files changed

+43
-90
lines changed

gix-archive/tests/archive.rs

+10-40
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod from_tree {
1717
#[test]
1818
fn basic_usage_internal() -> gix_testtools::Result {
1919
basic_usage(gix_archive::Format::InternalTransientNonPersistable, |buf| {
20-
assert_eq!(buf.len(), if cfg!(windows) { 565 } else { 551 });
20+
assert_eq!(buf.len(), 551);
2121

2222
let mut stream = gix_worktree_stream::Stream::from_read(std::io::Cursor::new(buf));
2323
let mut paths_and_modes = Vec::new();
@@ -27,11 +27,7 @@ mod from_tree {
2727
entry.read_to_end(&mut buf).expect("stream can always be read");
2828
}
2929

30-
let expected_link_mode = if cfg!(windows) {
31-
EntryKind::Blob
32-
} else {
33-
EntryKind::Link
34-
};
30+
let expected_link_mode = EntryKind::Link;
3531
let expected_exe_mode = if cfg!(windows) {
3632
EntryKind::Blob
3733
} else {
@@ -53,11 +49,7 @@ mod from_tree {
5349
(
5450
"symlink-to-a".into(),
5551
expected_link_mode,
56-
hex_to_id(if cfg!(windows) {
57-
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057"
58-
} else {
59-
"2e65efe2a145dda7ee51d1741299f848e5bf752e"
60-
})
52+
hex_to_id("2e65efe2a145dda7ee51d1741299f848e5bf752e")
6153
),
6254
(
6355
"dir/b".into(),
@@ -119,34 +111,20 @@ mod from_tree {
119111
header.mode()?,
120112
));
121113
}
122-
let expected_symlink_type = if cfg!(windows) {
123-
EntryType::Regular
124-
} else {
125-
EntryType::Symlink
126-
};
114+
let expected_symlink_type = EntryType::Symlink;
127115
let expected_exe_mode = if cfg!(windows) { 420 } else { 493 };
128116
assert_eq!(
129117
out,
130118
[
131119
("prefix/.gitattributes", EntryType::Regular, 56, 420),
132120
("prefix/a", EntryType::Regular, 3, 420),
133-
(
134-
"prefix/symlink-to-a",
135-
expected_symlink_type,
136-
if cfg!(windows) { 3 } else { 0 },
137-
420
138-
),
121+
("prefix/symlink-to-a", expected_symlink_type, 0, 420),
139122
("prefix/dir/b", EntryType::Regular, 3, 420),
140123
("prefix/dir/subdir/exe", EntryType::Regular, 0, expected_exe_mode),
141124
("prefix/extra-file", EntryType::Regular, 21, 420),
142125
("prefix/extra-exe", EntryType::Regular, 0, expected_exe_mode),
143126
("prefix/extra-dir-empty", EntryType::Directory, 0, 420),
144-
(
145-
"prefix/extra-dir/symlink-to-extra",
146-
expected_symlink_type,
147-
if cfg!(windows) { 21 } else { 0 },
148-
420
149-
)
127+
("prefix/extra-dir/symlink-to-extra", expected_symlink_type, 0, 420)
150128
]
151129
.into_iter()
152130
.map(|(path, b, c, d)| (bstr::BStr::new(path).to_owned(), b, c, d))
@@ -183,7 +161,7 @@ mod from_tree {
183161
},
184162
|buf| {
185163
assert!(
186-
buf.len() < 1270,
164+
buf.len() < 1280,
187165
"much bigger than uncompressed for some reason (565): {} < 1270",
188166
buf.len()
189167
);
@@ -208,19 +186,11 @@ mod from_tree {
208186
);
209187
let mut link = ar.by_name("prefix/symlink-to-a")?;
210188
assert!(!link.is_dir());
211-
assert_eq!(
212-
link.is_symlink(),
213-
cfg!(not(windows)),
214-
"symlinks are supported as well, but only on Unix"
215-
);
216-
assert_eq!(
217-
link.unix_mode(),
218-
Some(if cfg!(windows) { 0o100644 } else { 0o120644 }),
219-
"the mode specifies what it should be"
220-
);
189+
assert!(link.is_symlink(), "symlinks are supported as well, but only on Unix");
190+
assert_eq!(link.unix_mode(), Some(0o120644), "the mode specifies what it should be");
221191
let mut buf = Vec::new();
222192
link.read_to_end(&mut buf)?;
223-
assert_eq!(buf.as_bstr(), if cfg!(windows) { "hi\n" } else { "a" });
193+
assert_eq!(buf.as_bstr(), "a");
224194
Ok(())
225195
},
226196
)

gix-index/src/entry/mode.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl From<gix_object::tree::EntryMode> for Mode {
7474
}
7575

7676
/// A change of a [`Mode`].
77+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
7778
pub enum Change {
7879
/// The type of mode changed, like symlink => file.
7980
Type {

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,

gix-worktree-state/src/checkout/entry.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::{
23
fs::OpenOptions,
34
io::Write,
@@ -145,12 +146,19 @@ where
145146
err,
146147
path: dest.to_path_buf(),
147148
})?;
148-
let symlink_destination = gix_path::try_from_byte_slice(obj.data)
149-
.map_err(|_| crate::checkout::Error::IllformedUtf8 { path: obj.data.into() })?;
150-
151149
if symlink {
150+
#[cfg_attr(not(windows), allow(unused_mut))]
151+
let mut symlink_destination = Cow::Borrowed(
152+
gix_path::try_from_byte_slice(obj.data)
153+
.map_err(|_| crate::checkout::Error::IllformedUtf8 { path: obj.data.into() })?,
154+
);
155+
#[cfg(windows)]
156+
{
157+
symlink_destination = gix_path::to_native_path_on_windows(gix_path::into_bstr(symlink_destination))
158+
}
159+
152160
try_op_or_unlink(dest, overwrite_existing, |p| {
153-
gix_fs::symlink::create(symlink_destination, p)
161+
gix_fs::symlink::create(symlink_destination.as_ref(), p)
154162
})?;
155163
} else {
156164
let mut file = try_op_or_unlink(dest, overwrite_existing, |p| {

gix-worktree-stream/tests/stream.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ mod from_tree {
115115
} else {
116116
EntryKind::BlobExecutable
117117
};
118-
let expected_link_mode = if cfg!(windows) {
119-
EntryKind::Blob
120-
} else {
121-
EntryKind::Link
122-
};
118+
let expected_link_mode = EntryKind::Link;
123119
assert_eq!(
124120
paths_and_modes,
125121
&[
@@ -141,11 +137,7 @@ mod from_tree {
141137
(
142138
"symlink-to-a".into(),
143139
expected_link_mode,
144-
hex_to_id(if cfg!(windows) {
145-
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057"
146-
} else {
147-
"2e65efe2a145dda7ee51d1741299f848e5bf752e"
148-
})
140+
hex_to_id("2e65efe2a145dda7ee51d1741299f848e5bf752e")
149141
),
150142
(
151143
"dir/.gitattributes".into(),

tests/tools/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,16 @@ fn configure_command<'a>(
590590
script_result_directory: &Path,
591591
) -> &'a mut std::process::Command {
592592
let never_path = if cfg!(windows) { "-" } else { ":" };
593+
let mut msys_for_git_bash_on_windows = std::env::var("MSYS").unwrap_or_default();
594+
msys_for_git_bash_on_windows.push_str(" winsymlinks:nativestrict");
593595
cmd.args(args)
594596
.stdout(std::process::Stdio::piped())
595597
.stderr(std::process::Stdio::piped())
596598
.current_dir(script_result_directory)
597599
.env_remove("GIT_DIR")
598600
.env_remove("GIT_ASKPASS")
599601
.env_remove("SSH_ASKPASS")
602+
.env("MSYS", msys_for_git_bash_on_windows)
600603
.env("GIT_CONFIG_SYSTEM", never_path)
601604
.env("GIT_CONFIG_GLOBAL", never_path)
602605
.env("GIT_TERMINAL_PROMPT", "false")
@@ -751,7 +754,6 @@ fn extract_archive(
751754
}
752755
#[cfg(not(feature = "xz"))]
753756
{
754-
use std::io::Read;
755757
input_archive.read_to_end(&mut buf)?;
756758
}
757759
buf

0 commit comments

Comments
 (0)