Skip to content

Commit 810255f

Browse files
Petr BaudisJunio C Hamano
authored andcommitted
Properly git-bisect reset after bisecting from non-master head
git-bisect reset without an argument would return to master even if the bisecting started at a non-master branch. This patch makes it save the original branch name to .git/head-name and restore it afterwards. This is also compatible with Cogito and cg-seek, so cg-status will show that we are seeked on the bisect branch and cg-reset will properly restore the original branch. git-bisect start will refuse to work if it is not on a bisect but .git/head-name exists; this is to protect against conflicts with other seeking tools. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent c5e09c1 commit 810255f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

git-bisect.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ bisect_start() {
4949
die "Bad HEAD - I need a symbolic ref"
5050
case "$head" in
5151
refs/heads/bisect*)
52-
git checkout master || exit
52+
if [ -s "$GIT_DIR/head-name" ]; then
53+
branch=`cat "$GIT_DIR/head-name"`
54+
else
55+
branch=master
56+
fi
57+
git checkout $branch || exit
5358
;;
5459
refs/heads/*)
60+
[ -s "$GIT_DIR/head-name" ] && die "won't bisect on seeked tree"
61+
echo "$head" | sed 's#^refs/heads/##' >"$GIT_DIR/head-name"
5562
;;
5663
*)
5764
die "Bad HEAD - strange symbolic ref"
@@ -159,7 +166,11 @@ bisect_visualize() {
159166

160167
bisect_reset() {
161168
case "$#" in
162-
0) branch=master ;;
169+
0) if [ -s "$GIT_DIR/head-name" ]; then
170+
branch=`cat "$GIT_DIR/head-name"`
171+
else
172+
branch=master
173+
fi ;;
163174
1) test -f "$GIT_DIR/refs/heads/$1" || {
164175
echo >&2 "$1 does not seem to be a valid branch"
165176
exit 1
@@ -170,7 +181,7 @@ bisect_reset() {
170181
esac
171182
git checkout "$branch" &&
172183
rm -fr "$GIT_DIR/refs/bisect"
173-
rm -f "$GIT_DIR/refs/heads/bisect"
184+
rm -f "$GIT_DIR/refs/heads/bisect" "$GIT_DIR/head-name"
174185
rm -f "$GIT_DIR/BISECT_LOG"
175186
}
176187

0 commit comments

Comments
 (0)