]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - bin/git-update.sh
*: License under GPL v3+.
[config/dotfiles.git] / bin / git-update.sh
1 #!/bin/sh
2
3 # Push current commits to all remotes and fetch from all remotes. Then display
4 # unmerged commits and changes in the repositories.
5 #
6 # If --local is given as option, no fetching/pushing is performed.
7 #
8 # If an argument is given cd to this directory before running the commands.
9 #
10 # Very useful to sync multiple remotes.
11
12 # Copyright (C) 2011-2012  Simon Ruderich
13 #
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27
28 LOCAL=
29 if [ x$1 = x--local ];then
30     LOCAL=1
31     shift
32 fi
33
34 if [ x$1 != x ]; then
35     echo $1
36     cd "$1"
37 fi
38
39 if [ x$LOCAL = x ]; then
40     # Get all remote changes.
41     git remote update 2>&1 | grep -v Fetching
42     # Push all local changes to remote(s).
43     for remote in `git remote`; do
44         git push $remote 2>&1 | grep -v 'Everything up-to-date'
45         git push --tags $remote 2>&1 | grep -v 'Everything up-to-date'
46     done
47 fi
48 # Show unmerged changes.
49 git branch -rv --color --no-merged
50 # Show uncommitted changes.
51 if `echo "$1" | grep '\.git\$' > /dev/null`; then
52     cd ..
53 fi
54 git status | grep 'Changes to be committed:' > /dev/null \
55     && echo '-> modified (staged)'
56 git status | grep 'Changed but not updated:' > /dev/null \
57     && echo '-> modified'
58 git status | grep 'Untracked files:' > /dev/null \
59     && echo '-> modified (untracked)'
60
61 echo