Skip to content

Drop -v from rm and cp commands in fixtures for portability #1646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

EliahKagan
Copy link
Member

In the fixture scripts, there is one invocation of rm with the -v option, which is only very recently standardized, and one invocation of cp with the -v option, which is nonstandard. The intent appears to be to make it easier to understand what a fixture has done if it fails, or if it is run manually to investigate it. This PR drops -v from those commands without replacing it with anything.

The two affected fixture scripts are heavily used, and the archives they generate are .gitignored. So this change causes 106 formerly failing tests to pass on my OmniOS test system (decreasing the number of failing tests from 108 to 2). I expect most illiumos and various other significant but less common Unix-like systems to have the same benefit.

The tradeoff of not showing verbose output appears to be reasonable to me in context here, but it may not be the best approach. Alternative approaches, and other details about the change--including the conditions under which it makes a difference and its relationship to POSIX--are given in the commit messages.

This removes `-v` from an `rm -R` command in `make_basic_repo.sh`,
which can cause tests that needed to run that fixture to fail on
systems where `rm` does not support `-v`.

The script generates a fixtured used in numerous tests, and it is
always run even if `GIX_TEST_IGNORE_ARCHIVES` is not set, since its
output is `.gitignore`d. Because the script is so heavily used,
this change allows many more tests to pass on systems where `rm`
does not recognize `-v` than before.

`rm -v` is actually POSIX, but it was standardized very recently,
in 1003.1-2024; it was not even required in 1003.1-2017. Some Unix
systems' `rm` commands do not recognize `-v`. This includes most
(or all?) illumos and Solaris systems (except when `/usr/gnu/bin`
is present and placed early in the `$PATH`). It seems likely that
there are a number of other such systems.

Regarding the history of `rm -v` in POSIX, see:

- https://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html
- https://pubs.opengroup.org/onlinepubs/9799919799/utilities/rm.html
- https://www.austingroupbugs.net/view.php?id=1154
- https://www.austingroupbugs.net/view.php?id=1365
- https://www.austingroupbugs.net/view.php?id=1487

Based on a `git grep -En 'rm( -[^v ;&|]*)+v'` search, this
occurrence in `make_basic_repo.sh` appears to be the only place
where `-v` is passed to `rm` in any gitoxide fixture script.

Two nearby similar, conceptually related commands omit `-v`, and
when this command (rather, the command that turned into it) was
introduced in the first version of the script in a4cec4a (GitoxideLabs#399),
another such command without `-v` was also present. This suggests
that `-v` may have been used for exploratory purposes during
development, such that the approach here of omitting `-v` it
without replacing it with anything might be sufficient.

However, it is possible for information shown when the fixture
script runs and fails to be less informative as a result of this
omission. An alternative approach to the one taken here could be to
have the script carry out a tiny experiment to check if `-v` is
supported, then use it only if it was found to be accepted.
(Another option could be to use `find` with both `-print` and
`-delete`, though that might be stronger than desired given that
the affected `rm` command does not pass `-f`.)
This change removes the `-v` option from the one `cp` invocation in
`gix-dir/tests/fixtures/many.sh`, the one fixture script that uses
it.

This is roughly analogous to the preceding removal of `-v` from the
one `mv` invocation that used that, and both fixture scripts are
heavily used due to being used in multiple tests and due to being
intentionally re-run even when `GIX_TEST_IGNORE_ARCHIVES` is not
set.

But while `rm -v` is standardized but only recently, `cp -v` is not
standard. Even POSIX 1003.1-2024 does not require `cp` to recognize
`-v`:

- https://pubs.opengroup.org/onlinepubs/9799919799/utilities/cp.html

See the preceding commit for general considerations, advantages and
disadvantages, and alterntive approaches. As there, this currently
just drops the `-v` without replacing it with anything, based on
the idea that printing the list of files being operated on (here,
copied) may not be important.

- That assumption may be less well-founded here, since the affected
  command, introduced in 482d6f3 (GitoxideLabs#1285), does *not* have other
  nearby `cp` commands that are conceptually related but omit `-v`.

- But, unlike there, it may be reasonable to consider the `-v` here
  to be a (minor) bug, since it is not standardized but it appears
  in test fixture code that seems intended to run all targets.

Taken together, this and the preceding commit allow 106 formerly
failing tests to pass, on the OmniOS system I used for testing.
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, I couldn't agree more.

@Byron Byron merged commit 35d4d9f into GitoxideLabs:main Oct 24, 2024
16 checks passed
@EliahKagan EliahKagan deleted the run-ci/portable-rm branch October 24, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants