From ef2086280cf8009c3a2e2077db8d69947f9a9f56 Mon Sep 17 00:00:00 2001 From: Ryan Woods Date: Wed, 9 Nov 2022 10:26:14 +0100 Subject: [PATCH 1/2] Fix sandbox.tt variable comparison usage When an uninitialized variable is given to `-n`, it is treated as not NULL. The variable must be quoted for correct results. `[ -n "$SOLIDUS_BRANCH" ]` It is also recommended for variable comparisons in general as it can produce incorrect results for `! -z`. References: - https://tldp.org/LDP/abs/html/comparison-ops.html - https://tldp.org/LDP/abs/html/comparison-ops.html#STRTEST This meant that before, when running this file with no SOLIDUS_BRANCH variable, $BRANCH would end up NULL and the branch in the Gemfile would be an empty string. This caused an error, whereas instead, it should have defaulted to `master`. Error: ``` fatal: Needed a single revision Git error: command `git rev-parse --verify ''` in directory /Users/ryanwoods/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/cache/bundler/git/solidus-169f1ecb1aee2122950e6d586daf2410f62df66e has failed. Revision does not exist in the repository https://github.com/solidusio/solidus.git. Maybe you misspelled it? If this error persists you could try removing the cache directory '/Users/ryanwoods/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/cache/bundler/git/solidus-169f1ecb1aee2122950e6d586daf2410f62df66e' The git source https://github.com/solidusio/solidus.git is not yet checked out. Please run `bundle install` before trying to start your application ``` --- lib/solidus_dev_support/templates/extension/bin/sandbox.tt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt index b30c645c..db779999 100755 --- a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt +++ b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -if [ ! -z $DEBUG ] +if [ ! -z "$DEBUG" ] then set -x fi @@ -28,7 +28,7 @@ sqlite3|sqlite) esac echo "~~> Using $RAILSDB as the database engine" -if [ -n $SOLIDUS_BRANCH ] +if [ -n "$SOLIDUS_BRANCH" ] then BRANCH=$SOLIDUS_BRANCH else @@ -37,7 +37,7 @@ else fi echo "~~> Using branch $BRANCH of solidus" -if [ -z $SOLIDUS_FRONTEND ] +if [ -z "$SOLIDUS_FRONTEND" ] then echo "~~> Use 'export SOLIDUS_FRONTEND=[solidus_frontend|solidus_starter_frontend]' to control the Solidus frontend" SOLIDUS_FRONTEND="solidus_frontend" From 611a98f5ecc63d2ac237141b3993ba934a36e2b4 Mon Sep 17 00:00:00 2001 From: Ryan Woods Date: Wed, 9 Nov 2022 10:33:28 +0100 Subject: [PATCH 2/2] Refactor sandbox.tt -z string is null, that is, has zero length -n string is not null. Reference: - https://tldp.org/LDP/abs/html/comparison-ops.html --- .../templates/extension/bin/sandbox.tt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt index db779999..38a7d026 100755 --- a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt +++ b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -if [ ! -z "$DEBUG" ] +if [ -n "$DEBUG" ] then set -x fi @@ -28,14 +28,12 @@ sqlite3|sqlite) esac echo "~~> Using $RAILSDB as the database engine" -if [ -n "$SOLIDUS_BRANCH" ] +if [ -z "$SOLIDUS_BRANCH" ] then - BRANCH=$SOLIDUS_BRANCH -else echo "~~> Use 'export SOLIDUS_BRANCH=[master|v3.2|...]' to control the Solidus branch" - BRANCH="master" + SOLIDUS_BRANCH="master" fi -echo "~~> Using branch $BRANCH of solidus" +echo "~~> Using branch $SOLIDUS_BRANCH of solidus" if [ -z "$SOLIDUS_FRONTEND" ] then @@ -68,7 +66,7 @@ fi cd ./sandbox cat <> Gemfile -gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH' +gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH' gem 'rails-i18n' gem 'solidus_i18n'