Fix README text
[carddav-git-backup.git] / create-commit-message.sh
1 #!/bin/sh
2 #create a nice commit message that contains the names
3 # of all modified, added and deleted contacts
4 # to make it easier to find changes in the git history
5 set -e
6
7 numadd=$(git status --porcelain -uno|grep ^A|wc -l)
8 numdel=$(git status --porcelain -uno|grep ^D|wc -l)
9 nummod=$(git status --porcelain -uno|grep ^M|wc -l)
10 if [ "$numadd" -eq 0 -a "$numdel" -eq 0 -a "$nummod" -eq 0 ]; then
11     exit 0
12 fi
13
14 echo "Backup $(date +%F): ~$nummod +$numadd -$numdel"
15 echo
16
17 for addressbook in $(ls -1d */* | grep -v vdirsyncer-status/); do
18     user=$(echo $addressbook | cut -d/ -f1)
19     addressbookTitle=$(cat $addressbook/displayname)
20
21     added=$(git status --porcelain -uno\
22                 | grep ^A.*$addressbook.*vcf$\
23                 | cut -b 4-\
24                 | xargs -L1 grep ^FN:\
25                 | cut -b 4-\
26                 | sort)
27     modified=$(git status --porcelain -uno\
28                 | grep ^M.*$addressbook.*vcf$\
29                 | cut -b 4-\
30                 | xargs -L1 grep ^FN:\
31                 | cut -b 4-\
32                 | sort)
33     deleted=$(git status --porcelain -uno\
34                 | grep ^D.*$addressbook.*vcf$\
35                 | cut -b 4-\
36                 | xargs --replace={} git diff --cached -- {}\
37                 | grep ^-FN:\
38                 | cut -b 5-\
39                 | sort)
40
41     if [ -n "$added" -o -n "$modified" -o -n "$deleted" ]; then
42         echo "$user: $addressbookTitle"
43         echo "---------"
44
45         if [ -n "$added" ]; then
46             echo "Added:"
47             echo "$added" | sed 's/^/- /'
48             echo
49         fi
50
51         if [ -n "$modified" ]; then
52             echo "Modified:"
53             echo "$modified" | sed 's/^/- /'
54             echo
55         fi
56
57         if [ -n "$deleted" ]; then
58             echo "Deleted:"
59             echo "$deleted" | sed 's/^/- /'
60             echo
61         fi
62     fi
63 done