зеркало из https://github.com/microsoft/git.git
git-bisect: allow bisecting with only one bad commit.
This allows you to say: git bisect start git bisect bad $bad git bisect next to start bisection without knowing a good commit. This would have you try a commit that is half-way since the beginning of the history, which is rather wasteful if you already know a good commit, but if you don't (or your history is short enough that you do not care), there is no reason not to allow this. Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Родитель
4f50671699
Коммит
0a5280a9f4
|
@ -168,26 +168,40 @@ bisect_write_good() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bisect_next_check() {
|
bisect_next_check() {
|
||||||
next_ok=no
|
missing_good= missing_bad=
|
||||||
git show-ref -q --verify refs/bisect/bad &&
|
git show-ref -q --verify refs/bisect/bad || missing_bad=t
|
||||||
test -n "$(git for-each-ref "refs/bisect/good-*")" &&
|
test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
|
||||||
next_ok=yes
|
|
||||||
|
|
||||||
case "$next_ok,$1" in
|
case "$missing_good,$missing_bad,$1" in
|
||||||
no,) false ;;
|
,,*)
|
||||||
no,fail)
|
: have both good and bad - ok
|
||||||
THEN=''
|
;;
|
||||||
test -d "$GIT_DIR/refs/bisect" || {
|
*,)
|
||||||
echo >&2 'You need to start by "git bisect start".'
|
# do not have both but not asked to fail - just report.
|
||||||
THEN='then '
|
false
|
||||||
}
|
;;
|
||||||
echo >&2 'You '$THEN'need to give me at least one good' \
|
t,,good)
|
||||||
'and one bad revisions.'
|
# have bad but not good. we could bisect although
|
||||||
echo >&2 '(You can use "git bisect bad" and' \
|
# this is less optimum.
|
||||||
'"git bisect good" for that.)'
|
echo >&2 'Warning: bisecting only with a bad commit.'
|
||||||
exit 1 ;;
|
if test -t 0
|
||||||
|
then
|
||||||
|
printf >&2 'Are you sure [Y/n]? '
|
||||||
|
case "$(read yesno)" in [Nn]*) exit 1 ;; esac
|
||||||
|
fi
|
||||||
|
: bisect without good...
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
true ;;
|
THEN=''
|
||||||
|
test -d "$GIT_DIR/refs/bisect" || {
|
||||||
|
echo >&2 'You need to start by "git bisect start".'
|
||||||
|
THEN='then '
|
||||||
|
}
|
||||||
|
echo >&2 'You '$THEN'need to give me at least one good' \
|
||||||
|
'and one bad revisions.'
|
||||||
|
echo >&2 '(You can use "git bisect bad" and' \
|
||||||
|
'"git bisect good" for that.)'
|
||||||
|
exit 1 ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,27 +212,32 @@ bisect_auto_next() {
|
||||||
bisect_next() {
|
bisect_next() {
|
||||||
case "$#" in 0) ;; *) usage ;; esac
|
case "$#" in 0) ;; *) usage ;; esac
|
||||||
bisect_autostart
|
bisect_autostart
|
||||||
bisect_next_check fail
|
bisect_next_check good
|
||||||
|
|
||||||
bad=$(git-rev-parse --verify refs/bisect/bad) &&
|
bad=$(git-rev-parse --verify refs/bisect/bad) &&
|
||||||
good=$(git-rev-parse --sq --revs-only --not \
|
good=$(git for-each-ref --format='^%(objectname)' \
|
||||||
$(cd "$GIT_DIR" && ls refs/bisect/good-*)) &&
|
"refs/bisect/good-*" | tr '[\012]' ' ') &&
|
||||||
rev=$(eval "git-rev-list --bisect $good $bad -- $(cat "$GIT_DIR/BISECT_NAMES")") || exit
|
eval="git-rev-list --bisect-vars $good $bad --" &&
|
||||||
if [ -z "$rev" ]; then
|
eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" &&
|
||||||
echo "$bad was both good and bad"
|
eval=$(eval "$eval") &&
|
||||||
exit 1
|
eval "$eval" || exit
|
||||||
|
|
||||||
|
if [ -z "$bisect_rev" ]; then
|
||||||
|
echo "$bad was both good and bad"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ "$rev" = "$bad" ]; then
|
if [ "$bisect_rev" = "$bad" ]; then
|
||||||
echo "$rev is first bad commit"
|
echo "$bisect_rev is first bad commit"
|
||||||
git-diff-tree --pretty $rev
|
git-diff-tree --pretty $bisect_rev
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
nr=$(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" | wc -l) || exit
|
|
||||||
echo "Bisecting: $nr revisions left to test after this"
|
echo "Bisecting: $bisect_nr revisions left to test after this"
|
||||||
echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
|
echo "$bisect_rev" >"$GIT_DIR/refs/heads/new-bisect"
|
||||||
git checkout -q new-bisect || exit
|
git checkout -q new-bisect || exit
|
||||||
mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
|
mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
|
||||||
GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD refs/heads/bisect
|
GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD refs/heads/bisect
|
||||||
git-show-branch "$rev"
|
git-show-branch "$bisect_rev"
|
||||||
}
|
}
|
||||||
|
|
||||||
bisect_visualize() {
|
bisect_visualize() {
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#
|
#
|
||||||
test_description='Tests git-bisect functionality'
|
test_description='Tests git-bisect functionality'
|
||||||
|
|
||||||
|
exec </dev/null
|
||||||
|
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
add_line_into_file()
|
add_line_into_file()
|
||||||
|
@ -37,21 +39,14 @@ test_expect_success \
|
||||||
HASH3=$(git rev-list HEAD | head -2 | tail -1) &&
|
HASH3=$(git rev-list HEAD | head -2 | tail -1) &&
|
||||||
HASH4=$(git rev-list HEAD | head -1)'
|
HASH4=$(git rev-list HEAD | head -1)'
|
||||||
|
|
||||||
test_expect_success 'bisect does not start with only one bad' '
|
test_expect_success 'bisect starts with only one bad' '
|
||||||
git bisect reset &&
|
git bisect reset &&
|
||||||
git bisect start &&
|
git bisect start &&
|
||||||
git bisect bad $HASH4 || return 1
|
git bisect bad $HASH4 &&
|
||||||
|
git bisect next
|
||||||
if git bisect next
|
|
||||||
then
|
|
||||||
echo Oops, should have failed.
|
|
||||||
false
|
|
||||||
else
|
|
||||||
:
|
|
||||||
fi
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'bisect does not start with only one good' '
|
test_expect_success 'bisect starts with only one good' '
|
||||||
git bisect reset &&
|
git bisect reset &&
|
||||||
git bisect start &&
|
git bisect start &&
|
||||||
git bisect good $HASH1 || return 1
|
git bisect good $HASH1 || return 1
|
||||||
|
|
Загрузка…
Ссылка в новой задаче