mktar: Use `wc` instead of `du` in summary message
[sunny256-utils.git] / git-up
blob7179760c52dbb00eef921fe17048bd295179dbda
1 #!/bin/sh
3 #==============================================================================
4 # git-up
5 # File ID: 96b89f6a-d1eb-11e7-9056-f74d993421b0
7 # Make a full Git update in the current repository
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=git-up
14 VERSION=0.1.4
16 T_GREEN=$(tput setaf 2)
17 T_RED=$(tput setaf 1)
18 T_RESET=$(tput sgr0)
20 opt_help=0
21 opt_quiet=0
22 opt_verbose=0
23 while test -n "$1"; do
24 case "$1" in
25 -h|--help) opt_help=1; shift ;;
26 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
27 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
28 --version) echo $progname $VERSION; exit 0 ;;
29 --) shift; break ;;
31 if printf '%s\n' "$1" | grep -q ^-; then
32 echo "$progname: $1: Unknown option" >&2
33 exit 1
34 else
35 break
37 break ;;
38 esac
39 done
40 opt_verbose=$(($opt_verbose - $opt_quiet))
42 runcmd() {
43 echo >&2
44 echo "$T_GREEN$progname: $*$T_RESET" >&2
48 if test "$opt_help" = "1"; then
49 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
50 cat <<END
52 Make a full Git update in the current repository. Fetch everything from
53 all remotes, update all local branches and create commit-* branches from
54 dangling heads.
56 Usage: $progname [options]
58 Options:
60 -h, --help
61 Show this help.
62 -q, --quiet
63 Be more quiet. Can be repeated to increase silence.
64 -v, --verbose
65 Increase level of verbosity. Can be repeated.
66 --version
67 Print version information.
69 END
70 exit 0
73 repotop="$(git rev-parse --show-toplevel)"
74 if [ -z "$repotop" ]; then
75 echo $progname: Not in a Git repository >&2
76 exit 1
79 cd "$repotop" || {
80 echo $progname: $repotop: Cannot chdir to top of repo >&2
81 exit 1
84 currbranch=$(git rev-parse --abbrev-ref HEAD)
86 safe_checkout() {
87 local branch=$1
89 if test -n "$currbranch" -a "$currbranch" != "HEAD"; then
90 runcmd git checkout "$branch"
91 else
92 echo -n "$T_RED$progname: " >&2
93 echo "No current branch, skip \"git checkout $branch\"$T_RESET" >&2
97 runcmd git fetch --all --prune
98 runcmd git merge --ff-only
99 safe_checkout $(git rev-parse HEAD)
100 runcmd git allbr -a
101 safe_checkout -
102 runcmd git dangling
104 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :