Create and delete feature branch from dev

Home   »   Create and delete feature branch from dev

# Create new feature branch from sd-unity-4-0 dev branch

function createBranchFromDev()
{
  if [ "$1" ]; then

    printf "\n\rCreating feature core branch: sd-feature-core-$1-1 from \"dev\" branch\n\r"
    eval "git checkout dev"
    eval "git pull"
    eval "git checkout -b sd-feature-core-$1-1 dev"
    eval "git push --set-upstream origin sd-feature-core-$1-1"
    printf "\n\rSuccess! Created feature core branch: sd-feature-core-$1-1 from \"dev\" branch\n\r"
  else

    echo "Error in creating the feature branch please try again..."

  fi
}

alias feature=createBranchFromDev

# Delete a feature branch from sd-unity-4-0
# It does ask for confirmation before permanent deletion

function deleteFeature(){

    if [ "$1" ]; then

      # Ask for branch deletion confirmation
      echo #space
      echo -ne $(alert "- Are you sure you want to PERMANENTLY DELETE the feature core branch: \"sd-feature-core-$1-1\" ? (y,yes or n,no): ")

      read yesorno

      if [ "$yesorno" = yes ] || [ "$yesorno" = y ] ; then

        echo #space
        # Can't delete a branch while you are actively on it, so need to switch on dev
        eval "git checkout dev"
        # Delete branch locally
        eval "git branch -d sd-feature-core-$1-1"
        # Delete branch from remote
        eval "git push --delete origin sd-feature-core-$1-1"
        # Need git fetch to update branch deletion
        eval "git fetch -p"
        # Try to checkout deleted branch, should return a pathspec error if branch was deleted
        printf "\n\r If git return  a pathspec error below, it means the feature branch as been deleted correctly.\n\r"
        eval "git checkout sd-feature-core-$1-1"

      elif [ "$yesorno" = no ] || [ "$yesorno" = n ] ; then

        printf "\n\rFeature core branch: \"sd-feature-core-$1-1\" was NOT DELETED\n\r"
        printf "\n\rScript will now exit...\n\r"

      else

        printf "\n\rNo vailid answer, script will now exit...\n\r"

      fi

    else

        printf "\n\rYou need to pass a feature branch number.\n\r"
        printf "\n\rEx: \"deleteFeature 55432\" witch will be converted to \"sd-feature-core-55432-1\"\n\r"
        printf "\n\rScript will now exit...\n\r"

    fi
}

Leave a Reply

Your email address will not be published. Required fields are marked *