Skip to content
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

FIX 'which' check in 'sake' now works for aliases #11232

Merged
merged 3 commits into from
May 19, 2024

Conversation

NoLdman
Copy link
Contributor

@NoLdman NoLdman commented May 10, 2024

Description

sake may wrongly exit early on its which check, since the current implementation does the following:

  1. Retrieves via command -v information about the which executable
  2. Tries to check the returned information string, if it is executable.

This solution is problematic since the returned information string may include alias information (and more),
which test -x can not interpret.

Additionally is the test -x check unnecessary since command -v already only returns executable command or fails if the command can not be found.

Therefore, I changed the source to just check for the exit status of command -v.

Manual testing steps

Run vendor/bin/sake dev/build on a POSIX compliant system, where which itself has been aliased.

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@NoLdman NoLdman changed the title 🐛 Fixed 'which' check for 'sake' FIX 'which' check in 'sake' now works for aliases May 10, 2024
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Docs for the command command for future reference.

@michalkleiner and @minimalic can you please confirm if this works for you? I note there was discussion about the alternative PR, but hopefully this PR works for all those cases.

sake Outdated Show resolved Hide resolved
sake Outdated Show resolved Hide resolved
NoLdman and others added 3 commits May 20, 2024 10:52
Improves on the current implementations since
'command' already only returns executable commands.
Additionally, the success output of 'command' is not standardized
and may contain additional information.
Therefore, a 'test' if the result of 'command'
is a valid executable file, may fail incorrectly.

Now just relying on the standardized exit status of 'command -v'.
The previous implementation used '&&' piping
wich is handled differently in PHP and Bash code
and therefore, may be confusing to a PHP developer.
I refactored the function to use a traditional if statement.
Converted to 'if' to square bracket based testing
to be in comply with the other 'if' statements in the script.

Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com>
@GuySartorelli GuySartorelli changed the base branch from 5 to 5.2 May 19, 2024 22:52
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

LGTM, works well locally.
Retargetted to 5.2 so it can be released as a patch. Will merge when CI goes green.

@GuySartorelli GuySartorelli merged commit 470293a into silverstripe:5.2 May 19, 2024
15 checks passed
@NoLdman NoLdman deleted the better-which-check-for-sake branch May 21, 2024 05:26
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.

None yet

4 participants