Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions diffcore-rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filepair *p)
{
/* Lookup by p->ONE->path */
int idx = break_idx ? strintmap_get(break_idx, p->one->path) : -1;
return (idx == -1) ? NULL : &rename_dst[idx];
return (idx == -1 || idx == rename_dst_nr) ? NULL : &rename_dst[idx];
}

/*
Expand Down Expand Up @@ -1668,9 +1668,10 @@ void diffcore_rename_extended(struct diff_options *options,
if (DIFF_PAIR_BROKEN(p)) {
/* broken delete */
struct diff_rename_dst *dst = locate_rename_dst(p);
if (!dst)
BUG("tracking failed somehow; failed to find associated dst for broken pair");
if (dst->is_rename)
if (options->single_follow && dst &&
strcmp(dst->p->two->path, p->two->path))
dst = NULL;
if (dst && dst->is_rename)
/* counterpart is now rename/copy */
pair_to_free = p;
}
Expand Down
32 changes: 32 additions & 0 deletions t/t4206-log-follow-harder-copies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,36 @@ test_expect_success 'validate the output.' '
compare_diff_patch current expected
'

test_expect_success 'log --follow -B does not BUG' '
git switch --orphan break_and_follow_are_icky_so_use_both &&

test_seq 1 127 >numbers &&
git add numbers &&
git commit -m "numbers" &&

printf "%s\n" A B C D E F G H I J K L M N O Q R S T U V W X Y Z >pool &&
echo changed >numbers &&
git add pool numbers &&
git commit -m "pool" &&

git log -1 -B --raw --follow -- "p*"
'

test_expect_success 'log --follow -B does not die or use uninitialized memory' '
printf "%s\n" A B C D E F G H I J K L M N O P Q R S T U V W X Y Z >z &&
git add z &&
git commit -m "Initial" &&

test_seq 1 130 >z &&
echo lame >somefile &&
git add z somefile &&
git commit -m "Rewrite z, introduce lame somefile" &&

echo Content >somefile &&
git add somefile &&
git commit -m "Rewrite somefile" &&

git log -B --follow somefile
'

test_done
Loading