Skip to content

Commit 1e6065c

Browse files
Reset nodebuild when trying to update it (#418)
* Add support for nodebuild branches * Add workaround for asdf clearing nodebuild * Conditionally reset nodebuild if no binary
1 parent 2bd35bc commit 1e6065c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/commands/command-update-nodebuild

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,31 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../utils.sh"
66

77
: "${ASDF_NODEJS_NODEBUILD_HOME=$ASDF_NODEJS_PLUGIN_DIR/.node-build}"
88
: "${ASDF_NODEJS_NODEBUILD_REPOSITORY=https://github.com/nodenv/node-build.git}"
9+
: "${ASDF_NODEJS_NODEBUILD_BRANCH=main}"
910

1011
ensure_updated_project() {
11-
local pull_exit_code=0 output=
12+
local pull_exit_code=0
1213

1314
if ! [ -d "$ASDF_NODEJS_NODEBUILD_HOME" ]; then
1415
printf "Cloning node-build...\n"
15-
git clone "$ASDF_NODEJS_NODEBUILD_REPOSITORY" "$ASDF_NODEJS_NODEBUILD_HOME"
16+
git clone "$ASDF_NODEJS_NODEBUILD_REPOSITORY" "$ASDF_NODEJS_NODEBUILD_HOME" --branch "$ASDF_NODEJS_NODEBUILD_BRANCH"
1617
else
1718
printf "Trying to update node-build..."
18-
output=$(git -C "$ASDF_NODEJS_NODEBUILD_HOME" pull origin master 2>&1) || pull_exit_code=$?
19+
git -C "$ASDF_NODEJS_NODEBUILD_HOME" fetch origin "$ASDF_NODEJS_NODEBUILD_BRANCH" >&2 || pull_exit_code=$?
20+
git -C "$ASDF_NODEJS_NODEBUILD_HOME" checkout "$ASDF_NODEJS_NODEBUILD_BRANCH" >&2 || true
1921

2022
if [ "$pull_exit_code" != 0 ]; then
21-
printf "\n%s\n\n" "$output" >&2
22-
printf "$(colored $RED ERROR): Pulling the node-build repository exited with code %s\n" "$pull_exit_code" >&2
23-
printf "Please check if the git repository at %s doesn't have any changes or anything\nthat might not allow a git pull\n" "$ASDF_NODEJS_NODEBUILD_HOME" >&2
23+
printf "$(colored $RED ERROR): Pulling the node-build repository exited with code %s\n" "$pull_exit_code"
24+
printf "Please check if the git repository at %s doesn't have any changes or anything\nthat might not allow a git pull\n" "$ASDF_NODEJS_NODEBUILD_HOME"
2425
exit $pull_exit_code
2526
fi
2627

28+
# For some time, asdf-core was cleaning up the node-build directory by accident
29+
# This is a workaround to restore the files that were deleted
30+
if ! [ -f "$ASDF_NODEJS_NODEBUILD_HOME/bin/nodebuild" ]; then
31+
git -C "$ASDF_NODEJS_NODEBUILD_HOME" checkout HEAD . >&2
32+
fi
33+
2734
printf " ok\n"
2835
fi
2936
}

0 commit comments

Comments
 (0)