chiark / gitweb /
Don't directly print FDroidPopen output unless verbose
[fdroidserver.git] / fd-commit
1 #!/bin/sh
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         [ -z "$line" ] && continue
34
35         case "$line" in
36                 *\?\?*metadata/*.txt) new=true ;;
37                 *M*metadata/*.txt) new=false ;;
38         esac
39
40         file=${line##* }
41         id=${file##*/}
42         id=${id%.txt*}
43
44         if [ $# -gt 0 ]; then
45                 case "$@" in
46                         *" $id "*) ;;  # Middle
47                         "$id "*) ;;    # Start
48                         *" $id") ;;    # End
49                         "$id") ;;      # Alone
50                         *) continue ;; # Missing
51                 esac
52         fi
53
54         [ -d metadata/$id ] && extra=metadata/$id || extra=
55
56         name= autoname=
57         while read l; do
58                 case "$l" in
59                         'Auto Name:'*) autoname=${l#*:} ;;
60                         'Name:'*) name=${l#*:} ;;
61                 esac
62         done < "$file"
63
64         if [ -n "$name" ]; then
65                 fullname="$name"
66         elif [ -n "$autoname" ]; then
67                 fullname="$autoname"
68         else
69                 fullname="$id"
70         fi
71
72         if $new; then
73                 message="New app: $fullname"
74         else
75                 onlybuild=true
76                 newbuild=false
77                 disable=false
78
79                 while read l; do
80                         case "$l" in
81                                 *"Maintainer Notes:"*) break ;;
82                                 "-Build:"*) onlybuild=false ;;
83                                 "+Build:"*)
84                                         $newbuild && onlybuild=false
85                                         newbuild=true
86                                         build=${l#*:}
87                                         version=${build%%,*}
88                                         build=${build#*,}
89                                         vercode=${build%%,*}
90                                         ;;
91                                 '+'*"disable="*)
92                                         $newbuild && $onlybuild && disable=true
93                                         ;;
94                         esac
95                 done << EOF
96                 $(git diff HEAD -- "$file")
97 EOF
98
99                 if $newbuild && $onlybuild; then
100                         if $disable; then
101                                 message="Don't update $fullname to $version ($vercode)"
102                         else
103                                 message="Update $fullname to $version ($vercode)"
104                         fi
105                 else
106                         message="$fullname:"
107                 fi
108         fi
109
110         message=${message//\"/\\\"}
111         commands="$commands%%git add -- $file $extra && git commit -m \"$message\" -e -v"
112
113 done << EOF
114 $(git status --porcelain metadata)
115 EOF
116
117 [ -z "$commands" ] && exit 0
118
119 git reset >/dev/null
120 IFS='%%'
121 for cmd in $commands; do
122         [ -z "$cmd" ] && continue
123         eval $cmd
124         git reset >/dev/null
125 done