chiark / gitweb /
cab0320cc094ba1e6e486eeb0b86c27bdbe66c48
[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 exec 4>>../../absurd-apply-warnings
11
12 log () {
13         echo >&3 "DGIT ABSURD GIT APPLY (DEBUG)  $*"
14         echo >&2 "DGIT ABSURD GIT APPLY (STDERR) $*"
15 }
16
17 fail () {
18         log "FAILED: $*"
19         exit 127
20 }
21
22 self=${0%/*}
23 npath=${PATH#$self:}
24 if test "x$PATH" = "x$npath"; then
25         fail "PATH FILTER FAIL ($0 $self $PATH)"
26 fi
27
28 bypass=true
29 for arg in "$@"; do
30         case "$arg" in
31         apply)  bypass=false; break     ;;
32         -*)                             ;;
33         *)      bypass=true; break      ;;
34         esac
35 done
36
37 if $bypass; then
38         PATH=$npath
39         echo >&3 "DGIT ABSURD GIT APPLY - BYPASS: $*"
40         exec git "$@"
41 fi
42
43 log "NO BYPASS: $*"
44
45 case "$DGIT_ABSURD_DEBUG" in
46 ''|0|1) ;;
47 *)      set -x ;;
48 esac
49
50 #exec >/dev/tty 2>&1
51
52 index=0
53 noo=0
54
55 for arg in "$@"; do
56         case "$noo.$arg" in
57         1.--index)
58                 index=1
59                 continue
60                 ;;
61         1.--whitespace=fix)
62                 continue
63                 ;;
64         ?.-*)
65                 fail "UNKNOWN OPTION $arg ($*)"
66                 ;;
67         0.apply)
68                 ;;
69         1.*)    patch="$arg"
70                 ;;
71         *)
72                 fail "BAD USAGE $arg ($noo $*)"
73         esac
74         noo=$(( $noo + 1 ))
75 done
76
77 if [ $noo != 2 ]; then
78         fail "NO PATCH ($*)"
79 fi
80
81 pwd=`pwd`
82 patch=${patch#$pwd/debian/patches/}
83 rm -f debian/patches/series
84
85 # Work around #848611.
86 # We need a stunt filename which the source package must not
87 # contain.  A trick is to use the commit hash of HEAD, whose
88 # hash value cannot appear in any file in its own tree.
89 omgwtf="dgit-omg-wtf-$(git rev-parse HEAD)"
90 cat <<END >debian/patches/$omgwtf
91 ---
92 --- a/$omgwtf   2016-10-31 23:28:47.314155919 +0000
93 +++ b/$omgwtf   2016-12-18 22:40:01.870058270 +0000
94 @@ -0,0 +1 @@
95 +:
96 END
97 printf "%s\n" "$omgwtf" >debian/patches/series
98 printf "%s\n" "$patch" >>debian/patches/series
99
100 # Just in case some joker tries to patch .git/something
101 mv .git ../.git
102 set +e
103 dpkg-source --before-build .
104 rc=$?
105 set -e
106 rm -rf .git
107 mv ../.git .
108 test $rc = 0
109
110 rm -f $omgwtf debian/patches/$omgwtf
111
112 rm -rf .pc
113 git checkout debian/patches/series
114 git add -Af .
115
116 log "APPLIED $patch"
117 #printf 'APPLIED '; date --iso-8601=ns