Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ prepare() {

# Patching the install command in an error message.
sed -i -e 's/sudo apt install libsecret-tools/sudo pacman -S libsecret/' 'please.sh'

# Replace VERSION_NUMBER placeholder with the actual version derived from git tags.
_pkgver=$(git tag --sort=v:refname | tail -n1)
if [ -n "$_pkgver" ]; then
sed -i -e "s/VERSION_NUMBER/${_pkgver#v}/" 'please.sh'
fi
}

package() {
Expand Down
21 changes: 20 additions & 1 deletion please.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,27 @@ function store_api_key() {
done
}

_version="VERSION_NUMBER"

_script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

display_version() {
echo "Please vVERSION_NUMBER"
# The placeholder VERSION_NUMBER is replaced with the actual version by the
# bump-version CI workflow via sed. If it is still the literal string, the
# script is running from source or an unpatched install — fall back to git tags.
if [ "$_version" = "VERSION_NUMBER" ]; then
if [ -d "${_script_dir}/.git" ]; then
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

_tag is assigned inside display_version() without being declared local, which leaks a global variable into the script’s environment. Declare it as a local variable within the function to avoid unintended side effects with other globals.

Suggested change
if [ -d "${_script_dir}/.git" ]; then
if [ -d "${_script_dir}/.git" ]; then
local _tag

Copilot uses AI. Check for mistakes.
local _tag
_tag=$(cd "$_script_dir" && git tag --sort=v:refname 2>/dev/null | tail -n1)
Comment on lines +124 to +128
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The fallback version is derived from the highest tag in the repo (git tag --sort=v:refname | tail -n1), which can be incorrect if the user is on an older commit/branch (it can report a tag that doesn't point to the checked-out commit). Consider deriving the version from the current commit (e.g., nearest tag reachable from HEAD / tag pointing at HEAD) so --version reflects the code being executed.

Suggested change
# script is running from source or an unpatched install — fall back to git tags.
if [ "$_version" = "VERSION_NUMBER" ]; then
if [ -d "${_script_dir}/.git" ]; then
_tag=$(cd "$_script_dir" && git tag --sort=v:refname 2>/dev/null | tail -n1)
# script is running from source or an unpatched install — fall back to a tag
# that describes the currently checked-out commit.
if [ "$_version" = "VERSION_NUMBER" ]; then
if [ -d "${_script_dir}/.git" ]; then
_tag=$(cd "$_script_dir" && git describe --tags --exact-match 2>/dev/null)
if [ -z "$_tag" ]; then
_tag=$(cd "$_script_dir" && git describe --tags --abbrev=0 2>/dev/null)
fi

Copilot uses AI. Check for mistakes.
if [ -n "$_tag" ]; then
echo "Please v${_tag#v}"
return
fi
fi
echo "Please vVERSION_NUMBER"
else
echo "Please v$_version"
fi
}

display_help() {
Expand Down
11 changes: 11 additions & 0 deletions test/main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@ PLEASE_EXE=$BATS_TEST_DIRNAME/../please.sh
@test "smoke test please --version" {
result=$($PLEASE_EXE '--version')
[ "${result:0:8}" == "Please v" ]
[[ "${result}" != *"VERSION_NUMBER"* ]]
}

@test "version fallback derives version from git tags" {
_latest_tag=$(cd "$BATS_TEST_DIRNAME/.." && git tag --sort=v:refname | tail -n1)
if [ -z "$_latest_tag" ]; then
skip "No git tags available"
fi
_latest_tag="${_latest_tag#v}"
result=$($PLEASE_EXE '--version')
[ "$result" == "Please v${_latest_tag}" ]
Comment on lines +16 to +23
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

These tests assume the local checkout has git tags available. In GitHub Actions, actions/checkout often fetches a shallow clone without tags, which would make _latest_tag empty and also make please --version fall back to printing VERSION_NUMBER, failing both assertions. Consider skipping these assertions when no tags are present, or adjust the test setup to ensure tags are fetched/available before running the tests.

Copilot uses AI. Check for mistakes.
}
Loading