]> source.dussan.org Git - sonarqube.git/commitdiff
use a private repo before building in generate_batch_reports.sh
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 2 Jul 2015 13:03:00 +0000 (15:03 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 2 Jul 2015 14:14:34 +0000 (16:14 +0200)
scripts/generate_batch_reports.sh

index 227d734b923418d80dd6689724ce2b3ba4670cf0..605839fc895f30f4620589c3db0de6ad0b10d992 100755 (executable)
 
 set -euo pipefail
 
+function clean() {
+  rm -Rf $BUILD_DIR
+}
+
+function createPrivateClone() {
+  BRANCH=$(git symbolic-ref -q HEAD)
+  BRANCH=${BRANCH##refs/heads/}
+  BRANCH=${BRANCH:-HEAD}
+  LOCATION=$(pwd)
+  REPO_DIR=$(git rev-parse --show-toplevel)
+  REPO_NAME=${REPO_DIR##*/}
+  RELATIVE_PATH=${LOCATION#$REPO_DIR}
+
+  # create temp directory and register trap to clean it on exit
+  BUILD_DIR=$(mktemp -d -t ${REPO_NAME}.XXXXXXXX 2>/dev/null)
+  trap "clean" INT TERM EXIT
+
+  # Private build
+  cd $REPO_DIR
+  git clone --single-branch -slb "${BRANCH}" . ${BUILD_DIR}
+  cd ${BUILD_DIR}${RELATIVE_PATH}
+}
+
 DUMP_DIR="/tmp/batch_dumps"
 HISTORY_LENGTH=30
 SONAR_HOST="http://localhost:9000"
@@ -25,20 +48,11 @@ SONAR_JDBC_URL="jdbc:postgresql://localhost:5432/sonar"
 SONAR_JDBC_USERNAME="sonar"
 SONAR_JDBC_PASSWORD="sonar"
 
-function clean() {
-  git co $branch_name
-  git branch -D working_branch
-}
-
-trap "clean" EXIT
+createPrivateClone
 
 # retrieve ${HISTORY_LENGTH} commits for the current directory
 git log -${HISTORY_LENGTH} --pretty=%h -- . | tac > /tmp/sha1s.txt
 
-branch_name=$(git symbolic-ref -q HEAD)
-branch_name=${branch_name##refs/heads/}
-branch_name=${branch_name:-HEAD}
-
 git co -b working_branch 
 while read sha1; do
   echo $sha1