chiark / gitweb /
fd-commit: don't use wrong name when there is no autoname
[fdroidserver.git] / fd-commit
1 #!/bin/bash
2
3 # Commits updates to apps, allowing you to edit the commit messages
4
5 commands=()
6
7 if [ ! -d metadata ]; then
8         [ -d ../metadata ] && cd .. || { echo "No metadata files found!"; exit 2; }
9 fi
10
11 while read line; do
12         if [[ "$line" == *M*metadata/*.txt ]]; then
13                 file=${line##* }
14                 
15                 id=${file##*/}
16                 id=${id%.txt*}
17                 if [ $# -gt 0 ]; then
18                         found=false
19                         for arg in "$@"; do
20                                 if [ "$id" == "$arg" ]; then
21                                         found=true
22                                         break
23                                 fi
24                         done
25                         $found || continue
26                 fi
27
28                 [ -d metadata/$id ] && extra=metadata/$id
29
30                 autoname=""
31                 while read l; do
32                         if [[ "$l" == "Auto Name:"* ]]; then
33                                 autoname=${l##*:}
34                         elif [[ "$l" == "Name:"* ]]; then
35                                 name=${l##*:}
36                         fi
37                 done < "$file"
38
39                 if [ -n "$name" ]; then
40                         fullname="$name ($id)"
41                 elif [ -n "$autoname" ]; then
42                         fullname="$autoname ($id)"
43                 else
44                         fullname="$id"
45                 fi
46
47                 newbuild=0
48                 while read l; do
49                         if [[ "$l" == "+Build:"* ]]; then
50                                 newbuild=1
51                                 build=${l#*:}
52                                 version=${build%%,*}
53                                 build=${build#*,}
54                                 vercode=${build%%,*}
55                         fi
56                 done < <(git diff HEAD -- "$file")
57
58                 if [ $newbuild -eq 0 ]; then
59                         message="$fullname:"
60                 else
61                         message="Update $fullname to $version ($vercode)"
62                 fi
63
64                 commands+=("git commit -m '$message' -e -v -- $file $extra")
65         fi
66 done < <(git status --porcelain)
67
68 for cmd in "${commands[@]}"; do
69         eval "$cmd"
70 done
71