chiark / gitweb /
Fix Tags UCM on newer git-svn versions
[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
34         case "$line" in
35                 *'??'*'metadata/'*'.txt') new=true ;;
36                 *'M'*'metadata/'*'.txt') new=false ;;
37         esac
38
39         file=${line##* }
40         id=${file##*/}
41         id=${id%.txt*}
42
43         if [ $# -gt 0 ]; then
44                 case "$@" in
45                         *" $id "*) ;;  # Middle
46                         "$id "*) ;;    # Start
47                         *" $id") ;;    # End
48                         "$id") ;;      # Alone
49                         *) continue ;; # Missing
50                 esac
51         fi
52
53         [ -d metadata/$id ] && extra=metadata/$id || extra=
54
55         name= autoname=
56         while read l; do
57                 case "$l" in
58                         'Auto Name:'*) autoname=${l#*:} ;;
59                         'Name:'*) name=${l#*:} ;;
60                         'Summary:'*) break ;;
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                 while read line; do
79                         case "$line" in
80                                 *'Maintainer Notes:'*) break ;;
81                                 '-Build:'*) onlybuild=false ;;
82                                 '+Build:'*)
83                                         $newbuild && onlybuild=false
84                                         newbuild=true
85                                         build=${line#*:}
86                                         version=${build%%,*}
87                                         build=${build#*,}
88                                         vercode=${build%%,*}
89                                         ;;
90                                 '+'*'disable='*)
91                                         $newbuild && $onlybuild && disable=true
92                                         ;;
93                         esac
94                 done < <(git diff HEAD -- "$file")
95
96                 if $newbuild && $onlybuild; then
97                         if $disable; then
98                                 message="Don't update $fullname to $version ($vercode)"
99                         else
100                                 message="Update $fullname to $version ($vercode)"
101                         fi
102                 else
103                         message="$fullname:"
104                 fi
105         fi
106
107         message=${message//\"/\\\"}
108         commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
109
110 done < <(git status --porcelain metadata)
111
112 [ -z "$commands" ] && exit 0
113
114 git reset >/dev/null
115 for cmd in "${commands[@]}"; do
116         eval "$cmd"
117         git reset >/dev/null
118 done