chiark / gitweb /
Fix: Also add new files in app metadata dirs (e.g. new patches)
[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 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                 newbuild=false
64                 while read l; do
65                         if [[ "$l" == "+Build:"* ]]; then
66                                 newbuild=true
67                                 build=${l#*:}
68                                 version=${build%%,*}
69                                 build=${build#*,}
70                                 vercode=${build%%,*}
71                         fi
72                 done < <(git diff HEAD -- "$file")
73
74                 if $newbuild ; then
75                         message="Update $fullname to $version ($vercode)"
76                 else
77                         message="$fullname:"
78                 fi
79
80                 message=${message//\"/\\\"}
81                 commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
82         fi
83 done < <(git status --porcelain)
84
85 for cmd in "${commands[@]}"; do
86         eval "$cmd"
87 done