chiark / gitweb /
Update my own copyright notices
[fdroidserver.git] / fd-commit
1 #!/bin/bash
2 #
3 # fd-commit - part of the FDroid server tools
4 # Commits updates to apps, allowing you to edit the commit messages
5 #
6 # Copyright (C) 2013-2014 Daniel Martí <mvdan@mvdan.cc>
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Affero General Public License for more details.
17 #
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 commands=()
22
23 if [ ! -d metadata ]; then
24         [ -d ../metadata ] && cd .. || { echo "No metadata files found!"; exit 2; }
25 fi
26
27 while read line; do
28         if [[ "$line" == *M*metadata/*.txt ]]; then
29                 file=${line##* }
30
31                 id=${file##*/}
32                 id=${id%.txt*}
33                 if [ $# -gt 0 ]; then
34                         found=false
35                         for arg in "$@"; do
36                                 if [ "$id" == "$arg" ]; then
37                                         found=true
38                                         break
39                                 fi
40                         done
41                         $found || continue
42                 fi
43
44                 [ -d metadata/$id ] && extra=metadata/$id || extra=
45
46                 name= autoname=
47                 while read l; do
48                         if [[ "$l" == "Auto Name:"* ]]; then
49                                 autoname=${l##*:}
50                         elif [[ "$l" == "Name:"* ]]; then
51                                 name=${l##*:}
52                         fi
53                 done < "$file"
54
55                 if [ -n "$name" ]; then
56                         fullname="$name ($id)"
57                 elif [ -n "$autoname" ]; then
58                         fullname="$autoname ($id)"
59                 else
60                         fullname="$id"
61                 fi
62
63                 onlybuild=true
64                 newbuild=false
65                 while read l; do
66                         if [[ "$l" == "-Build:"* ]]; then
67                                 onlybuild=false
68                         elif [[ "$l" == "+Build:"* ]]; then
69                                 if $newbuild; then
70                                         onlybuild=false
71                                 fi
72                                 newbuild=true
73                                 build=${l#*:}
74                                 version=${build%%,*}
75                                 build=${build#*,}
76                                 vercode=${build%%,*}
77                         elif $newbuild && $onlybuild [[ "$l" == "+"*"disable="* ]]; then
78                                 disable=true
79                         fi
80                 done < <(git diff HEAD -- "$file")
81
82                 if $newbuild && $onlybuild; then
83                         if $disable; then
84                                 message="Don't update $fullname to $version ($vercode)"
85                         else
86                                 message="Update $fullname to $version ($vercode)"
87                         fi
88                 else
89                         message="$fullname:"
90                 fi
91
92                 message=${message//\"/\\\"}
93                 commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
94         fi
95 done < <(git status --porcelain)
96
97 git reset >/dev/null
98 for cmd in "${commands[@]}"; do
99         eval "$cmd"
100         git reset >/dev/null
101 done