git/t/t4064-diff-oidfind.sh

69 строки
1.4 KiB
Bash
Исходник Обычный вид История

diffcore: add a pickaxe option to find a specific blob Sometimes users are given a hash of an object and they want to identify it further (ex.: Use verify-pack to find the largest blobs, but what are these? or [1]) One might be tempted to extend git-describe to also work with blobs, such that `git describe <blob-id>` gives a description as '<commit-ish>:<path>'. This was implemented at [2]; as seen by the sheer number of responses (>110), it turns out this is tricky to get right. The hard part to get right is picking the correct 'commit-ish' as that could be the commit that (re-)introduced the blob or the blob that removed the blob; the blob could exist in different branches. Junio hinted at a different approach of solving this problem, which this patch implements. Teach the diff machinery another flag for restricting the information to what is shown. For example: $ ./git log --oneline --find-object=v2.0.0:Makefile b2feb64309 Revert the whole "ask curl-config" topic for now 47fbfded53 i18n: only extract comments marked with "TRANSLATORS:" we observe that the Makefile as shipped with 2.0 was appeared in v1.9.2-471-g47fbfded53 and in v2.0.0-rc1-5-gb2feb6430b. The reason why these commits both occur prior to v2.0.0 are evil merges that are not found using this new mechanism. [1] https://stackoverflow.com/questions/223678/which-commit-has-this-blob [2] https://public-inbox.org/git/20171028004419.10139-1-sbeller@google.com/ Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-01-05 01:50:42 +03:00
#!/bin/sh
test_description='test finding specific blobs in the revision walking'
. ./test-lib.sh
test_expect_success 'setup ' '
git commit --allow-empty -m "empty initial commit" &&
echo "Hello, world!" >greeting &&
git add greeting &&
git commit -m "add the greeting blob" && # borrowed from Git from the Bottom Up
git tag -m "the blob" greeting $(git rev-parse HEAD:greeting) &&
echo asdf >unrelated &&
git add unrelated &&
git commit -m "unrelated history" &&
git revert HEAD^ &&
git commit --allow-empty -m "another unrelated commit"
'
test_expect_success 'find the greeting blob' '
cat >expect <<-EOF &&
Revert "add the greeting blob"
add the greeting blob
EOF
git log --format=%s --find-object=greeting^{blob} >actual &&
test_cmp expect actual
'
test_expect_success 'setup a tree' '
mkdir a &&
echo asdf >a/file &&
git add a/file &&
git commit -m "add a file in a subdirectory"
'
test_expect_success 'find a tree' '
cat >expect <<-EOF &&
add a file in a subdirectory
EOF
git log --format=%s -t --find-object=HEAD:a >actual &&
test_cmp expect actual
'
test_expect_success 'setup a submodule' '
test_create_repo sub &&
test_commit -C sub sub &&
git submodule add ./sub sub &&
git commit -a -m "add sub"
'
test_expect_success 'find a submodule' '
cat >expect <<-EOF &&
add sub
EOF
git log --format=%s --find-object=HEAD:sub >actual &&
test_cmp expect actual
'
test_done