Skip to content

Commit

Permalink
Set +x in index in gix-archive basic fixture, adjust tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EliahKagan committed Nov 3, 2024
1 parent ab45415 commit 470c76e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
24 changes: 8 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,7 @@ 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 +72,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 +105,18 @@ 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

0 comments on commit 470c76e

Please sign in to comment.