Skip to content

Instantly share code, notes, and snippets.

@niqdev
Created March 16, 2019 11:34
Show Gist options
  • Save niqdev/14928a372548a47378dc4411dbb15cc5 to your computer and use it in GitHub Desktop.
Save niqdev/14928a372548a47378dc4411dbb15cc5 to your computer and use it in GitHub Desktop.
Update all git and mercurial repositories in a directory
#!/bin/bash
# unofficial bash strict mode
set -euo pipefail
IFS=$'\n\t'
# run from any directory (no symlink allowed)
CURRENT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)
cd ${CURRENT_PATH}
function update_mercurial {
local DIRECTORY=$1
if [ -d ".hg" ]; then
echo "[+] update MERCURIAL repository"
hg st
hg up default
hg pull -u
fi
}
function update_git {
local DIRECTORY=$1
if [ -d ".git" ]; then
echo "[+] update GIT repository"
git st
git checkout master
git pull --rebase
fi
}
function main {
for DIRECTORY in $(find . -mindepth 1 -maxdepth 1 -type d); do
echo "[*] scan $DIRECTORY"
cd $DIRECTORY
pwd
update_mercurial $DIRECTORY
update_git $DIRECTORY
cd ..
echo -e "[-] done\n"
sleep 1s
done
}
main
@niqdev
Copy link
Author

niqdev commented Apr 30, 2019

find . -name .git -type d -execdir pwd ';' -execdir git st ';'
find . -name .git -type d -exec sh -c "pwd; ls -la" \;
find . -name .git -type d -execdir pwd ';' -execdir git reset --hard origin/master ';' -execdir git pull --rebase ';'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment