Skip to content

Instantly share code, notes, and snippets.

@kytulendu
Created September 23, 2018 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kytulendu/4bf32bf07537754dc0ddfde63099a45d to your computer and use it in GitHub Desktop.
Save kytulendu/4bf32bf07537754dc0ddfde63099a45d to your computer and use it in GitHub Desktop.
A shell script for update all git, hg and svn below current directory or specified directory.
#!/bin/bash
# Update all git, hg and svn directories below current directory or specified directory
# Skips directories that contain a file called .ignore
HIGHLIGHT="\e[01;34m"
NORMAL='\e[00m'
process_dir() {
local d="$1"
echo "Scanning:$1"
if [ -d "$d" ]; then
if [ -e "$d/.ignore" ]; then
echo -e "${HIGHLIGHT}Ignoring:$d${NORMAL}"
else
#echo "Entering: $d"
cd "$d" > /dev/null
if [ -d ".git" ]; then
echo -e "${HIGHLIGHT}Updating:`pwd`${NORMAL}"
# revert changes in working copy
git checkout .
git pull
else
if [ -d ".svn" ]; then
echo -e "${HIGHLIGHT}Updating:`pwd`${NORMAL}"
svn update
else
if [ -d ".hg" ]; then
echo -e "${HIGHLIGHT}Updating:`pwd`${NORMAL}"
hg pull
hg update
else
scan "${PWD}"
fi
fi
fi
cd .. > /dev/null
fi
fi
#echo "Exiting `pwd`"
}
function scan {
#echo "Current directory: `pwd`"
for x in "$1"/*; do
if [ -d "$x" ]; then
process_dir "$x"
fi
done
}
#clear
scan "${PWD}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment