Skip to content

Commit

Permalink
Merge pull request #9 from zondor/master
Browse files Browse the repository at this point in the history
git branch restore script
  • Loading branch information
Gundars committed Mar 13, 2015
2 parents 96b09ea + 8a0ed76 commit 421446c
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
71 changes: 71 additions & 0 deletions git-branch-restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
# Restore mising test and development branches in repos founded in dirs
# Syntax: $ <>.sh {dir1} [{dir2} {dir3}...

CNORMAL='\e[00m'
CHIGHLIGHT="\e[01;36m"
CERROR='\033[31m'
CSUCCESS='\e[32m'
ERRMASCOT=' __\n / _)\n .-^^^-/ /\n __/ /\n<__.|_|-|_|';
ERRCOUNT=0

if [ $# -lt 1 ]; then
echo -e "\n${CERROR}${ERRMASCOT}\nERROR: Incorrect arguments specified${CNORMAL}"
echo "Usage: gcobranch [branch] [dir] [dir]..."
exit 0
fi

directories="${@:1}";
echo $directories

for dir in $directories do
if [ -d "$dir" ]; then
cd $dir>/dev/null;
echo -e "Scanning ${PWD}";
cd ->/dev/null

for d in `find $dir -name .git -type d`; do
cd $d/.. > /dev/null
echo -e "\n${CHIGHLIGHT}Repo: `pwd`$CNORMAL"
CURRENT=`git rev-parse --abbrev-ref HEAD`;
git checkout master
git fetch --all

TESTBR=`git branch | grep "test" | tr -d '* '`
DEVBR=`git branch | grep "development" | tr -d '* '`

RTESTBR=`git branch -r | grep -w 'origin/test' | tr -d " origin/"`
RDEVBR=`git branch -r | grep -w 'origin/development' | tr -d " origin/"`

echo -e "===Current branch$CNORMAL: ${CURRENT}"
echo -e "===Test: (${TESTBR}) on remote (${RTESTBR})"
echo -e "===Dev : (${DEVBR}) on remote (${RDEVBR})"

if [[ "${RTESTBR}" != "" ]]; then
if [[ "${TESTBR}" != 'test' ]]; then
echo -e "Creating local Test"
git checkout -b test origin/test
fi
fi

if [[ "${RDEVBR}" != "" ]]; then
if [[ "${DEVBR}" != 'development' ]]; then
echo -e "Creating local Development"
git checkout -b development origin/development
fi
fi

cd - > /dev/null
done
else
echo -e "\n${CERROR}${ERRMASCOT}\nERROR: Directory $dir does not exist ${CNORMAL}"
fi
done

if [[ "${ERRCOUNT}" == "0" ]] ; then
finalcol=${CSUCCESS}
else
finalcol=${CERROR}
fi

echo -e "\n${finalcol}Done with ${ERRCOUNT} errors${CNORMAL}"
44 changes: 44 additions & 0 deletions git-check-changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Checks out and pulls specified {branch} in all git repos found in each of specified {dir}
# Syntax: $ gcobranch.sh {branch} {dir1} [{dir2} {dir3}...]

CNORMAL='\e[00m'
CHIGHLIGHT="\e[01;36m"
CERROR='\033[31m'
CSUCCESS='\e[32m'
ERRMASCOT=' __\n / _)\n .-^^^-/ /\n __/ /\n<__.|_|-|_|';
ERRCOUNT=0
CHANGPENDING=''
# ERRCOUNT=$[ERRCOUNT + 1]
if [ $# -lt 1 ]
then
echo -e "\n${CERROR}${ERRMASCOT}\nERROR: Incorrect arguments specified${CNORMAL}"
echo "Usage: git-check-status [dir] [dir]..."
exit 0
fi

directories="${@:1}";

for dir in $directories
do
if [ -d "$dir" ]; then
cd $dir>/dev/null;
echo -e "Scanning ${PWD}";
cd ->/dev/null

for d in `find $dir -name .git -type d`; do
cd $d/.. > /dev/null
CHANGE=`git status --porcelain`

if [ -n "$CHANGE" ]; then
PWD=`pwd `
echo -e "\n${CHIGHLIGHT}${PWD}"
echo -e "\n${CERROR}${CHANGE}"

fi
cd - > /dev/null
done
else
echo -e "\n${CERROR}${ERRMASCOT}\nERROR: Directory $dir does not exist ${CNORMAL}"
fi
done
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ INSTDIR=~/.bashscripts
SYMLINKDIR=/usr/local/bin
cd $INSTDIR
git pull origin master
SCRIPTS=(gcobranch gitmerge guorigin buildenv gitpress)
SCRIPTS=(gcobranch gitmerge guorigin buildenv gitpress git-branch-restore git-check-changes)
for SCRIPT in ${SCRIPTS[@]}
do
if [ ! -f ${SYMLINKDIR}/${SCRIPT} ]; then
Expand Down

0 comments on commit 421446c

Please sign in to comment.