Expected behaviour of 'git log -S' when searching in a merged/deleted file?
- From
Jonathan del Strother <jdelstrother@gmail.com>
- Date
- Dec 22, 2010, 13:37 UTC
- Message-ID
- <AANLkTimXk6ei6EAQfvTTfnMzdBqYHkNoaxkEab+atnHd@mail.gmail.com>
Hi,
I was trying to find a particular string in my project this morning. 'git grep mystring' suggested that the string didn't exist in my repo, but 'git log -Smystring' turned up a single commit that had added it. It took me a long time to figure out that in the past, a branch had added that string to foo.c, but a second branch deleted foo.c, and the two branches were later merged (deleting foo.c and ignoring mystring). I was surprised that 'git log -S' didn't show the merge commit as the point at which the string had been removed.
I've attached a testcase which I would expect to pass (perhaps naively), but doesn't. Is this a git bug, or do I misunderstand git log -S?
--
#!/bin/sh
test_description='git log'
. ./test-lib.sh
test_expect_success setup ' echo haystack\\nhaystack\\nhaystack\\nhaystack\\n > haystack && git add haystack && test_tick && git commit -m initial &&
git checkout -b branchA && echo needle >haystack && git add haystack && test_tick && git commit -m "adding needle" &&
git checkout -b branchB HEAD~1 && git rm haystack && test_tick && git commit -m "removing haystack" &&
git merge branchA || git rm haystack && test_tick && git commit -m "merging: haystack and needle removed" '
printf "merging: haystack and needle removed\nadding needle" > expect test_expect_success 'log -S in a merge-deleted file' '
git log -Sneedle --pretty="format:%s" > actual && test_cmp expect actual '
test_done