3 # Copyright (c) Josef "Jeff" Sipek, 2006
8 local d
=`git-rev-parse --git-dir`
10 if [ $?
-ne 0 -o -z "$d" ]; then
11 echo "Not a git repository" >&2
20 git-symbolic-ref HEAD |
sed -e 's,^refs/heads/,,'
23 function verify_branch
27 [ ! -d "$GIT_DIR/patches" ] &&
28 echo "Patches directory doesn't exist, try gq-init" >&2 &&
30 [ ! -d "$GIT_DIR/patches/$b" ] &&
31 echo "Branch $b is not initialized, try gq-init" >&2 &&
33 [ ! -f "$GIT_DIR/patches/$b/series" ] &&
34 echo "Branch $b does not have a series file" >&2 &&
36 [ ! -f "$GIT_DIR/patches/$b/status" ] &&
37 echo "Branch $b does not have a status file" >&2 &&
39 [ -f "$GIT_DIR/patches/$b/applied" ] &&
40 echo "Warning: Branch $b has 'applied' file - gq is not compatible with stgit" >&2 &&
48 tail -1 $GQ_DIR/$branch/status
53 local n
=`wc -l < $GQ_DIR/$branch/status`
57 for p
in `cat $GQ_DIR/$branch/status`; do
59 [ $idx -lt $n ] && continue
60 [ $idx -gt $n ] && break
66 # usage: index_update_magic
67 function index_update_magic
70 fil
=`echo $l | cut -d: -f 2`
71 git-update-index
--add --remove "$fil"
75 # usage: do_get_header patchfile
76 function do_get_header
78 cat $1 |
awk 'BEGIN{ok=1}/^(diff|---)/{ok=0}{if (ok==1) print $0}'
84 git
reset --hard HEAD^
86 head -n -1 < $applied > $applied.tmp
90 # usage: push_patch patchname
93 local p
="$GQ_DIR/$branch/$1"
98 # apply the patch if and only if there is something to apply
99 if [ `wc -l < $p` -gt 0 ]; then
100 git-apply
--reject $p > /dev
/null
2> /tmp
/gq.log.$$
102 [ $bail -ne 0 ] && cat /tmp
/gq.log.$$
104 [ $bail -ne 0 ] && cat /tmp
/gq.log.$$
>&2
106 ( git-apply
--numstat $p |
awk '{print "changed:" $3}';
107 #git-apply --summary $p | awk '
108 # /^ (create|delete)/{print $1 ":" $4}
109 # /^ mode change/{print "mode:" $6}'
110 )| index_update_magic
113 # grab a commit message out of the patch
114 do_get_header
$p > /tmp
/gq.msg.$$
116 # make a default commit message if patch doesn't contain one
117 [ ! -s /tmp
/gq.msg.$$
] && echo "patch $pname" > /tmp
/gq.msg.$$
120 local treeish
=`git-write-tree`
121 local commitish
=`git-commit-tree $treeish -p HEAD < /tmp/gq.msg.$$`
122 echo $commitish > $GIT_DIR/`git-symbolic-ref HEAD`
124 rm -f /tmp
/gq.msg.$$
/tmp
/gq.log.$$
129 # usage: must_commit_first
130 function must_commit_first
132 [ `git-diff-files | wc -l` -eq 0 ]
136 # usage: refresh_patch patchname
137 function refresh_patch
139 local p
="$GQ_DIR/$branch/$1"
141 git-diff-files
--name-only |
(while read n
; do git-update-index
$n ; done)
143 # get the patch header
144 do_get_header
$p > /tmp
/gq.
diff.$$
147 git-diff HEAD^
>> /tmp
/gq.
diff.$$
149 # drop the current commit
150 git-reset
--hard HEAD^
152 # move the new patch in
154 mv /tmp
/gq.
diff.$$
$p
160 # The following gets run every time this file is source'd
163 export GIT_DIR
=`find_git_dir`
164 [ $?
-ne 0 ] && exit 1
166 GQ_DIR
="$GIT_DIR/patches"
170 # most of the time we want to verify that the repo's branch has been
171 # initialized, but every once in a blue moon (e.g., we want to run gq-init),
172 # we must avoid the checks
173 if [ -z "$DO_NOT_CHECK_BRANCH_EXISTENCE" ]; then
174 verify_branch ||
exit 1
178 series
="$GQ_DIR/$branch/series"
179 applied
="$GQ_DIR/$branch/status"