Upgrade youtube-dl to version 2021.04.21
[sunny256-utils.git] / git-wait-until-clean
blobdceb83a30bd13c0713da87142bdcb3a9e5d0af7c
1 #!/bin/sh
3 #==============================================================================
4 # git-wait-until-clean
5 # File ID: 92d46e22-d5a1-11e4-9769-000df06acc56
7 # Wait until the current Git repository is clean before continuing.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=git-wait-until-clean
14 VERSION=0.5.0
16 opt_exit_val=0
17 opt_help=0
18 opt_ignored=0
19 opt_quiet=0
20 opt_untracked=0
21 opt_verbose=0
22 while :; do
23 case "$1" in
24 -e|--exit-val) opt_exit_val=1; shift ;;
25 -h|--help) opt_help=1; shift ;;
26 -i|--ignored) opt_ignored=1; shift ;;
27 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
28 -u|--untracked) opt_untracked=1; shift ;;
29 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
30 --version) echo $progname $VERSION; exit 0 ;;
31 --) shift; break ;;
33 if printf '%s\n' "$1" | grep -q ^-; then
34 echo "$progname: $1: Unknown option" >&2
35 exit 1
36 else
37 break
39 break ;;
40 esac
41 done
42 opt_verbose=$(($opt_verbose - $opt_quiet))
44 if test "$opt_help" = "1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 cat <<END
48 Wait until the current Git repository is clean before continuing.
49 Does nothing in bare repositories.
51 Usage: $progname [options]
53 Options:
55 -e, --exit-val
56 Don't wait if the repository is modified, but exit immediately and
57 use the return value to tell if it's modified or not.
58 0: Repository is not modified
59 1: Repository is modified
60 -h, --help
61 Show this help.
62 -i, --ignored
63 Also wait if there are any ignored files in the repository.
64 -q, --quiet
65 Be more quiet. Can be repeated to increase silence.
66 -u, --untracked
67 Allow untracked files in the repository.
68 -v, --verbose
69 Increase level of verbosity. Can be repeated.
70 --version
71 Print version information.
73 END
74 exit 0
77 is_bare=0
78 test "$(git config --get core.bare)" = "true" && is_bare=1
80 test "$is_bare" = "1" && exit 0
82 unset i_str
83 test "$opt_ignored" = "1" && i_str=" --ignored"
85 unset u_str
86 test "$opt_untracked" = "1" && u_str=" --untracked-files=no"
88 unset did_wait
89 while test "$(git status --porcelain$i_str$u_str "$@")" != ""; do
90 if test "$opt_exit_val" = "1"; then
91 if test $opt_verbose -ge 1; then
92 echo -n "$progname: $(pwd) is modified, " >&2
93 echo exit with value 1 >&2
95 exit 1
97 echo -n "Waiting for $(hostname):$(pwd) to be cleaned up " >&2
98 echo \(opt: $i_str$u_str\)... \($(date)\) >&2
99 sleep 5
100 did_wait=1
101 done
102 test -n "$did_wait" && echo $(hostname):$(pwd) is clean. Continuing... >&2
103 if test $opt_verbose -ge 1; then
104 echo $progname: $(pwd) is clean, exit with value 0 >&2
106 exit 0
108 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :