From 1b28a4bf6e02e6cc73c4f6e34da72e42e1dfbcb0 Mon Sep 17 00:00:00 2001
From: ATLAS Robot <atlas.robot@cern.ch>
Date: Wed, 8 Feb 2017 09:48:44 +0100
Subject: [PATCH] handle already existing source directories

The build scripts were failing when executed twice with the same
build directory. Re-using previous builds is essential for
incremental builds.


Former-commit-id: 534656e776627b272db19ed50903356cc1e2f676
---
 Build/AtlasBuildScripts/checkout_Gaudi.sh          |  9 +++++++--
 Build/AtlasBuildScripts/checkout_atlasexternals.sh | 11 ++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/Build/AtlasBuildScripts/checkout_Gaudi.sh b/Build/AtlasBuildScripts/checkout_Gaudi.sh
index 8d89cc12a44..fcadbd9ddd1 100755
--- a/Build/AtlasBuildScripts/checkout_Gaudi.sh
+++ b/Build/AtlasBuildScripts/checkout_Gaudi.sh
@@ -62,12 +62,17 @@ if [ "$HASHFILE" != "" ]; then
     echo "Writing the commit hash into file: $HASHFILE"
 fi
 
-# Clone the repository:
-git clone https://gitlab.cern.ch/atlas/Gaudi.git \
+if [ ! -d "${SOURCEDIR}" ]; then
+    # Clone the repository:
+    git clone https://gitlab.cern.ch/atlas/Gaudi.git \
     ${SOURCEDIR}
+else
+    echo "${SOURCEDIR} already exists -> assume previous checkout"
+fi
 
 # Get the appropriate tag of it:
 cd ${SOURCEDIR}
+git fetch origin
 git checkout ${TAGBRANCH}
 
 # If an output file was not specified, stop here:
diff --git a/Build/AtlasBuildScripts/checkout_atlasexternals.sh b/Build/AtlasBuildScripts/checkout_atlasexternals.sh
index ebf07cbc34c..219215043db 100755
--- a/Build/AtlasBuildScripts/checkout_atlasexternals.sh
+++ b/Build/AtlasBuildScripts/checkout_atlasexternals.sh
@@ -67,11 +67,16 @@ if [ "$HASHFILE" != "" ]; then
     echo "Writing the commit hash into file: $HASHFILE"
 fi
 
-# Clone the repository:
-git clone ${EXTERNALSURL} ${SOURCEDIR}
+if [ ! -d "${SOURCEDIR}" ]; then
+    # Clone the repository:
+    git clone ${EXTERNALSURL} ${SOURCEDIR}
+else
+    echo "${SOURCEDIR} already exists -> assume previous checkout"
+fi
 
 # Get the appropriate tag of it:
 cd ${SOURCEDIR}
+git fetch origin
 git checkout ${TAGBRANCH}
 
 # If an output file was not specified, stop here:
@@ -81,4 +86,4 @@ fi
 
 # Write the hash of whatever we have checked out currently, into the
 # specified output file:
-git rev-parse ${TAGBRANCH} > ${HASHFILE}
\ No newline at end of file
+git rev-parse ${TAGBRANCH} > ${HASHFILE}
-- 
GitLab