3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
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 guilt-init" >&2 &&
30 [ ! -d "$GIT_DIR/patches/$b" ] &&
31 echo "Branch $b is not initialized, try guilt-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 - guilt is not compatible with stgit" >&2 &&
48 tail -1 $GUILT_DIR/$branch/status
53 local n
=`wc -l < $GUILT_DIR/$branch/status`
57 for p
in `cat $GUILT_DIR/$branch/status`; do
59 [ $idx -lt $n ] && continue
60 [ $idx -gt $n ] && break
68 # ignore all lines matching:
71 # - optional whitespace followed by '#' followed by more
73 grep -ve '^[[:space:]]*\(#.*\)*$' < $series
76 # usage: index_update_magic
77 function index_update_magic
80 fil
=`echo $l | cut -d: -f 2`
81 git-update-index
--add --remove "$fil"
85 # usage: do_get_header patchfile
86 function do_get_header
88 cat $1 |
awk 'BEGIN{ok=1}/^(diff|---)/{ok=0}{if (ok==1) print $0}'
94 git
reset --hard HEAD^
96 head -n -1 < $applied > $applied.tmp
100 # usage: push_patch patchname
103 local p
="$GUILT_DIR/$branch/$1"
108 # apply the patch if and only if there is something to apply
109 if [ `wc -l < $p` -gt 0 ]; then
110 git-apply
--reject $p > /dev
/null
2> /tmp
/guilt.log.$$
112 [ $bail -ne 0 ] && cat /tmp
/guilt.log.$$
114 [ $bail -ne 0 ] && cat /tmp
/guilt.log.$$
>&2
116 ( git-apply
--numstat $p |
awk '{print "changed:" $3}';
117 #git-apply --summary $p | awk '
118 # /^ (create|delete)/{print $1 ":" $4}
119 # /^ mode change/{print "mode:" $6}'
120 )| index_update_magic
123 # grab a commit message out of the patch
124 do_get_header
$p > /tmp
/guilt.msg.$$
126 # make a default commit message if patch doesn't contain one
127 [ ! -s /tmp
/guilt.msg.$$
] && echo "patch $pname" > /tmp
/guilt.msg.$$
130 local treeish
=`git-write-tree`
131 local commitish
=`git-commit-tree $treeish -p HEAD < /tmp/guilt.msg.$$`
132 echo $commitish > $GIT_DIR/`git-symbolic-ref HEAD`
134 rm -f /tmp
/guilt.msg.$$
/tmp
/guilt.log.$$
139 # usage: must_commit_first
140 function must_commit_first
142 [ `git-diff-files | wc -l` -eq 0 ]
146 # usage: refresh_patch patchname
147 function refresh_patch
149 local p
="$GUILT_DIR/$branch/$1"
151 git-diff-files
--name-only |
(while read n
; do git-update-index
$n ; done)
153 # get the patch header
154 do_get_header
$p > /tmp
/guilt.
diff.$$
157 git-diff HEAD^
>> /tmp
/guilt.
diff.$$
159 # drop the current commit
160 git-reset
--hard HEAD^
162 # move the new patch in
164 mv /tmp
/guilt.
diff.$$
$p
170 # The following gets run every time this file is source'd
173 export GIT_DIR
=`find_git_dir`
174 [ $?
-ne 0 ] && exit 1
176 GUILT_DIR
="$GIT_DIR/patches"
180 # most of the time we want to verify that the repo's branch has been
181 # initialized, but every once in a blue moon (e.g., we want to run guilt-init),
182 # we must avoid the checks
183 if [ -z "$DO_NOT_CHECK_BRANCH_EXISTENCE" ]; then
184 verify_branch ||
exit 1
188 series
="$GUILT_DIR/$branch/series"
189 applied
="$GUILT_DIR/$branch/status"