diff --git a/git_00_checkout_branch.sh b/git_00_checkout_branch.sh deleted file mode 100755 index bb12f3e..0000000 --- a/git_00_checkout_branch.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/env bash - -git_current_branch() { - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' -} -CUR_BRANCH=`git_current_branch` - -CIBLE=$1 -if [ "$CIBLE" == "" ] -then - CIBLE=$CUR_BRANCH -fi - -git_01_quick_commit.sh - -if [ ! "$CIBLE" = "$CUR_BRANCH" ]; -then - git checkout $CIBLE - git pull -fi diff --git a/git_03_push_branch.sh b/git_03_push_branch.sh index aa4dae2..2eeb3f8 100755 --- a/git_03_push_branch.sh +++ b/git_03_push_branch.sh @@ -1,26 +1,21 @@ #!/bin/env bash -git_current_branch() { - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' -} -CUR_BRANCH=`git_current_branch` - CIBLE=$1 if [ "$CIBLE" == "" ] then - CIBLE=$CUR_BRANCH + CIBLE=$GIT_CURRENT_BRANCH fi git_01_quick_commit.sh -if [ ! "$CIBLE" = "$CUR_BRANCH" ]; +if [ ! "$CIBLE" = "$GIT_CURRENT_BRANCH" ]; then git_00_checkout_branch.sh $CIBLE fi git push all -if [ ! "$CIBLE" = "$CUR_BRANCH" ]; +if [ ! "$CIBLE" = "$GIT_CURRENT_BRANCH" ]; then - git_00_checkout_branch.sh $CUR_BRANCH + git_00_checkout_branch.sh $GIT_CURRENT_BRANCH fi diff --git a/git_05_delete_feature_branch.sh b/git_05_delete_feature_branch.sh index 1e63426..1c136cf 100755 --- a/git_05_delete_feature_branch.sh +++ b/git_05_delete_feature_branch.sh @@ -1,14 +1,9 @@ #!/bin/env bash -git_current_branch() { - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' -} -CUR_BRANCH=`git_current_branch` - CIBLE=$1 if [ "$CIBLE" == "" ] then - CIBLE=$CUR_BRANCH + CIBLE=$GIT_CURRENT_BRANCH fi internal_delete_branch() { @@ -27,7 +22,7 @@ delete_branch() { git_03_push_branch.sh -if [ ! "$CUR_BRANCH" = "develop" ] +if [ ! "$GIT_CURRENT_BRANCH" = "develop" ] then echo "La branche actuelle n'est pas develop" read -p "Voulez-vous basculer sur develop ? " -n 1 -r @@ -39,7 +34,7 @@ then fi case $CIBLE in - ($CUR_BRANCH) echo "Impossible : $CIBLE is current branch !";; + ($GIT_CURRENT_BRANCH) echo "Impossible : $CIBLE is current branch !";; ("evo"*) delete_branch $CIBLE;; ("ano"*) delete_branch $CIBLE;; (*) echo "$CIBLE is not a feature branch";; diff --git a/git_98_checkout.sh b/git_98_checkout.sh new file mode 100755 index 0000000..e336e94 --- /dev/null +++ b/git_98_checkout.sh @@ -0,0 +1,15 @@ +#!/bin/env bash + +CIBLE=$1 +if [ "$CIBLE" == "" ] +then + CIBLE=$GIT_CURRENT_BRANCH +fi + +git_01_quick_commit.sh + +if [ ! "$CIBLE" = "$GIT_CURRENT_BRANCH" ]; +then + git checkout $CIBLE + git pull +fi diff --git a/git_00_status.sh b/git_99_status.sh similarity index 72% rename from git_00_status.sh rename to git_99_status.sh index 7a8a80f..019707e 100755 --- a/git_00_status.sh +++ b/git_99_status.sh @@ -1,14 +1,9 @@ #!/bin/env bash -git_current_branch() { - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' -} -CUR_BRANCH=`git_current_branch` - TEST=`git status | grep propre | wc -l` if [ $TEST -eq 0 ] then - echo "La branche actuelle ($CUR_BRANCH) n'est pas propre" + echo "La branche actuelle ($GIT_CURRENT_BRANCH) n'est pas propre" echo # (optional) move to a new line read -p "Voulez-vous voir les modifications courantes ? " -n 1 -r diff --git a/mygitflow b/mygitflow index df719ae..8da42e3 100755 --- a/mygitflow +++ b/mygitflow @@ -1,9 +1,14 @@ #!/bin/env bash +git_parse_branches() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' +} + git_current_branch() { - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' + export GIT_CURRENT_BRANCH="$(git_parse_branches)" } -export CUR_BRANCH=`git_current_branch`o + +git_current_branch usage(){ echo @@ -22,8 +27,8 @@ GITCMD=$1 shift case $GITCMD in - ("checkout") git_00_checkout_branch.sh $@;; - ("status") git_00_status.sh $@;; + ("checkout") git_98_checkout_branch.sh $@;; + ("status") git_99_status.sh $@;; ("commit") git_01_quick_commit.sh $@;; ("add") git_02_add_branch.sh $@;; ("push") git_03_push_branch.sh $@;;