Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
fix: shell tools pass over branches
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybatch committed Apr 7, 2023
1 parent a108b70 commit a0e3b8c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ mint-md5sum
search
skype

.idea
92 changes: 46 additions & 46 deletions branches
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Search the file system down from the specified path looking for git repos.
Expand All @@ -15,32 +15,33 @@ and the path to the repo.
Optional a new named branch can be created and checkout out/pulled.
-f Fetch origin
-p Plain out put, supress colours. Use to create a changelog entry.
-p Plain out put, suppress colours. Use to create a changelog entry.
-l Show latest tag. If colours are enabled then tag that have different
content to the current branch are coloured red.
-b branch
If specified and the remote branch exists then a the branch is checked out
and pulled. Existing changes will be stashed, and then applied.
-m nakefile
-m makefile
Attempt to check the branch/tag specified in this make file for each repo
found. Overrides -b and implies -f
EOF
}

while getopts "b:lm:pfh" options; do
case $options in
b) newbranch="$OPTARG";;
l) latesttag=1;;
p) plainoutput=1;;
f) fetchorigin=1;;
b) new_branch="$OPTARG";;
l) latest_tag=1;;
p) plain_output=1;;
f) fetch_origin=1;;
m) makefile="$OPTARG";;
h) usage; exit;;
*) echo "unknown option";;
esac
done

shift $((OPTIND-1))

if [ -z "$plainoutput" ]; then
if [ -z "$plain_output" ]; then
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
Expand All @@ -51,66 +52,65 @@ if [ -z "$plainoutput" ]; then
COL_CYAN=$ESC_SEQ"36;01m"
fi

if [ ! -z "$latesttag" ]; then
if [ -n "$latest_tag" ]; then
printf "${COL_GREEN}%-20s %-25s %-10s %s${COL_RESET}\n" Name Branch Tag Path
else
printf "${COL_GREEN}%-20s %-25s %s${COL_RESET}\n" Name Branch Path
fi

EXITSTATE=0
if [ ! -z "$@" ]; then
ROOTPATH=$@
EXIT_STATE=0
if [ -n "$1" ]; then
ROOT_PATH=$1
else
ROOTPATH=`pwd`
ROOT_PATH=$(pwd)
fi

for var in "$ROOTPATH"; do
if [ -d $var ]; then
for x in `find $var/* -name .git | grep -v vendor`; do
dir=`dirname $x`
name=`basename $dir`
clean_dir=${dir#$ROOTPATH/}
for var in $ROOT_PATH; do
if [ -d "$var" ]; then
for x in $(find "$var"/* -name .git | grep -v vendor); do
dir=$(dirname "$x")
name=$(basename "$dir")
clean_dir=${dir#$ROOT_PATH/}
if [ "$name" == "tabs-api-client" ] || [ "$name" == "contrib" ]; then
continue
fi
GITCMD="git -C `dirname $x`"
GIT_CMD="git -C $(dirname "$x")"
# Fetch latest
if [ ! -z "$fetchorigin" ] || [ ! -z "$makefile" ]; then
$GITCMD fetch origin > /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

0 comments on commit a0e3b8c

Please sign in to comment.