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