From 610e2b924020fe2d6a55e7ca6651f309b85c2d1d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 24 Sep 2020 21:55:04 -0700 Subject: blame: validate and peel the object names on the ignore list The command reads list of object names to place on the ignore list either from the command line or from a file, but they are not checked with their object type (those read from the file are not even checked for object existence). Extend the oidset_parse_file() API and allow it to take a callback that can be used to die (e.g. when an inappropriate input is read) or modify the object name read (e.g. when a tag pointing at a commit is read, and the caller wants a commit object name), and use it in the code that handles ignore list. Signed-off-by: Junio C Hamano --- t/t8013-blame-ignore-revs.sh | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 't') diff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh index 67de83ae2b..24ae5018e8 100755 --- a/t/t8013-blame-ignore-revs.sh +++ b/t/t8013-blame-ignore-revs.sh @@ -21,6 +21,7 @@ test_expect_success setup ' test_tick && git commit -m X && git tag X && + git tag -a -m "X (annotated)" XT && git blame --line-porcelain file >blame_raw && @@ -33,19 +34,35 @@ test_expect_success setup ' test_cmp expect actual ' -# Ignore X, make sure A is blamed for line 1 and B for line 2. -test_expect_success ignore_rev_changing_lines ' - git blame --line-porcelain --ignore-rev X file >blame_raw && - - grep -E "^[0-9a-f]+ [0-9]+ 1" blame_raw | sed -e "s/ .*//" >actual && - git rev-parse A >expect && - test_cmp expect actual && +# Ensure bogus --ignore-rev requests are caught +test_expect_success 'validate --ignore-rev' ' + test_must_fail git blame --ignore-rev X^{tree} file +' - grep -E "^[0-9a-f]+ [0-9]+ 2" blame_raw | sed -e "s/ .*//" >actual && - git rev-parse B >expect && - test_cmp expect actual +# Ensure bogus --ignore-revs-file requests are caught +test_expect_success 'validate --ignore-revs-file' ' + git rev-parse X^{tree} >ignore_x && + test_must_fail git blame --ignore-revs-file ignore_x file ' +for I in X XT +do + # Ignore X (or XT), make sure A is blamed for line 1 and B for line 2. + # Giving X (i.e. commit) and XT (i.e. annotated tag to commit) should + # produce the same result. + test_expect_success "ignore_rev_changing_lines ($I)" ' + git blame --line-porcelain --ignore-rev $I file >blame_raw && + + grep -E "^[0-9a-f]+ [0-9]+ 1" blame_raw | sed -e "s/ .*//" >actual && + git rev-parse A >expect && + test_cmp expect actual && + + grep -E "^[0-9a-f]+ [0-9]+ 2" blame_raw | sed -e "s/ .*//" >actual && + git rev-parse B >expect && + test_cmp expect actual + ' +done + # For ignored revs that have added 'unblamable' lines, attribute those to the # ignored commit. # A--B--X--Y -- cgit v1.2.3