test-ly-files: Display symlink creation, add `-v` to `ln`
[sunny256-utils.git] / ciall
blob3d1d2a0944accb1514e2ff53bb1ecc7a4de94159
1 #!/bin/sh
3 #==============================================================================
4 # ciall
5 # File ID: dd770008-300f-11df-b5fc-90e6ba3022ac
7 # Commit all files in current directory tree to Git.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=ciall
14 VERSION=0.4.0
16 opt_store_empty_dirs=0
17 opt_edit=0
18 opt_help=0
19 opt_quiet=0
20 opt_verbose=0
21 opt_yes=0
22 while test -n "$1"; do
23 case "$1" in
24 -d|--store-empty-dirs) opt_store_empty_dirs=1; shift ;;
25 -e|--edit) opt_edit=1; shift ;;
26 -h|--help) opt_help=1; shift ;;
27 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
28 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
29 -y|--yes) opt_yes=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 Commit all files in current directory tree to Git.
50 Usage: $progname [options]
52 Options:
54 -e, --edit
55 Edit the log message in your favourite editor, using the value of
56 the EDITOR environment variable.
57 -d, --store-empty-dirs
58 Also store empty directories in ".emptydirs".
59 -h, --help
60 Show this help.
61 -q, --quiet
62 Be more quiet. Can be repeated to increase silence.
63 -v, --verbose
64 Increase level of verbosity. Can be repeated.
65 -y, --yes
66 Answer "yes" to commit prompt, commit automatically.
67 --version
68 Print version information.
70 END
71 exit 0
74 unset opt_str
75 test "$opt_store_empty_dirs" = "1" && {
76 opt_str=-d
77 test "$(git config --get ciall.noemptydirs)" = "true" && {
78 echo $progname: -d option not allowed here >&2
79 exit 1
81 echo -n $progname: Executing git-store-dirs... >&2
82 git store-dirs || {
83 echo git-store-dirs error >&2;
84 exit 1;
86 echo DONE >&2
88 besafe=n
89 test "$opt_yes" = "1" && { besafe=y; opt_str=-y; }
90 echo $progname: git status 1... >&2
91 LC_ALL=C git status . | grep "^nothing to commit" && {
92 echo $progname: Nothing to do here.
93 exit 0
96 unset logmsg
97 test ! -z "$1" && logmsg="$*"
99 echo $progname: git status 2... >&2
100 git status .
101 echo
102 echo "Log message: $opt_str '$logmsg'"
103 until test "$besafe" = "y"; do
104 echo -n "Press 'y' + Enter to commit all new changes " >&2
105 echo -n or \'n\' to abort... >&2
106 read besafe
107 test "$besafe" = "n" && exit 0;
108 done
110 if test "$opt_edit" = "1"; then
111 if test -z "$EDITOR"; then
112 echo -n "$progname: The EDITOR environment variable " >&2
113 echo is not defined >&2
114 exit 1
116 tmpmsgfile=/tmp/$(date +%s)-$$.tmp
117 $EDITOR $tmpmsgfile
118 logmsg=$(cat $tmpmsgfile)
119 test -z "$logmsg" && {
120 echo $progname: No text entered in editor, aborting. >&2
121 exit 1
125 echo $progname: git status 3... >&2
126 LC_ALL=C git status . | grep "^nothing to commit" || (
127 echo $progname: git add --all .
128 git add --all . && (
129 echo $progname: git commit >&2
130 git commit -m "$logmsg$(
131 echo
132 echo
133 suuid -t $progname -c "$logmsg" -wa
137 echo ========== git status ==========
138 git status
139 exit 0
141 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :