chiark / gitweb /
Use logging with proper format when warning about improper verbose/quiet usage
[fdroidserver.git] / fd-commit
index e64486a1afef53374d8998dfa71e9f17a9b9bd37..20c84895fd1d8097ab3e3e84e7c52bcada45ae96 100755 (executable)
--- a/fd-commit
+++ b/fd-commit
@@ -1,9 +1,9 @@
-#!/bin/bash
+#!/bin/sh
 #
 # fd-commit - part of the FDroid server tools
 # Commits updates to apps, allowing you to edit the commit messages
 #
-# Copyright (C) 2013 Daniel Martí <mvdan@mvdan.cc>
+# Copyright (C) 2013-2014 Daniel Martí <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
 # 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=()
+commands=""
 
 if [ ! -d metadata ]; then
-       [ -d ../metadata ] && cd .. || { echo "No metadata files found!"; exit 2; }
+       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##* }
-
-               id=${file##*/}
-               id=${id%.txt*}
-               if [ $# -gt 0 ]; then
-                       found=false
-                       for arg in "$@"; do
-                               if [ "$id" == "$arg" ]; then
-                                       found=true
-                                       break
-                               fi
-                       done
-                       $found || continue
-               fi
+       [ -z "$line" ] && continue
 
-               [ -d metadata/$id ] && extra=metadata/$id || extra=
+       case "$line" in
+               *\?\?*metadata/*.txt) new=true ;;
+               *M*metadata/*.txt) new=false ;;
+       esac
 
-               name= autoname=
-               while read l; do
-                       if [[ "$l" == "Auto Name:"* ]]; then
-                               autoname=${l##*:}
-                       elif [[ "$l" == "Name:"* ]]; then
-                               name=${l##*:}
-                       fi
-               done < "$file"
+       file=${line##* }
+       id=${file##*/}
+       id=${id%.txt*}
 
-               if [ -n "$name" ]; then
-                       fullname="$name ($id)"
-               elif [ -n "$autoname" ]; then
-                       fullname="$autoname ($id)"
-               else
-                       fullname="$id"
-               fi
+       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#*:} ;;
+               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 l; do
-                       if [[ "$l" == "+Build:"* ]]; then
-                               newbuild=true
-                               build=${l#*:}
-                               version=${build%%,*}
-                               build=${build#*,}
-                               vercode=${build%%,*}
-                       fi
-               done < <(git diff HEAD -- "$file")
+                       case "$l" in
+                               *"Maintainer Notes:"*) break ;;
+                               "-Build:"*) onlybuild=false ;;
+                               "+Build:"*)
+                                       $newbuild && onlybuild=false
+                                       newbuild=true
+                                       build=${l#*:}
+                                       version=${build%%,*}
+                                       build=${build#*,}
+                                       vercode=${build%%,*}
+                                       ;;
+                               '+'*"disable="*)
+                                       $newbuild && $onlybuild && disable=true
+                                       ;;
+                       esac
+               done << EOF
+               $(git diff HEAD -- "$file")
+EOF
 
-               if $newbuild ; then
-                       message="Update $fullname to $version ($vercode)"
+               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="$fullname:"
                fi
-
-               message=${message//\"/\\\"}
-               commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
        fi
-done < <(git status --porcelain)
+
+       message=${message//\"/\\\"}
+       commands="$commands%%git add -- $file $extra && git commit -m \"$message\" -e -v"
+
+done << EOF
+$(git status --porcelain metadata)
+EOF
+
+[ -z "$commands" ] && exit 0
 
 git reset >/dev/null
-for cmd in "${commands[@]}"; do
-       eval "$cmd"
+IFS='%%'
+for cmd in $commands; do
+       [ -z "$cmd" ] && continue
+       eval $cmd
        git reset >/dev/null
 done