Skip to content

Commit 470c76e

Browse files
committed
Set +x in index in gix-archive basic fixture, adjust tests
As far as I know, gix-archive has no limitations related to Unix executable bits, on any platform. On Windows, the *filesystem* does not support these, and `chmod +x` commands in fixtures run in Git Bash appear to succeed but actually have no effect. But +x metadata can be staged and committed in Git repositories. When that is done, gix-archive can use those metadata just as it does on a Unix-like system. This fixes the tests to reflect this ability. Changes: 1. Add a `git update-index --chmod=+x` command to the gix-archive `basic.sh` fixture for `dir/subdir/exe`, so that even if the `chmod +x` command has no effect, the executable bit is set. This only affects `dir/subdir/exe`. It does not affect `extra-exe`, since that is never staged. On Windows, `extra-exe` can never have any associated executable mode bits. 2. Update the `basic_usage_internal` test to assert that `dir/subdir/exe` is `EntryKind::BlobExecutable` on all platforms, i.e., no longer `EntryKind::Blob` on Windows. Without this change, the change in (1) causes the test to fail. This also refactors to remove the `expected_exe_mode` constant, since its value is now only used in one place (for `extra-exe`), and to remove `expected_link_mode`, which has unconditionally been another name for `EntryKind::Link` since 93e088a (GitoxideLabs#1444). 3. Update the `basic_usage_tar` test to assert that the mode stored for `prefix/dir/subdir/exe` is 493 (0o755) on all platforms, i.e., no longer 420 (0o644) on Windows. This is analogous to (2), and without this the `basic_usage_tar` test fails due to the changes in (1). As in (2), this includes refactoring: `expected_exe_mode` is removed now that the choice between 420 (0o644) and 493 (0o755) is only made in one place (for `prefix/extra-exe`), and `expected_symlink_type` is removed, since it has unconditionally been another name for `EntryType::Symlink` since 93e088a (GitoxideLabs#1444). For future reference, with (1) but before (2), the failure is: --- STDERR: gix-archive::archive from_tree::basic_usage_internal --- Archive at 'tests\fixtures\generated-archives\basic.tar' not found, creating fixture using script 'basic.sh' thread 'from_tree::basic_usage_internal' panicked at gix-archive\tests\archive.rs:36:13: assertion `left == right` failed left: [(".gitattributes", Blob, Sha1(45c160c35c17ad264b96431cceb9793160396e99)), ("a", Blob, Sha1(45b983be36b73c0788dc9cbcb76cbb80fc7bb057)), ("symlink-to-a", Link, Sha1(2e65efe2a145dda7ee51d1741299f848e5bf752e)), ("dir/b", Blob, Sha1(ab4a98190cf776b43cb0fe57cef231fb93fd07e6)), ("dir/subdir/exe", BlobExecutable, Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)), ("extra-file", Blob, Sha1(0000000000000000000000000000000000000000)), ("extra-exe", Blob, Sha1(0000000000000000000000000000000000000000)), ("extra-dir-empty", Tree, Sha1(0000000000000000000000000000000000000000)), ("extra-dir/symlink-to-extra", Link, Sha1(0000000000000000000000000000000000000000))] right: [(".gitattributes", Blob, Sha1(45c160c35c17ad264b96431cceb9793160396e99)), ("a", Blob, Sha1(45b983be36b73c0788dc9cbcb76cbb80fc7bb057)), ("symlink-to-a", Link, Sha1(2e65efe2a145dda7ee51d1741299f848e5bf752e)), ("dir/b", Blob, Sha1(ab4a98190cf776b43cb0fe57cef231fb93fd07e6)), ("dir/subdir/exe", Blob, Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)), ("extra-file", Blob, Sha1(0000000000000000000000000000000000000000)), ("extra-exe", Blob, Sha1(0000000000000000000000000000000000000000)), ("extra-dir-empty", Tree, Sha1(0000000000000000000000000000000000000000)), ("extra-dir/symlink-to-extra", Link, Sha1(0000000000000000000000000000000000000000))] And with (1) but before (3), the failure is: --- STDERR: gix-archive::archive from_tree::basic_usage_tar --- thread 'from_tree::basic_usage_tar' panicked at gix-archive\tests\archive.rs:116:13: assertion `left == right` failed left: [("prefix/.gitattributes", Regular, 56, 420), ("prefix/a", Regular, 3, 420), ("prefix/symlink-to-a", Symlink, 0, 420), ("prefix/dir/b", Regular, 3, 420), ("prefix/dir/subdir/exe", Regular, 0, 493), ("prefix/extra-file", Regular, 21, 420), ("prefix/extra-exe", Regular, 0, 420), ("prefix/extra-dir-empty", Directory, 0, 420), ("prefix/extra-dir/symlink-to-extra", Symlink, 0, 420)] right: [("prefix/.gitattributes", Regular, 56, 420), ("prefix/a", Regular, 3, 420), ("prefix/symlink-to-a", Symlink, 0, 420), ("prefix/dir/b", Regular, 3, 420), ("prefix/dir/subdir/exe", Regular, 0, 420), ("prefix/extra-file", Regular, 21, 420), ("prefix/extra-exe", Regular, 0, 420), ("prefix/extra-dir-empty", Directory, 0, 420), ("prefix/extra-dir/symlink-to-extra", Symlink, 0, 420)] note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 parent ab45415 commit 470c76e

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

gix-archive/tests/archive.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ mod from_tree {
2727
entry.read_to_end(&mut buf).expect("stream can always be read");
2828
}
2929

30-
let expected_link_mode = EntryKind::Link;
31-
let expected_exe_mode = if cfg!(windows) {
32-
EntryKind::Blob
33-
} else {
34-
EntryKind::BlobExecutable
35-
};
3630
assert_eq!(
3731
paths_and_modes,
3832
&[
@@ -48,7 +42,7 @@ mod from_tree {
4842
),
4943
(
5044
"symlink-to-a".into(),
51-
expected_link_mode,
45+
EntryKind::Link,
5246
hex_to_id("2e65efe2a145dda7ee51d1741299f848e5bf752e")
5347
),
5448
(
@@ -58,7 +52,7 @@ mod from_tree {
5852
),
5953
(
6054
"dir/subdir/exe".into(),
61-
expected_exe_mode,
55+
EntryKind::BlobExecutable,
6256
hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")
6357
),
6458
(
@@ -68,7 +62,7 @@ mod from_tree {
6862
),
6963
(
7064
"extra-exe".into(),
71-
expected_exe_mode,
65+
if cfg!(windows) { EntryKind::Blob } else { EntryKind::BlobExecutable },
7266
hex_to_id("0000000000000000000000000000000000000000")
7367
),
7468
(
@@ -78,7 +72,7 @@ mod from_tree {
7872
),
7973
(
8074
"extra-dir/symlink-to-extra".into(),
81-
expected_link_mode,
75+
EntryKind::Link,
8276
hex_to_id("0000000000000000000000000000000000000000")
8377
)
8478
]
@@ -111,20 +105,18 @@ mod from_tree {
111105
header.mode()?,
112106
));
113107
}
114-
let expected_symlink_type = EntryType::Symlink;
115-
let expected_exe_mode = if cfg!(windows) { 420 } else { 493 };
116108
assert_eq!(
117109
out,
118110
[
119111
("prefix/.gitattributes", EntryType::Regular, 56, 420),
120112
("prefix/a", EntryType::Regular, 3, 420),
121-
("prefix/symlink-to-a", expected_symlink_type, 0, 420),
113+
("prefix/symlink-to-a", EntryType::Symlink, 0, 420),
122114
("prefix/dir/b", EntryType::Regular, 3, 420),
123-
("prefix/dir/subdir/exe", EntryType::Regular, 0, expected_exe_mode),
115+
("prefix/dir/subdir/exe", EntryType::Regular, 0, 493),
124116
("prefix/extra-file", EntryType::Regular, 21, 420),
125-
("prefix/extra-exe", EntryType::Regular, 0, expected_exe_mode),
117+
("prefix/extra-exe", EntryType::Regular, 0, if cfg!(windows) { 420 } else { 493 }),
126118
("prefix/extra-dir-empty", EntryType::Directory, 0, 420),
127-
("prefix/extra-dir/symlink-to-extra", expected_symlink_type, 0, 420)
119+
("prefix/extra-dir/symlink-to-extra", EntryType::Symlink, 0, 420)
128120
]
129121
.into_iter()
130122
.map(|(path, b, c, d)| (bstr::BStr::new(path).to_owned(), b, c, d))

gix-archive/tests/fixtures/basic.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ echo "/dir-ignored/ export-ignore" > .gitattributes
2020
echo "/file-ignored export-ignore" >> .gitattributes
2121

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

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

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

0 commit comments

Comments
 (0)