Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa68de5c authored by Amit Kumar's avatar Amit Kumar
Browse files

Add sanitation check for working tree

parent bb3f7917
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ NOCOLOR="\033[0m"

QUESTION_FLAG="${GREEN}?"
NOTICE_FLAG="${CYAN}❯"
WARNING_FLAG="${YELLOW}!"
ERROR_FLAG="${RED}\U25CF"

BUMPING_MSG="${NOTICE_FLAG} Bumping up version...${NOCOLOR}"
@@ -145,6 +146,11 @@ do_version_upgrade() {
# It must check for dev or hotfix* branch and bump the version only when current branch is dev or hotfix.
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
if [[ ${branch} = "dev" ]] || [[ ${branch} = hotfix* ]]; then
    git diff-index --quiet HEAD
    if [[ $? == 1 ]] ; then
        echo -e "${WARNING_FLAG} Working tree must be empty before bumping the version."
        exit 1
    fi
    do_version_upgrade $1
else
    echo -e "${ERROR_FLAG} Can only be used on dev or hotfix branch."
+21 −1
Original line number Diff line number Diff line
@@ -2,8 +2,29 @@

# It must check for master branch and tag only if current branch is master.

YELLOW="\033[1;33m"

WARNING_FLAG=${YELLOW}!
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')

if [[ ${branch} = "master" ]]; then

    # Check if your working tree is cleaned or not.
    git diff-index --quiet HEAD
    if [[ $? == 1 ]] ; then
        echo -e "${WARNING_FLAG} Working tree must be empty before tagging the version."
        exit 1
    fi

    # Check if your current source is not already tagged by using current hash
    GIT_COMMIT=`git rev-parse HEAD`
    NEEDS_TAG=`git describe --contains ${GIT_COMMIT}`
    # Only tag if no tag already (would be better if the git describe command above could have a silent option)
    if [[ -n "$NEEDS_TAG" ]]; then
        echo -e "${WARNING_FLAG} Latest commit is already tagged. Aborting now..."
        exit 0
    fi

    major=$((`cat app/build.gradle | grep "versionMajor = " | awk '{print $4}'`))
    minor=$((`cat app/build.gradle | grep "versionMinor = " | awk '{print $4}'`))
    patch=$((`cat app/build.gradle | grep "versionPatch = " | awk '{print $4}'`))
@@ -14,7 +35,6 @@ if [[ ${branch} = "master" ]]; then
    read -r -p "" response
    response=${response,,}
    if [[ ${response} =~ ^(yes|y| ) ]] || [[ -z ${response} ]]; then
        branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
        git push origin --tags
    else
        exit 1