Skip to content

Commit

Permalink
blame: respect .git-blame-ignore-revs automatically
Browse files Browse the repository at this point in the history
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 <abhijeet040403@gmail.com>
  • Loading branch information
Ethan0456 committed Oct 7, 2024
1 parent 777489f commit 1aac6b5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions t/t8015-blame-default-ignore-revs.sh
Original file line number Diff line number Diff line change
@@ -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 > 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

0 comments on commit 1aac6b5

Please sign in to comment.