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