From e4f34eced903eff582f2cf2b740cc690caa392a6 Mon Sep 17 00:00:00 2001 From: sbimochan Date: Fri, 11 Jan 2019 23:11:41 +0545 Subject: [PATCH 1/3] Enhancing... Color echo and code cleanups --- commit | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/commit b/commit index 3a4aeec..1201af7 100755 --- a/commit +++ b/commit @@ -1,26 +1,35 @@ #!/usr/bin/env bash +set -euo pipefail -echo 'Running commit script' - -IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging") +IS_IGNORED=false IGNORED_PATH="./.ignore" +CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" +IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging") + +colorEcho(){ + RED="\033[0;31m" + GREEN='\033[0;32m' + YELLOW='\033[1;33m' + NO_COLOR='\033[0m' + printf "${!1}${2} ${NO_COLOR}\n" +} -if [ -f "$IGNORED_PATH" ] +commitWithBranch() { + colorEcho "GREEN" "Commit translation: \"$CURRENT_BRANCH: $1\"" + git commit -m "$CURRENT_BRANCH: $1" +} + +if [[ -f "$IGNORED_PATH" ]] then CUSTOM_BRANCHES=$(cat "$IGNORED_PATH") BRANCHES=( $CUSTOM_BRANCHES ) IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} ) -fi - -CURRENT_BRANCH_CMD="git rev-parse --abbrev-ref HEAD" -CURRENT_BRANCH=$(eval $CURRENT_BRANCH_CMD) - -COMMIT_WITH_BRANCH="git commit -m \"$CURRENT_BRANCH: $1\"" -DEFAULT_COMMIT="git commit -m \"$1\"" + colorEcho "YELLOW" ".ignore file found. Skimming off from .ignore file" +else + colorEcho "YELLOW" ".ignore file not found" +fi -IS_IGNORED=false - -for branch in "${IGNORED_BRANCHES[@]}"; +for branch in "${IGNORED_BRANCHES[@]}" do if [ "$CURRENT_BRANCH" == $branch ] then @@ -29,11 +38,11 @@ for branch in "${IGNORED_BRANCHES[@]}"; fi done + if [ "$IS_IGNORED" == false ] then - echo "Commiting with branch name -> $CURRENT_BRANCH" - eval $COMMIT_WITH_BRANCH + commitWithBranch $1 else - echo "Commiting with default branch" - eval $DEFAULT_COMMIT + colorEcho "GREEN" "Commit translation: \"$1\"" + git commit -m "$1" fi From 3f34458ca14c451db5bb9799a19315c018b8c81d Mon Sep 17 00:00:00 2001 From: sbimochan Date: Sat, 12 Jan 2019 13:34:12 +0545 Subject: [PATCH 2/3] enhancement: Change --- commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commit b/commit index 1201af7..afc0f21 100755 --- a/commit +++ b/commit @@ -24,7 +24,7 @@ then CUSTOM_BRANCHES=$(cat "$IGNORED_PATH") BRANCHES=( $CUSTOM_BRANCHES ) IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} ) - colorEcho "YELLOW" ".ignore file found. Skimming off from .ignore file" + colorEcho "YELLOW" "Excluding branches from .ignore file" else colorEcho "YELLOW" ".ignore file not found" fi From c92d40aeb8d4bcafa50735c90e3d1f0fe936a9c3 Mon Sep 17 00:00:00 2001 From: sbimochan Date: Sat, 12 Jan 2019 14:54:54 +0545 Subject: [PATCH 3/3] enhancement: Improve --- commit | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commit b/commit index afc0f21..51cd027 100755 --- a/commit +++ b/commit @@ -16,6 +16,7 @@ colorEcho(){ commitWithBranch() { colorEcho "GREEN" "Commit translation: \"$CURRENT_BRANCH: $1\"" + # Edit your config here git commit -m "$CURRENT_BRANCH: $1" } @@ -24,9 +25,9 @@ then CUSTOM_BRANCHES=$(cat "$IGNORED_PATH") BRANCHES=( $CUSTOM_BRANCHES ) IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} ) - colorEcho "YELLOW" "Excluding branches from .ignore file" + colorEcho "YELLOW" "Excluding branches from .ignore file." else - colorEcho "YELLOW" ".ignore file not found" + colorEcho "YELLOW" ".ignore file not found, excluding default branches." fi for branch in "${IGNORED_BRANCHES[@]}"