Skip to content

Commit

Permalink
Merge pull request #1652 from EliahKagan/run-ci/chmod
Browse files Browse the repository at this point in the history
Test cross-platform symlink and +x permission expectations on Windows
  • Loading branch information
Byron authored Nov 5, 2024
2 parents 3fb989b + d03971b commit 8e99eba
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 70 deletions.
33 changes: 17 additions & 16 deletions gix-archive/tests/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ mod from_tree {
entry.read_to_end(&mut buf).expect("stream can always be read");
}

let expected_link_mode = EntryKind::Link;
let expected_exe_mode = if cfg!(windows) {
EntryKind::Blob
} else {
EntryKind::BlobExecutable
};
assert_eq!(
paths_and_modes,
&[
Expand All @@ -48,7 +42,7 @@ mod from_tree {
),
(
"symlink-to-a".into(),
expected_link_mode,
EntryKind::Link,
hex_to_id("2e65efe2a145dda7ee51d1741299f848e5bf752e")
),
(
Expand All @@ -58,7 +52,7 @@ mod from_tree {
),
(
"dir/subdir/exe".into(),
expected_exe_mode,
EntryKind::BlobExecutable,
hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")
),
(
Expand All @@ -68,7 +62,11 @@ mod from_tree {
),
(
"extra-exe".into(),
expected_exe_mode,
if cfg!(windows) {
EntryKind::Blob
} else {
EntryKind::BlobExecutable
},
hex_to_id("0000000000000000000000000000000000000000")
),
(
Expand All @@ -78,7 +76,7 @@ mod from_tree {
),
(
"extra-dir/symlink-to-extra".into(),
expected_link_mode,
EntryKind::Link,
hex_to_id("0000000000000000000000000000000000000000")
)
]
Expand Down Expand Up @@ -111,20 +109,23 @@ mod from_tree {
header.mode()?,
));
}
let expected_symlink_type = EntryType::Symlink;
let expected_exe_mode = if cfg!(windows) { 420 } else { 493 };
assert_eq!(
out,
[
("prefix/.gitattributes", EntryType::Regular, 56, 420),
("prefix/a", EntryType::Regular, 3, 420),
("prefix/symlink-to-a", expected_symlink_type, 0, 420),
("prefix/symlink-to-a", EntryType::Symlink, 0, 420),
("prefix/dir/b", EntryType::Regular, 3, 420),
("prefix/dir/subdir/exe", EntryType::Regular, 0, expected_exe_mode),
("prefix/dir/subdir/exe", EntryType::Regular, 0, 493),
("prefix/extra-file", EntryType::Regular, 21, 420),
("prefix/extra-exe", EntryType::Regular, 0, expected_exe_mode),
(
"prefix/extra-exe",
EntryType::Regular,
0,
if cfg!(windows) { 420 } else { 493 }
),
("prefix/extra-dir-empty", EntryType::Directory, 0, 420),
("prefix/extra-dir/symlink-to-extra", expected_symlink_type, 0, 420)
("prefix/extra-dir/symlink-to-extra", EntryType::Symlink, 0, 420)
]
.into_iter()
.map(|(path, b, c, d)| (bstr::BStr::new(path).to_owned(), b, c, d))
Expand Down
2 changes: 1 addition & 1 deletion gix-archive/tests/fixtures/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ echo "/dir-ignored/ export-ignore" > .gitattributes
echo "/file-ignored export-ignore" >> .gitattributes

git add .
git update-index --chmod=+x dir/subdir/exe # For Windows.
git commit -m "init"

echo "extra to be streamed" > extra-file
Expand All @@ -28,4 +29,3 @@ mkdir extra-dir-empty extra-dir
ln -s ../extra-file extra-dir/symlink-to-extra

git rev-parse @^{tree} > head.hex

7 changes: 3 additions & 4 deletions gix-dir/tests/fixtures/many-symlinks.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env bash
set -eu -o pipefail

# Note that symlink creation fails on Windows for some reason,
# so these tests shouldn't be run there.
# These fixtures use symlinks. See `many.sh` for some that don't.

git init breakout-symlink
(cd breakout-symlink
Expand All @@ -20,7 +19,7 @@ git init immediate-breakout-symlink

git init excluded-symlinks-to-dir
(cd excluded-symlinks-to-dir
cat <<EOF >.gitignore
cat <<'EOF' >.gitignore
src1
src2/
file1
Expand All @@ -42,4 +41,4 @@ EOF
ln -s src/file file2
)

ln -s excluded-symlinks-to-dir worktree-root-is-symlink
ln -s excluded-symlinks-to-dir worktree-root-is-symlink
2 changes: 1 addition & 1 deletion gix-dir/tests/fixtures/many.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -eu -o pipefail

# Nothing here may use symlinks so these fixtures can be used on windows as well.
# These fixtures don't use symlinks. See `many-symlinks.sh` for some that do.

git init with-nested-dot-git
(cd with-nested-dot-git
Expand Down
4 changes: 0 additions & 4 deletions gix-dir/tests/walk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use gix_dir::walk::ForDeletionMode;
use gix_ignore::Kind::*;

#[test]
#[cfg_attr(windows, ignore = "symlinks the way they are organized don't yet work on windows")]
fn symlink_to_dir_can_be_excluded() -> crate::Result {
let root = fixture_in("many-symlinks", "excluded-symlinks-to-dir");
let ((out, _root), entries) = collect(&root, None, |keep, ctx| {
Expand Down Expand Up @@ -94,7 +93,6 @@ fn symlink_to_dir_can_be_excluded() -> crate::Result {
}

#[test]
#[cfg_attr(windows, ignore = "symlinks the way they are organized don't yet work on windows")]
fn root_may_not_lead_through_symlinks() -> crate::Result {
for (name, intermediate, expected) in [
("immediate-breakout-symlink", "", 0),
Expand All @@ -121,7 +119,6 @@ fn root_may_not_lead_through_symlinks() -> crate::Result {
}

#[test]
#[cfg_attr(windows, ignore = "symlinks the way they are organized don't yet work on windows")]
fn root_may_be_a_symlink_if_it_is_the_worktree() -> crate::Result {
let root = fixture_in("many-symlinks", "worktree-root-is-symlink");
let ((_out, _root), entries) = collect(&root, None, |keep, ctx| {
Expand Down Expand Up @@ -2702,7 +2699,6 @@ fn decomposed_unicode_in_directory_is_returned_precomposed() -> crate::Result {
}

#[test]
#[cfg_attr(windows, ignore = "symlinks the way they are organized don't yet work on windows")]
fn worktree_root_can_be_symlink() -> crate::Result {
let root = fixture_in("many-symlinks", "symlink-to-breakout-symlink");
let troot = root.join("file");
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions gix-index/tests/fixtures/make_index/v2_all_file_kinds.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env bash
set -eu -o pipefail

export GIT_INDEX_VERSION=2;
export GIT_INDEX_VERSION=2

git init -q sub
(cd sub

touch a b c
git add .
git commit -m "init"
Expand All @@ -21,6 +20,7 @@ mkdir d
(cd d && touch a b c)

git add .
git update-index --chmod=+x b # For Windows.
git commit -m "init"

git rev-parse @^{tree} > head.tree
3 changes: 2 additions & 1 deletion gix-index/tests/fixtures/make_index/v2_deeper_tree.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -eu -o pipefail

export GIT_INDEX_VERSION=2;
export GIT_INDEX_VERSION=2

mkdir sub
(cd sub
Expand All @@ -25,4 +25,5 @@ mkdir d
)

git add .
git update-index --chmod=+x b # For Windows.
git commit -m "init"
Binary file modified gix-merge/tests/fixtures/generated-archives/tree-baseline.tar
Binary file not shown.
12 changes: 6 additions & 6 deletions gix-merge/tests/fixtures/tree-baseline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ git init same-rename-different-mode

git checkout A
write_lines 1 2 3 4 5 >a/x.f
chmod +x a/x.f
chmod +x a/w
chmod +x a/x.f a/w
git update-index --chmod=+x a/x.f a/w
git mv a a-renamed
git commit -am "changed all content, add +x, renamed a -> a-renamed"

Expand All @@ -486,8 +486,8 @@ git init same-rename-different-mode
git commit -am "changed all content, renamed a -> a-renamed"

git checkout expected
chmod +x a/x.f
chmod +x a/w
chmod +x a/x.f a/w
git update-index --chmod=+x a/x.f a/w
write_lines 1 2 3 4 5 6 >a/x.f
git mv a a-renamed
git commit -am "Git, when branches are reversed, doesn't keep the +x flag on a/w so we specify our own expectation"
Expand Down Expand Up @@ -530,13 +530,13 @@ git init added-file-changed-content-and-mode
git checkout B
write_lines original 1 2 3 4 5 6 >new
chmod +x new
git add .
git add --chmod=+x new
git commit -m "add new with content B and +x"

git checkout expected
echo -n $'<<<<<<< A\n1\n2\n3\n4\n5\n=======\noriginal\n1\n2\n3\n4\n5\n6\n>>>>>>> B\n' >new
chmod +x new
git add new
git add --chmod=+x new
git commit -m "Git has a better merge here, but that's due to better hunk handling/hunk splitting. We, however, consistently use +x"
)

Expand Down
Binary file modified gix-status/tests/fixtures/generated-archives/status_many.tar
Binary file not shown.
Binary file modified gix-status/tests/fixtures/generated-archives/status_removed.tar
Binary file not shown.
3 changes: 2 additions & 1 deletion gix-status/tests/fixtures/status_changed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mkdir dir/sub-dir
(cd dir/sub-dir && ln -sf ../content symlink)

git add -A
git update-index --chmod=+x executable # For Windows.
git commit -m "Commit"

chmod +x dir/content
Expand All @@ -23,4 +24,4 @@ echo -n "foo" > executable

rm empty
ln -sf dir/content empty
git reset
git reset
1 change: 1 addition & 0 deletions gix-status/tests/fixtures/status_many.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ git init -q changed-and-untracked
echo "different content" > dir/content2

git add -A
git update-index --chmod=+x executable # For Windows.
git commit -m "Commit"
echo "change" >> executable

Expand Down
3 changes: 2 additions & 1 deletion gix-status/tests/fixtures/status_removed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mkdir dir/sub-dir
(cd dir/sub-dir && ln -sf ../content symlink)

git add -A
git update-index --chmod=+x executable # For Windows.
git commit -m "Commit"
rm -rf ./empty ./executable ./dir/content ./dir/sub-dir/symlink
git reset
git reset
3 changes: 2 additions & 1 deletion gix-status/tests/fixtures/status_unchanged.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ mkdir dir/sub-dir
(cd dir/sub-dir && ln -sf ../content symlink)

git add -A
git update-index --chmod=+x executable # For Windows.
git commit -m "Commit"

touch ./empty ./executable ./dir/content ./dir/sub-dir/symlink

git reset # ensure index timestamp is large enough to not mark everything racy
git reset # ensure index timestamp is large enough to not mark everything racy
1 change: 1 addition & 0 deletions gix-worktree-state/tests/fixtures/make_mixed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mkdir dir/sub-dir
(cd dir/sub-dir && ln -sf ../content symlink)

git add -A
git update-index --chmod=+x executable # For Windows.
git commit -m "Commit"

git init module1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ mkdir dir/sub-dir
(cd dir/sub-dir && ln -sf ../content symlink)

git add -A
git update-index --chmod=+x executable # For Windows.
git commit -m "Commit"
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ mkdir dir/sub-dir
echo "even other content" > dir/sub-dir/file

git add -A
git update-index --chmod=+x executable # For Windows.
git commit -m "Commit"
22 changes: 4 additions & 18 deletions gix-worktree-state/tests/state/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,13 @@ fn delayed_driver_process() -> crate::Result {
}

#[test]
#[cfg_attr(
windows,
ignore = "on windows, the symlink to a directory doesn't seem to work and we really want to test with symlinks"
)]
fn overwriting_files_and_lone_directories_works() -> crate::Result {
for delay in [
gix_filter::driver::apply::Delay::Allow,
gix_filter::driver::apply::Delay::Forbid,
] {
let mut opts = opts_from_probe();
assert!(
opts.fs.symlink,
"BUG: the probe must detect to be able to generate symlinks"
);
assert!(opts.fs.symlink, "The probe must detect to be able to generate symlinks");
opts.overwrite_existing = true;
opts.filter_process_delay = delay;
opts.destination_is_initially_empty = false;
Expand Down Expand Up @@ -244,8 +237,7 @@ fn overwriting_files_and_lone_directories_works() -> crate::Result {
);

let symlink = destination.path().join("dir/sub-dir/symlink");
// on windows, git won't create symlinks as its probe won't detect the capability, even though we do.
assert_eq!(std::fs::symlink_metadata(&symlink)?.is_symlink(), cfg!(unix));
assert!(std::fs::symlink_metadata(&symlink)?.is_symlink());
assert_eq!(
std::fs::read(symlink)?.as_bstr(),
"➡other content\r\n",
Expand All @@ -270,10 +262,7 @@ fn symlinks_become_files_if_disabled() -> crate::Result {
#[test]
fn symlinks_to_directories_are_usable() -> crate::Result {
let opts = opts_from_probe();
if !opts.fs.symlink {
eprintln!("Skipping directory symlink test on filesystem that doesn't support it");
return Ok(());
}
assert!(opts.fs.symlink, "The probe must detect to be able to generate symlinks");

let (_source_tree, destination, _index, outcome) =
checkout_index_in_tmp_dir(opts.clone(), "make_dir_symlink", None)?;
Expand All @@ -298,10 +287,7 @@ fn symlinks_to_directories_are_usable() -> crate::Result {
#[test]
fn dangling_symlinks_can_be_created() -> crate::Result {
let opts = opts_from_probe();
if !opts.fs.symlink {
eprintln!("Skipping dangling symlink test on filesystem that doesn't support it");
return Ok(());
}
assert!(opts.fs.symlink, "The probe must detect to be able to generate symlinks");

for (fixture, symlink_name, target_name) in [
("make_dangling_symlink", "dangling", "non-existing-target"),
Expand Down
2 changes: 1 addition & 1 deletion gix-worktree-stream/tests/fixtures/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ echo "/file-ignored export-ignore" >> .gitattributes
dd if=/dev/zero of=bigfile bs=1024 count=156

git add .
git update-index --chmod=+x dir/subdir/exe
git commit -m "init"

echo "extra" > extra-file
Expand All @@ -32,4 +33,3 @@ ln -s ../extra-file extra-dir/symlink-to-extra
dd if=/dev/zero of=extra-bigfile bs=1024 count=156

git rev-parse @^{tree} > head.hex

Loading

0 comments on commit 8e99eba

Please sign in to comment.