Skip to content

Commit 1aac6b5

Browse files
committed
blame: respect .git-blame-ignore-revs automatically
Modify `git blame` to automatically respect a `.git-blame-ignore-revs` file if it exists in the repository. This file is used by many projects to ignore non-functional changes, such as reformatting or large-scale refactoring, when generating blame information. Before this change, users had to manually specify the file with the `--ignore-revs-file` option. This update streamlines the process by automatically detecting the `.git-blame-ignore-revs` file, reducing manual effort. This change aligns with the standardized practice in many repositories and simplifies the workflow for users. Signed-off-by: Abhijeetsingh Meena <[email protected]>
1 parent 777489f commit 1aac6b5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

builtin/blame.c

+8
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,14 @@ int cmd_blame(int argc,
11051105
add_pending_object(&revs, &head_commit->object, "HEAD");
11061106
}
11071107

1108+
/*
1109+
* By default, add .git-blame-ignore-revs to the list of files
1110+
* containing revisions to ignore if it exists.
1111+
*/
1112+
if (access(".git-blame-ignore-revs", F_OK) == 0) {
1113+
string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
1114+
}
1115+
11081116
init_scoreboard(&sb);
11091117
sb.revs = &revs;
11101118
sb.contents_from = contents_from;

t/t8015-blame-default-ignore-revs.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
test_description='default revisions to ignore when blaming'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
6+
. ./test-lib.sh
7+
8+
test_expect_success 'blame: default-ignore-revs-file' '
9+
test_commit first-commit hello.txt hello &&
10+
11+
echo world >>hello.txt &&
12+
test_commit second-commit hello.txt &&
13+
14+
sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
15+
mv hello.txt.tmp hello.txt &&
16+
test_commit third-commit hello.txt &&
17+
18+
git rev-parse HEAD >ignored-file &&
19+
git blame --ignore-revs-file=ignored-file hello.txt >expect &&
20+
git rev-parse HEAD >.git-blame-ignore-revs &&
21+
git blame hello.txt >actual &&
22+
23+
test_cmp expect actual
24+
'
25+
26+
test_done

0 commit comments

Comments
 (0)