Skip to content

Commit 854b694

Browse files
In case of CLONE_DIR already exists and not a git repository, clean it
1 parent 93a4a17 commit 854b694

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

start.sh

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,44 @@ if [ -d "$CLONE_DIR" ]; then
5353
echo "Preparing to update $REPO"
5454
cd $CLONE_DIR
5555

56-
# Reset the remote URL because the embedded user token may have changed
57-
git remote set-url origin $REPO
56+
# Make sure the CLONE_DIR folder is a git folder
57+
if git status &> /dev/null ; then
58+
# Reset the remote URL because the embedded user token may have changed
59+
git remote set-url origin $REPO
5860

59-
echo "Cleaning up the working directory"
60-
git reset -q --hard
61-
git clean -df
62-
git gc
63-
git_retry git remote prune origin
61+
echo "Cleaning up the working directory"
62+
git reset -q --hard
63+
git clean -df
64+
git gc
65+
git_retry git remote prune origin
6466

65-
echo "Fetching the updates from origin"
66-
git_retry git fetch --tags
67+
echo "Fetching the updates from origin"
68+
git_retry git fetch --tags
6769

68-
if [ -n "$REVISION" ]; then
70+
if [ -n "$REVISION" ]; then
6971

70-
echo "Updating $REPO to revision $REVISION"
71-
git checkout $REVISION
72+
echo "Updating $REPO to revision $REVISION"
73+
git checkout $REVISION
7274

73-
CURRENT_BRANCH="`git branch 2>/dev/null | grep '^*' | cut -d' ' -f2-`"
75+
CURRENT_BRANCH="`git branch 2>/dev/null | grep '^*' | cut -d' ' -f2-`"
7476

75-
# If the revision is identical to the current branch we can rebase it with the latest changes. This isn't needed when running detached
76-
if [ "$REVISION" == "$CURRENT_BRANCH" ]; then
77-
echo 'Rebasing current branch $REVISION to latest changes...'
78-
git rebase
77+
# If the revision is identical to the current branch we can rebase it with the latest changes. This isn't needed when running detached
78+
if [ "$REVISION" == "$CURRENT_BRANCH" ]; then
79+
echo 'Rebasing current branch $REVISION to latest changes...'
80+
git rebase
81+
fi
82+
fi
83+
else
84+
# The folder already exists but it is not a git repository
85+
# Clean folder and clone a fresh copy on current directory
86+
cd ..
87+
rm -rf $CLONE_DIR
88+
echo "cloning $REPO"
89+
git_retry git clone $REPO $CLONE_DIR
90+
cd $CLONE_DIR
91+
92+
if [ -n "$REVISION" ]; then
93+
git checkout $REVISION
7994
fi
8095
fi
8196
else

0 commit comments

Comments
 (0)