From a0e3b8c2832b802bac248ea6ea337e0d2ed3c079 Mon Sep 17 00:00:00 2001 From: Tobias Batch Date: Fri, 7 Apr 2023 18:18:12 +0100 Subject: [PATCH] fix: shell tools pass over branches --- .gitignore | 1 + branches | 92 +++++++++++++++++++++++++++--------------------------- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index 55347fd..596ab23 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ mint-md5sum search skype +.idea diff --git a/branches b/branches index 436c937..5a7d912 100755 --- a/branches +++ b/branches @@ -1,11 +1,11 @@ #!/bin/bash NO_ARGS=0 -USAGE="`basename $0` [-f] [-l [-a]] [-p] [-b branch] path/to/drupal" -EXITSTATE=0 +USAGE="$(basename "$0") [-f] [-l [-a]] [-p] [-b branch] path/to/repos" +EXIT_STATE=0 function usage { - echo $USAGE + echo "$USAGE" cat < /dev/null + if [ -n "$fetch_origin" ] || [ -n "$makefile" ]; then + $GIT_CMD fetch origin > /dev/null fi - branch=`$GITCMD branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | tr -d "()"` - if [ ! -z "$latesttag" ]; then - lt=`$GITCMD describe --abbrev=0 --tags 2> /dev/null` - diff=`$GITCMD diff refs/heads/${branch}..refs/tags/${lt} 2> /dev/null` - if [ ! -z "$diff" ]; then - printf "$COL_MAGENTA%-20s$COL_RESET %-25s $COL_RED%-10s$COL_RESET %s\n" $name "$branch" $lt $clean_dir + branch=$($GIT_CMD branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | tr -d "()") + if [ -n "$latest_tag" ]; then + lt=$($GIT_CMD describe --abbrev=0 --tags 2> /dev/null) + diff=$($GIT_CMD diff refs/heads/"$branch"..refs/tags/"$lt" 2> /dev/null) + if [ -n "$diff" ]; then + printf "$COL_MAGENTA%-20s$COL_RESET %-25s $COL_RED%-10s$COL_RESET %s\n" "$name" "$branch" "$lt" "$clean_dir" else - printf "$COL_CYAN%-20s$COL_RESET %-25s %-10s %s\n" $name "$branch" $lt $clean_dir + printf "$COL_CYAN%-20s$COL_RESET %-25s %-10s %s\n" "$name" "$branch" "$lt" "$clean_dir" fi else - printf "%-25s %-20s %s\n" $name $branch $clean_dir + printf "%-25s %-20s %s\n" "$name" "$branch" "$clean_dir" fi - if [ ! -z "$makefile" ]; then - # grep 'ntbr_theme2]\[download]\[tag' ~/workspace/cottaging/ntdr-pas/files/br.make | awk '{print $3}' - tag=`grep "$name]\[download]\[tag" $makefile | awk '{print $3}'` + if [ -n "$makefile" ]; then + tag=$(grep "$name]\[download]\[tag" "$makefile" | awk '{print $3}') echo - echo $tag + echo "$tag" echo - newbranch=$tag + new_branch=$tag fi - if [ ! -z "$newbranch" ]; then + if [ ! -z "$new_branch" ]; then # The --git-dir doesn't work in this case - $GITCMD stash - $GITCMD fetch origin --tags - # $GITCMD show-branch $newbranch > /dev/null - $GITCMD show-branch $newbranch - if [ "$?" == 0 ]; then - $GITCMD checkout $newbranch - $GITCMD pull origin $newbranch + $GIT_CMD stash + $GIT_CMD fetch origin --tags + # $GIT_CMD show-branch $new_branch > /dev/null + $GIT_CMD show-branch "$new_branch" + if [ $GIT_CMD show-branch "$new_branch" ]; then + $GIT_CMD checkout "$new_branch" + $GIT_CMD pull origin "$new_branch" fi fi done fi done -exit $EXITSTATE +exit $EXIT_STATE