]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-build.git/commitdiff
scripts: create a branch filtering for slashes
authorAlfredo Deza <adeza@redhat.com>
Fri, 9 Sep 2016 18:54:12 +0000 (14:54 -0400)
committerAlfredo Deza <adeza@redhat.com>
Fri, 9 Sep 2016 18:56:56 +0000 (14:56 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
scripts/build_utils.sh

index 147a9af89fcb10c205b966bcf71cc84572607060..75108391f376efe604dfe544997e8fc060c48e3d 100644 (file)
@@ -5,6 +5,24 @@ set -ex
 TEMPVENV=$(mktemp -td venv.XXXXXXXXXX)
 VENV="$TEMPVENV/bin"
 
+branch_slash_filter() {
+    # The build system relies on an HTTP binary store that uses branches/refs
+    # as URL parts.  A literal extra slash in the branch name is considered
+    # illegal, so this function performs a check *and* prunes the common
+    # `origin/branch-name` scenario (which is OK to have).
+    RAW_BRANCH=$1
+    branch_slashes=$(grep -o "/" <<< ${RAW_BRANCH} | wc -l)
+    FILTERED_BRANCH=`echo ${RAW_BRANCH} | rev | cut -d '/' -f 1 | rev`
+
+    # Prevent building branches that have slashes in their name
+    if [ "$((branch_slashes))" -gt 1 ] ; then
+        echo "Will refuse to build branch: ${RAW_BRANCH}"
+        echo "Invalid branch name (contains slashes): ${FILTERED_BRANCH}"
+        exit 1
+    fi
+    echo $FILTERED_BRANCH
+}
+
 install_python_packages () {
     # Use this function to create a virtualenv and install
     # python packages. Pass a list of package names.