Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created January 16, 2014 08:32
Show Gist options
  • Save chmouel/8451585 to your computer and use it in GitHub Desktop.
Save chmouel/8451585 to your computer and use it in GitHub Desktop.
git pull my git repo fetching only if it's inside a local change.
#!/bin/zsh
set -e
if [[ $1 == "-c" ]];then
clean=yes
shift
fi
if [[ -z $@ ]];then
DIRS=( /opt/stack /opt/stack/GIT )
else
DIRS=$@
fi
typeset -A notprocessed
autoload -U colors
for dir in ${DIRS};do
cd ${dir}
for gitdir in *(/);do
[[ -d ${gitdir}/.git/ ]] || continue
pushd ${gitdir}/$d >/dev/null;
branch=${${"$(<.git/HEAD)"#ref: }#refs/heads/}
[[ ${branch} == master ]] && cmd="pull" || {
cmd="fetch"
notprocessed[$gitdir]=$branch
}
for f in $(git status --porcelain|sed -n '/requirements.txt/ { s/.* //;p; }');do
git checkout -- ${f}
done
git ${cmd} origin master
popd >/dev/null
done
done
[[ -z ${notprocessed} ]] && exit
echo $fg[red]Not updated on master only fetch$fg[default]
for k in ${(k)notprocessed};do
echo $k : $notprocessed[$k]
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment