chiark / gitweb /
Produce better error reporting when absurd git wrapper fails on a patch
[dgit.git] / absurd / git
1 #!/bin/sh
2 set -e
3
4 case "$DGIT_ABSURD_DEBUG" in
5 ''|0)   exec 3>/dev/null ;;
6 1)      exec 3>>../../gbp-pq-output ;;
7 *)      exec 3>>../../gbp-pq-output 2>&3 ;;
8 esac
9
10 log () {
11         echo >&3 "DGIT ABSURD GIT APPLY (DEBUG)  $*"
12         echo >&2 "DGIT ABSURD GIT APPLY (STDERR) $*"
13 }
14
15 fail () {
16         log "FAILED: $*"
17         exit 127
18 }
19
20 self=${0%/*}
21 npath=${PATH#$self:}
22 if test "x$PATH" = "x$npath"; then
23         fail "PATH FILTER FAIL ($0 $self $PATH)"
24 fi
25
26 bypass=true
27 for arg in "$@"; do
28         case "$arg" in
29         apply)  bypass=false; break     ;;
30         -*)                             ;;
31         *)      bypass=true; break      ;;
32         esac
33 done
34
35 if $bypass; then
36         PATH=$npath
37         echo >&3 "DGIT ABSURD GIT APPLY - BYPASS: $*"
38         exec git "$@"
39 fi
40
41 log "NO BYPASS: $*"
42
43 case "$DGIT_ABSURD_DEBUG" in
44 ''|0|1) ;;
45 *)      set -x ;;
46 esac
47
48 #exec >/dev/tty 2>&1
49
50 index=0
51 noo=0
52
53 for arg in "$@"; do
54         case "$noo.$arg" in
55         1.--index)
56                 index=1
57                 continue
58                 ;;
59         1.--whitespace=fix)
60                 continue
61                 ;;
62         ?.-*)
63                 fail "UNKNOWN OPTION $arg ($*)"
64                 ;;
65         0.apply)
66                 ;;
67         1.*)    patch="$arg"
68                 ;;
69         *)
70                 fail "BAD USAGE $arg ($noo $*)"
71         esac
72         noo=$(( $noo + 1 ))
73 done
74
75 if [ $noo != 2 ]; then
76         fail "NO PATCH ($*)"
77 fi
78
79 pwd=`pwd`
80 patch=${patch#$pwd/debian/patches/}
81 rm -f debian/patches/series
82 printf "%s\n" "$patch" >debian/patches/series
83
84 dpkg-source --before-build .
85
86 rm -rf .pc
87 git checkout debian/patches/series
88 git add -Af .
89
90 log "APPLIED $patch"
91 #printf 'APPLIED '; date --iso-8601=ns