forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-cpush
executable file
·62 lines (52 loc) · 1.47 KB
/
git-cpush
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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