-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgear-commit
More file actions
executable file
·146 lines (122 loc) · 3.91 KB
/
gear-commit
File metadata and controls
executable file
·146 lines (122 loc) · 3.91 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh -efu
#
# Copyright (C) 2006-2017 Alexey Gladkov <legion@altlinux.org>
# Copyright (C) 2006-2016 Dmitry V. Levin <ldv@altlinux.org>
# Copyright (C) 2006 Sergey Vlasov <vsu@altlinux.org>
#
# git commit wrapper for gear.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
. gear-utils-sh-functions
. shell-getopt
. shell-var
show_help()
{
cat <<EOF
Usage: $PROG [options] [git-commit options] [--] <filepattern>...
Options:
--spec=FILE do not look for specfile in repository,
use given FILE instead;
--no-edit do not edit the message taken from changelog
entry or with -m option;
-e, --edit edit the message before commit;
-m, --message=TEXT use given TEXT for commit message;
-V, --version print program version and exit;
-h, --help show this text and exit.
Report bugs to https://bugzilla.altlinux.org/
EOF
exit
}
print_version()
{
cat <<EOF
$PROG version $PROG_VERSION
Written by Alexey Gladkov <legion@altlinux.org>
Copyright (C) 2006-2017 Alexey Gladkov <legion@altlinux.org>
Copyright (C) 2006-2016 Dmitry V. Levin <ldv@altlinux.org>
Copyright (C) 2006 Sergey Vlasov <vsu@altlinux.org>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit
}
GETOPT_ALLOW_UNKNOWN=1
TEMP=$(getopt -n $PROG -o 'e,m:,h,V' -l 'edit,message:,no-edit,spec:,help,version' -- "$@") || show_usage
eval set -- "$TEMP"
gear_config_option gear_edit_message edit-message yes
gear_config_option gear_require_message_save require-message-save no
commitlog=
specfile=
while :; do
case "$1" in
--spec) shift
specfile="$1"
[ -z "$commitlog" ] ||
show_usage "Options --spec and --message are mutually exclusive."
;;
--no-edit) gear_edit_message=no
;;
-e|--edit)
gear_edit_message=yes
;;
-m|--message) shift
commitlog="$1"
[ -z "$specfile" ] ||
show_usage "Options --spec and --message are mutually exclusive."
;;
-h|--help) show_help
;;
-V|--version) print_version
;;
--) shift; break
;;
esac
shift
done
GEAR_COMMIT=1
GEAR_COMMIT_AMEND=
args=
while [ $# -gt 0 ]; do
[ "$1" != '--amend' ] ||
GEAR_COMMIT_AMEND=1
args="$args \"$(quote_shell "$1")\""
shift
done
# Change to toplevel directory
chdir_to_toplevel
guess_specfile
[ -s "$specfile" ] ||
fatal "$specfile: file not available or empty"
install_cleanup_handler cleanup_workdir
workdir="$(mktemp -dt "$PROG.XXXXXXXXXX")"
if [ -z "$commitlog" ]; then
vr="$(sed -ne '/^[[:space:]]*%changelog[[:space:]]*$/{n; s/\* .* \([^[:space:]]\+\)$/\1/p}' "$specfile")"
ch="$(sed -ne '0,/^[[:space:]]*%changelog[[:space:]]*$/d;2,/^* /{/^* /!p}' "$specfile")"
[ -z "$vr$ch" ] ||
commitlog="$(printf '%s\n\n%s\n' "$vr" "$ch" |sed s/%%/%/g)"
unset ch vr specfile
fi
{
! shell_var_is_yes "$gear_require_message_save" ||
printf '%s\n\n' '<gear-commit message template, please remove this line and save to commit>'
printf '%s\n' "$commitlog"
} > "$workdir/commit-msg"
export GEAR_COMMIT GEAR_COMMIT_AMEND
git_edit=
git_msgtype='-F'
! shell_var_is_yes "$gear_edit_message" || git_edit='--edit'
! shell_var_is_yes "$gear_require_message_save" || git_msgtype='-t'
eval git commit $git_msgtype "$workdir/commit-msg" $git_edit $args