summaryrefslogtreecommitdiffstats
path: root/extra/prepare-commit-msg
blob: 9948d543f0aed0965626f1089d45ebac95d3e658 (plain) (blame)
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
#!/bin/bash

[ -n "$2" ] && exit 0
[ -e "$1" ] || exit 1

declare -A stuff
re='core/(modules|rootfs)/([^/]+)/'
while IFS='' read -r line || [[ -n "$line" ]]; do
	if [[ $line =~ $re ]]; then
		if [ -z "${stuff["${BASH_REMATCH[2]}"]}" ]; then
			stuff["${BASH_REMATCH[2]}"]=1
		else
			let stuff["${BASH_REMATCH[2]}"]++
		fi
	fi
done < <( git status --porcelain | grep -E '^(A|M|D)' )

[ "${#stuff[@]}" -gt 2 ] && exit 0
[ "${#stuff[@]}" -lt 1 ] && exit 0

out=""
for key in "${!stuff[@]}"; do
	out+="/$key"
	#echo "$key = ${stuff["$key"]}"
done
sed -i "1s~^~[${out:1}] ~" "$1"