diff --git a/builtin/blame.c b/builtin/blame.c index e407a22da3bacf..1eddabaf60f4ea 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1105,6 +1105,14 @@ int cmd_blame(int argc, add_pending_object(&revs, &head_commit->object, "HEAD"); } + /* + * By default, add .git-blame-ignore-revs to the list of files + * containing revisions to ignore if it exists. + */ + if (access(".git-blame-ignore-revs", F_OK) == 0) { + string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs"); + } + init_scoreboard(&sb); sb.revs = &revs; sb.contents_from = contents_from; diff --git a/t/t8015-blame-default-ignore-revs.sh b/t/t8015-blame-default-ignore-revs.sh new file mode 100755 index 00000000000000..d4ab686f14d2ad --- /dev/null +++ b/t/t8015-blame-default-ignore-revs.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +test_description='default revisions to ignore when blaming' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +test_expect_success 'blame: default-ignore-revs-file' ' + test_commit first-commit hello.txt hello && + + echo world >>hello.txt && + test_commit second-commit hello.txt && + + sed "1s/hello/hi/" hello.txt.tmp && + mv hello.txt.tmp hello.txt && + test_commit third-commit hello.txt && + + git rev-parse HEAD >ignored-file && + git blame --ignore-revs-file=ignored-file hello.txt >expect && + git rev-parse HEAD >.git-blame-ignore-revs && + git blame hello.txt >actual && + + test_cmp expect actual +' + +test_done