Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .agents/scripts/issue-sync-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

While ${BASH_SOURCE[0]%/*} is a good replacement for dirname to avoid an external command dependency, it behaves differently when ${BASH_SOURCE[0]} does not contain a /. For example, if the script is in the current directory and invoked as bash issue-sync-helper.sh, ${BASH_SOURCE[0]} will be issue-sync-helper.sh.

  • dirname "issue-sync-helper.sh" correctly returns .
  • echo "${BASH_SOURCE[0]%/*}" returns issue-sync-helper.sh, which causes cd to fail.

This introduces a regression that can break the script in some invocation scenarios. A more robust approach would be to handle this edge case.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit
SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && pwd)" || exit

source "${SCRIPT_DIR}/shared-constants.sh"
# shellcheck source=issue-sync-lib.sh
source "${SCRIPT_DIR}/issue-sync-lib.sh"
Expand Down
2 changes: 1 addition & 1 deletion .agents/scripts/issue-sync-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _ISSUE_SYNC_LIB_LOADED=1
# Source shared-constants.sh to make the library self-contained.
# Resolves SCRIPT_DIR from BASH_SOURCE so it works when sourced from any location.
if [[ -z "${SCRIPT_DIR:-}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

While ${BASH_SOURCE[0]%/*} is a good replacement for dirname to avoid an external command dependency, it behaves differently when ${BASH_SOURCE[0]} does not contain a /. For example, if this library is sourced from a script in the current directory that is invoked as bash script.sh, ${BASH_SOURCE[0]} will be issue-sync-lib.sh.

  • dirname "issue-sync-lib.sh" correctly returns .
  • echo "${BASH_SOURCE[0]%/*}" returns issue-sync-lib.sh, which causes cd to fail.

This introduces a regression that can break the script in some invocation scenarios. A more robust approach would be to handle this edge case.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && pwd)"

fi
source "${SCRIPT_DIR}/shared-constants.sh"

Expand Down