Skip to content

Commit eca5438

Browse files
Ethan0456ttaylorr
authored andcommitted
blame: respect .git-blame-ignore-revs automatically
git-blame(1) can ignore a list of commits with `--ignore-revs-file`. This is useful for marking uninteresting commits like formatting changes, refactors and whatever else should not be “blamed”. Some projects even version control this file so that all contributors can use it; the conventional name is `.git-blame-ignore-revs`. But each user still has to opt-in to the standard ignore list, either with this option or with the config `blame.ignoreRevsFile`. Let’s teach git-blame(1) to respect this conventional file in order to streamline the process. Signed-off-by: Abhijeetsingh Meena <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent ef8ce8f commit eca5438

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

builtin/blame.c

Lines changed: 8 additions & 0 deletions
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;
Lines changed: 26 additions & 0 deletions
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)