Skip to content

Commit

Permalink
bisect: fix replay of CRLF logs
Browse files Browse the repository at this point in the history
Sometimes bisect logs have CRLF newlines. (E.g., if they've been edited
on a Windows machine and their LF-only nature wasn't preserved.)
Previously, such log files would cause odd failures deep in the guts of
git bisect, like "?? what are you talking about?" or "couldn't get the
oid of the rev '...?'" (notice the trailing ?) as each line's CR ends up
part of the final value read from the log.

This commit fixes that by stripping CRs from the log before further
processing.

A regression test that fails without the git-bisect.sh change, "bisect
replay with CRLF log" has been added as well.

Were anyone to intentionally be using terms/revs with embedded CRs,
replaying such bisects will no longer work with this change. I suspect
that this is incredibly rare.

Signed-off-by: Christopher Warrington <chwarr@microsoft.com>
  • Loading branch information
chwarr committed May 7, 2020
1 parent af6b65d commit dbdb691
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions git-bisect.sh
Expand Up @@ -209,7 +209,11 @@ bisect_replay () {
test "$#" -eq 1 || die "$(gettext "No logfile given")"
test -r "$file" || die "$(eval_gettext "cannot read \$file for replaying")"
git bisect--helper --bisect-reset || exit
while read git bisect command rev

# We remove any CR in the input to handle bisect log files that have
# CRLF line endings. The assumption is that CR within bisect
# commands also don't matter.
tr -d '\r' <"$file" | while read git bisect command rev
do
test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue
if test "$git" = "git-bisect"
Expand All @@ -231,7 +235,9 @@ bisect_replay () {
*)
die "$(gettext "?? what are you talking about?")" ;;
esac
done <"$file"
done

get_terms
bisect_auto_next
}

Expand Down
7 changes: 7 additions & 0 deletions t/t6030-bisect-porcelain.sh
Expand Up @@ -792,6 +792,13 @@ test_expect_success 'bisect replay with old and new' '
git bisect reset
'

test_expect_success 'bisect replay with CRLF log' '
awk 1 "ORS=\\r\\n" <log_to_replay.txt >log_to_replay_crlf.txt &&
git bisect replay log_to_replay_crlf.txt >bisect_result_crlf &&
grep "$HASH2 is the first new commit" bisect_result_crlf &&
git bisect reset
'

test_expect_success 'bisect cannot mix old/new and good/bad' '
git bisect start &&
git bisect bad $HASH4 &&
Expand Down

1 comment on commit dbdb691

@mfc-pbl-game
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Search:Open

t/t6030-bisect-porcelain.sh

Please sign in to comment.