From da8763d88975299a0887ddeaeb01e6a6a0cc7fea Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 30 Apr 2021 14:49:33 -0700 Subject: [PATCH] tools: Avoid `readlink -f` in *-pull-request scripts. This is a feature of GNU readlink that isn't in the BSD readlink found on macOS. For using this and other GNU coreutils features in our scripts in general, we could use a solution like mobile's tools/lib/ensure-coreutils.sh to get GNU coreutils on the PATH -- check if it's there already, if not then try to find a Homebrew install of it and use that, if not then print a helpful message. But even then there'd be a bootstrapping problem of how to find ensure-coreutils.sh . That involves exactly the same problem as we have for finding git-tools.sh in these lines. So in fact in mobile for the task of finding ensure-coreutils.sh in the first place, we do without `readlink -f` anyway. The one consequence of this behavior-wise is that if you make a symlink somewhere that points directly at that script (say in your `~/bin/`), and try to run it using that symlink, it won't work. (It'll still work just fine if there are symlinks somewhere higher up in the paths involved -- just not for the script itself.) An ideal CLI program really should support that, I think, but lacking a better idea, this seems an acceptable compromise. --- tools/fetch-pull-request | 4 ++-- tools/fetch-rebase-pull-request | 4 ++-- tools/reset-to-pull-request | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/fetch-pull-request b/tools/fetch-pull-request index d23b34f774..0d6c4c961e 100755 --- a/tools/fetch-pull-request +++ b/tools/fetch-pull-request @@ -1,9 +1,9 @@ #!/usr/bin/env bash set -e -this_file=$(readlink -f "${BASH_SOURCE[0]}") +this_dir=${BASH_SOURCE[0]%/*} # shellcheck source=lib/git-tools.bash -. "${this_file%/*}"/lib/git-tools.bash +. "${this_dir}"/lib/git-tools.bash require_clean_work_tree 'check out PR as branch' diff --git a/tools/fetch-rebase-pull-request b/tools/fetch-rebase-pull-request index 115f61d9d8..31ff4cdf75 100755 --- a/tools/fetch-rebase-pull-request +++ b/tools/fetch-rebase-pull-request @@ -1,9 +1,9 @@ #!/usr/bin/env bash set -e -this_file=$(readlink -f "${BASH_SOURCE[0]}") +this_dir=${BASH_SOURCE[0]%/*} # shellcheck source=lib/git-tools.bash -. "${this_file%/*}"/lib/git-tools.bash +. "${this_dir}"/lib/git-tools.bash require_clean_work_tree 'check out PR as branch' diff --git a/tools/reset-to-pull-request b/tools/reset-to-pull-request index 0480d5535f..6e5962ac62 100755 --- a/tools/reset-to-pull-request +++ b/tools/reset-to-pull-request @@ -39,9 +39,9 @@ if [ -z "$request_id" ]; then usage fi -this_file=$(readlink -f "${BASH_SOURCE[0]}") +this_dir=${BASH_SOURCE[0]%/*} # shellcheck source=lib/git-tools.bash -. "${this_file%/*}"/lib/git-tools.bash +. "${this_dir}"/lib/git-tools.bash require_clean_work_tree 'reset to PR'