chiark / gitweb /
Properly complete partially written vercodes
[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         if [ -d ../metadata ]; then
25                 cd ..
26         else
27                 echo "No metadata files found!"
28                 exit 2
29         fi
30 fi
31
32 while read line; do
33         if [[ "$line" == *M*metadata/*.txt ]]; then
34                 file=${line##* }
35
36                 id=${file##*/}
37                 id=${id%.txt*}
38                 if [ $# -gt 0 ]; then
39                         found=false
40                         for arg in "$@"; do
41                                 if [ "$id" == "$arg" ]; then
42                                         found=true
43                                         break
44                                 fi
45                         done
46                         $found || continue
47                 fi
48
49                 [ -d metadata/$id ] && extra=metadata/$id || extra=
50
51                 name= autoname=
52                 while read l; do
53                         if [[ "$l" == "Auto Name:"* ]]; then
54                                 autoname=${l#*:}
55                         elif [[ "$l" == "Name:"* ]]; then
56                                 name=${l#*:}
57                         fi
58                 done < "$file"
59
60                 if [ -n "$name" ]; then
61                         fullname="$name"
62                 elif [ -n "$autoname" ]; then
63                         fullname="$autoname"
64                 else
65                         fullname="$id"
66                 fi
67
68                 onlybuild=true
69                 newbuild=false
70                 disable=false
71                 while read l; do
72                         if [[ "$l" == *"Maintainer Notes:"* ]]; then
73                                 break
74                         fi
75                         if [[ "$l" == "-Build:"* ]]; then
76                                 onlybuild=false
77                         elif [[ "$l" == "+Build:"* ]]; then
78                                 if $newbuild; then
79                                         onlybuild=false
80                                 fi
81                                 newbuild=true
82                                 build=${l#*:}
83                                 version=${build%%,*}
84                                 build=${build#*,}
85                                 vercode=${build%%,*}
86                         elif $newbuild && $onlybuild && [[ "$l" == "+"*"disable="* ]]; then
87                                 disable=true
88                         fi
89                 done < <(git diff HEAD -- "$file")
90
91                 if $newbuild && $onlybuild; then
92                         if $disable; then
93                                 message="Don't update $fullname to $version ($vercode)"
94                         else
95                                 message="Update $fullname to $version ($vercode)"
96                         fi
97                 else
98                         message="$fullname:"
99                 fi
100
101                 message=${message//\"/\\\"}
102                 commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
103         fi
104 done < <(git status --porcelain)
105
106 [[ -z $commands ]] && exit 0
107
108 git reset >/dev/null
109 for cmd in "${commands[@]}"; do
110         eval "$cmd"
111         git reset >/dev/null
112 done