-
Notifications
You must be signed in to change notification settings - Fork 59
/
xrevbump
executable file
·75 lines (65 loc) · 1.43 KB
/
xrevbump
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
#!/bin/bash
# xrevbump MESSAGE TEMPLATES... -- git commit options - increase template revision and commit
# TEMPLATES can be "-", then read linewise from stdin.
MESSAGE=$1
shift
if [ $# -eq 0 ]; then
printf "Usage: xrevbump MESSAGE TEMPLATES... -- git commit options\n" >&2
exit 1
fi
declare -a seen
bump() {
t="$1"
if [ -f "$t" ]; then
:
elif [ -f "$t/template" ]; then
t="$t/template"
elif [ -f "srcpkgs/$t/template" ]; then
t="srcpkgs/$t/template"
elif [ -f "$XBPS_DISTDIR/srcpkgs/$1/template" ]; then
t="$XBPS_DISTDIR/srcpkgs/$1/template"
else
printf "Cannot find template '%s'\n" "$t"
return
fi
. "$t"
case "${seen[@]}" in
*" $pkgname "*)
printf "%s: bumped already.\n" "$t"
;;
*)
if ! $(git diff HEAD "$t" | grep -q '^[-+]revision='); then
revision=$((revision + 1))
printf "%s: bump to revision %d\n" "$t" "$revision"
sed -i -e "/^revision=/s/=.*/=$revision/" "$t"
else
printf "%s: committing\n" "$t"
fi
git -C "${t%/*}" commit $commit_args -m "$pkgname: $MESSAGE" . || printf "\033[1;31m%s: failed to commit!\033[0m\n" "$t"
seen+=($pkgname)
;;
esac
}
XBPS_DISTDIR="$(xdistdir)"
declare -a templates
if [ "$1" = - ]; then
shift
if [ "$1" = -- ]; then
shift
commit_args="$@"
fi
IFS=$'\n' read -d '' -r -a templates
else
for t; do
if [ "$1" = -- ]; then
shift
commit_args="$@"
break
fi
templates+=($t)
shift
done
fi
for t in "${templates[@]}"; do
bump "$t"
done