chiark / gitweb /
86050082f1d38bc1ceb5f9ecb6472556530bbebd
[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         ?.-*)
60                 fail "UNKNOWN OPTION $arg ($*)"
61                 ;;
62         0.apply)
63                 ;;
64         1.*)    patch="$arg"
65                 ;;
66         *)
67                 fail "BAD USAGE $arg ($noo $*)"
68         esac
69         noo=$(( $noo + 1 ))
70 done
71
72 if [ $noo != 2 ]; then
73         fail "NO PATCH ($*)"
74 fi
75
76 pwd=`pwd`
77 patch=${patch#$pwd/debian/patches/}
78 rm -f debian/patches/series
79 printf "%s\n" "$patch" >debian/patches/series
80
81 dpkg-source --before-build .
82
83 rm -rf .pc
84 git checkout debian/patches/series
85 git add -Af .
86
87 log "APPLIED $patch"
88 #printf 'APPLIED '; date --iso-8601=ns