Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9dfa319180
Fetching contributors…

Cannot retrieve contributors at this time

executable file 63 lines (52 sloc) 1.509 kb
#!/bin/bash -e
## Do a conditional push: only push, if remotes are behind
## otherwise accept the same arguments as push
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Push only if necessary
This command is similar to git-push, but only executes the push
if necessary.
Before pushing, the submodules are pushed.
Usage:
git cpush ...
...: same arguments as git-push
EOF
exit 0;
fi
## from the git mailinglist:
function git
{
LC_MESSAGES=C command git "$@"
}
export git
## push submodules first
if [ -f $(git rev-parse --show-toplevel)/.gitmodules ]; then
CMD='cd "$1"; git cpush '"$@"
#git submodule --quiet foreach git cpush "$@" || exit 1
git submodule --quiet foreach 'echo "$toplevel/$path"' |
xargs -r -n1 -P5 bash -c "$CMD" xargs || exit 1
fi
tmp=`git branch --no-color -vv 2> /dev/null`
while read line; do
if [[ "${line:0:1}" != "*" ]]; then
continue
fi
##echo "$line"
branch=`expr "$line" : '\** *\([^ ]*\)'`
##echo "$branch"
remote=`expr "$line" : '.*\[\(.*\)\]'` || continue
##echo "$remote"
## if we're ahead: branch will show it after ":"
status=`expr "$remote" : '.*: ahead \(.*\)'` || continue
##echo "$status"
unpushed=" Branch \"$branch\" is ahead by $status commit(s)."
done <<< "$tmp"
## push also if --tags argument is given
if [[ "$@" == *--tags* ]]; then
unpushed="Push tags"
fi
if [ "$unpushed" ]; then
echo "Pushing $PWD."
git push "$@"
fi
Jump to Line
Something went wrong with that request. Please try again.