-
Notifications
You must be signed in to change notification settings - Fork 13
fix: replace dirname with POSIX parameter expansion in issue-sync scripts #2607
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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)" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other file, this change introduces a regression. While using parameter expansion is a great improvement, this specific implementation isn't a fully equivalent replacement for If To make this more robust and handle all invocation scenarios correctly, you could add a check for this edge case.
Suggested change
|
||||||
| fi | ||||||
| source "${SCRIPT_DIR}/shared-constants.sh" | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While using parameter expansion is a great improvement for performance and robustness in minimal environments, this specific implementation isn't a fully equivalent replacement for
dirname. It introduces a failure case when the script is executed from its own directory without a path prefix (e.g.,cd .agents/scripts && ./issue-sync-helper.shwould work, butissue-sync-helper.shwould fail if it's in the PATH and called from within its directory).If
${BASH_SOURCE[0]}contains no slashes (e.g., justissue-sync-helper.sh), the expansion${BASH_SOURCE[0]%/*}returns the script name itself.cding to a file will fail.dirnamecorrectly returns.in this case.To make this more robust and handle all invocation scenarios correctly, you could add a check for this edge case.