[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 3/5] scripts/git-checkout.sh: add standard scripting safety steps



Date: Fri, 16 Oct 2026 19:11:11 -0700

Add doublequotes to all variable references.  This ensures building
doesn't fail if the full build directory has spaces in it.  Also move
the `set -e` to the front of the script.

Add a default value for $GIT.

Rename $TREE to $REPO.  These are generally called "repositories", the
checked out directory is a tree.

Signed-off-by: Elliott Mitchell <ehem+xen@xxxxxxx>
---
 scripts/git-checkout.sh | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/scripts/git-checkout.sh b/scripts/git-checkout.sh
index 56a60193a73..7dde6702b6c 100755
--- a/scripts/git-checkout.sh
+++ b/scripts/git-checkout.sh
@@ -1,28 +1,30 @@
 #!/bin/sh
 
+set -e
+
 if test $# -lt 3; then
-       echo "Usage: $0 <tree> <committish> <dir>"
+       echo "Usage: $0 <repo> <committish> <dir>"
        exit 1
 fi
 
-TREE=$1
-COMMITTISH=$2
-DIR=$3
+GIT="${GIT:-git}"
 
-set -e
+REPO="$1"
+COMMITTISH="$2"
+DIR="$3"
 
-if test \! -d $DIR-remote; then
-       rm -rf $DIR-remote $DIR-remote.tmp
-       mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp
-       $GIT clone $TREE $DIR-remote.tmp
+if test \! -d "$DIR-remote"; then
+       rm -rf "$DIR-remote" "$DIR-remote.tmp"
+       mkdir -p "$DIR-remote.tmp"; rmdir "$DIR-remote.tmp"
+       "$GIT" clone "$REPO" "$DIR-remote.tmp"
        if test "$COMMITTISH" ; then
-               cd $DIR-remote.tmp
-               $GIT fetch origin "$COMMITTISH"
-               $GIT branch -D dummy >/dev/null 2>&1 ||:
-               $GIT checkout -b dummy FETCH_HEAD
+               cd "$DIR-remote.tmp"
+               "$GIT" fetch origin "$COMMITTISH"
+               "$GIT" branch -D dummy >/dev/null 2>&1 ||:
+               "$GIT" checkout -b dummy FETCH_HEAD
                cd -
        fi
-       mv $DIR-remote.tmp $DIR-remote
+       mv "$DIR-remote.tmp" "$DIR-remote"
 fi
-rm -f $DIR
-ln -sf $(basename $DIR-remote) $DIR
+rm -f "$DIR"
+ln -sf $(basename "$DIR-remote") "$DIR"
-- 
2.47.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.