chiark / gitweb /
travis-ci: use most recent OSX image to get Java8
[fdroidserver.git] / fd-commit
index e1445a475e4b8e3119c042e84f190b15c15a0ea4..4f6e9697cbd20211d5fc8d64d56adf95c63bc2a5 100755 (executable)
--- a/fd-commit
+++ b/fd-commit
 #!/bin/bash
-
+#
+# fd-commit - part of the F-Droid server tools
 # Commits updates to apps, allowing you to edit the commit messages
+#
+# Copyright (C) 2013-2014 Daniel Marti <mvdan@mvdan.cc>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 commands=()
 
+if [ ! -d metadata ]; then
+       if [ -d ../metadata ]; then
+               cd ..
+       else
+               echo "No metadata files found!"
+               exit 2
+       fi
+fi
+
 while read line; do
-    if [[ "$line" == *M*metadata/*.txt ]]; then
-        file=${line##* }
-
-        while read l; do
-            [[ "$l" == "Auto Name:"* ]] && name=${l##*:}
-        done < "$file"
-
-        id=${file##*/}
-        id=${id%.txt*}
-        [ -d metadata/$id ] && extra=metadata/$id
-        [ -n "$name" ] && id="$name ($id)"
-
-        newbuild=0
-        while read l; do
-            if [[ "$l" == "+Build:"* ]]; then
-                newbuild=1
-                build=${l#*:}
-                version=${build%%,*}
-                build=${build#*,}
-                vercode=${build%%,*}
-            fi
-        done < <(git diff HEAD -- "$file")
-
-        if [ $newbuild -eq 0 ]
-               then
-                       message="$id:"
+
+       case "$line" in
+               *'??'*'metadata/'*'.txt') new=true ;;
+               *'M'*'metadata/'*'.txt') new=false ;;
+               *) continue ;;
+       esac
+
+       file=${line##* }
+       id=${file##*/}
+       id=${id%.txt*}
+
+       if [ $# -gt 0 ]; then
+               case "$@" in
+                       *" $id "*) ;;  # Middle
+                       "$id "*) ;;    # Start
+                       *" $id") ;;    # End
+                       "$id") ;;      # Alone
+                       *) continue ;; # Missing
+               esac
+       fi
+
+       [ -d metadata/$id ] && extra=metadata/$id || extra=
+
+       name= autoname=
+       while read l; do
+               case "$l" in
+                       'Auto Name:'*) autoname=${l#*:} ;;
+                       'Name:'*) name=${l#*:} ;;
+                       'Summary:'*) break ;;
+               esac
+       done < "$file"
+
+       if [ -n "$name" ]; then
+               fullname="$name"
+       elif [ -n "$autoname" ]; then
+               fullname="$autoname"
+       else
+               fullname="$id"
+       fi
+
+       if $new; then
+               message="New app: $fullname"
+       else
+               onlybuild=true
+               newbuild=false
+               disable=false
+               while read line; do
+                       case "$line" in
+                               '-Build:'*) onlybuild=false ;;
+                               '+Build:'*)
+                                       $newbuild && onlybuild=false
+                                       newbuild=true
+                                       build=${line#*:}
+                                       version=${build%%,*}
+                                       build=${build#*,}
+                                       vercode=${build%%,*}
+                                       ;;
+                               '+'*'disable='*)
+                                       $newbuild && $onlybuild && disable=true
+                                       ;;
+                       esac
+               done < <(git diff HEAD -- "$file")
+
+               if $newbuild && $onlybuild; then
+                       if $disable; then
+                               message="Don't update $fullname to $version ($vercode)"
+                       else
+                               message="Update $fullname to $version ($vercode)"
+                       fi
                else
-                       message="Update $id to $version ($vercode)"
+                       message="$fullname:"
                fi
+       fi
 
-        commands+=("git commit -m '$message' -e -v -- $file $extra")
-    fi
-done < <(git status --porcelain)
+       message=${message//\"/\\\"}
+       commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
 
+done < <(git status --porcelain metadata)
+
+[ -z "$commands" ] && exit 0
+
+git reset >/dev/null
 for cmd in "${commands[@]}"; do
-    eval "$cmd"
+       eval "$cmd"
+       git reset >/dev/null
 done
-