From: Silvio Rhatto Date: Wed, 19 Jun 2024 12:07:28 +0000 (-0300) Subject: Feat: adds git-clone-or-pull X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=3106b52eeb9cb8ded2497bf6611355b1f1bf4c87;p=utils-git.git Feat: adds git-clone-or-pull --- diff --git a/git-clone-or-pull b/git-clone-or-pull new file mode 100755 index 0000000..f2575c2 --- /dev/null +++ b/git-clone-or-pull @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Handy single command to clone or pull a repository +# + +# Parameters +BASENAME="`basename $0`" +ORIGIN="$1" +DEST="$2" + +# Check +if [ -z "$DEST" ]; then + echo "usage: $BASENAME " + exit 1 +fi + +# Dispatch +if [ ! -e "$DEST" ]; then + echo "Cloning $ORIGIN into $DEST..." + git clone $ORIGIN $DEST +else + echo "Updating $DEST..." + git -C $DEST pull + + # Alternate approach, that restore any existing changes + #( + # cd $DEST &> /dev/null + # git restore . + # git pull + #) +fi + +# Exit +exit $?