chiark / gitweb /
git-debrebase: comment: explain why tagged linear anchors are evil
[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
83 # Work around #848611.
84 # We need a stunt filename which the source package must not
85 # contain.  A trick is to use the commit hash of HEAD, whose
86 # hash value cannot appear in any file in its own tree.
87 omgwtf="dgit-omg-wtf-$(git rev-parse HEAD)"
88 cat <<END >debian/patches/$omgwtf
89 ---
90 --- a/$omgwtf   2016-10-31 23:28:47.314155919 +0000
91 +++ b/$omgwtf   2016-12-18 22:40:01.870058270 +0000
92 @@ -0,0 +1 @@
93 +:
94 END
95 printf "%s\n" "$omgwtf" >debian/patches/series
96 printf "%s\n" "$patch" >>debian/patches/series
97
98 # Just in case some joker tries to patch .git/something
99 mv .git ../.git
100 set +e
101 dpkg-source --before-build .
102 rc=$?
103 set -e
104 rm -rf .git
105 mv ../.git .
106 test $rc = 0
107
108 rm -f $omgwtf debian/patches/$omgwtf
109
110 rm -rf .pc
111 git checkout debian/patches/series
112 git add -Af .
113
114 log "APPLIED $patch"
115 #printf 'APPLIED '; date --iso-8601=ns