ci: skip GitHub workflow runs for already-tested commits/trees
[git.git] / t / t8002-blame.sh
blob015973e8fe227e91f9dff8f9c6b08d298670f1ac
1 #!/bin/sh
3 test_description='git blame'
4 . ./test-lib.sh
6 PROG='git blame -c'
7 . "$TEST_DIRECTORY"/annotate-tests.sh
9 test_expect_success 'setup' '
10 hexsz=$(test_oid hexsz)
13 test_expect_success 'blame untracked file in empty repo' '
14 >untracked &&
15 test_must_fail git blame untracked
18 PROG='git blame -c -e'
19 test_expect_success 'blame --show-email' '
20 check_count \
21 "<A@test.git>" 1 \
22 "<B@test.git>" 1 \
23 "<B1@test.git>" 1 \
24 "<B2@test.git>" 1 \
25 "<author@example.com>" 1 \
26 "<C@test.git>" 1 \
27 "<D@test.git>" 1 \
28 "<E at test dot git>" 1
31 test_expect_success 'setup showEmail tests' '
32 echo "bin: test number 1" >one &&
33 git add one &&
34 GIT_AUTHOR_NAME=name1 \
35 GIT_AUTHOR_EMAIL=email1@test.git \
36 git commit -m First --date="2010-01-01 01:00:00" &&
37 cat >expected_n <<-\EOF &&
38 (name1 2010-01-01 01:00:00 +0000 1) bin: test number 1
39 EOF
40 cat >expected_e <<-\EOF
41 (<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1
42 EOF
45 find_blame () {
46 sed -e 's/^[^(]*//'
49 test_expect_success 'blame with no options and no config' '
50 git blame one >blame &&
51 find_blame <blame >result &&
52 test_cmp expected_n result
55 test_expect_success 'blame with showemail options' '
56 git blame --show-email one >blame1 &&
57 find_blame <blame1 >result &&
58 test_cmp expected_e result &&
59 git blame -e one >blame2 &&
60 find_blame <blame2 >result &&
61 test_cmp expected_e result &&
62 git blame --no-show-email one >blame3 &&
63 find_blame <blame3 >result &&
64 test_cmp expected_n result
67 test_expect_success 'blame with showEmail config false' '
68 git config blame.showEmail false &&
69 git blame one >blame1 &&
70 find_blame <blame1 >result &&
71 test_cmp expected_n result &&
72 git blame --show-email one >blame2 &&
73 find_blame <blame2 >result &&
74 test_cmp expected_e result &&
75 git blame -e one >blame3 &&
76 find_blame <blame3 >result &&
77 test_cmp expected_e result &&
78 git blame --no-show-email one >blame4 &&
79 find_blame <blame4 >result &&
80 test_cmp expected_n result
83 test_expect_success 'blame with showEmail config true' '
84 git config blame.showEmail true &&
85 git blame one >blame1 &&
86 find_blame <blame1 >result &&
87 test_cmp expected_e result &&
88 git blame --no-show-email one >blame2 &&
89 find_blame <blame2 >result &&
90 test_cmp expected_n result
93 test_expect_success 'set up abbrev tests' '
94 test_commit abbrev &&
95 sha1=$(git rev-parse --verify HEAD) &&
96 check_abbrev () {
97 expect=$1; shift
98 echo $sha1 | cut -c 1-$expect >expect &&
99 git blame "$@" abbrev.t >actual &&
100 perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&
101 test_cmp expect actual.sha
105 test_expect_success 'blame --abbrev=<n> works' '
106 # non-boundary commits get +1 for alignment
107 check_abbrev 31 --abbrev=30 HEAD &&
108 check_abbrev 30 --abbrev=30 ^HEAD
111 test_expect_success 'blame -l aligns regular and boundary commits' '
112 check_abbrev $hexsz -l HEAD &&
113 check_abbrev $((hexsz - 1)) -l ^HEAD
116 test_expect_success 'blame --abbrev with full length behaves like -l' '
117 check_abbrev $hexsz --abbrev=$hexsz HEAD &&
118 check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD
121 test_expect_success '--no-abbrev works like --abbrev with full length' '
122 check_abbrev $hexsz --no-abbrev
125 test_expect_success '--exclude-promisor-objects does not BUG-crash' '
126 test_must_fail git blame --exclude-promisor-objects one
129 test_expect_success 'blame with uncommitted edits in partial clone does not crash' '
130 git init server &&
131 echo foo >server/file.txt &&
132 git -C server add file.txt &&
133 git -C server commit -m file &&
135 git clone --filter=blob:none "file://$(pwd)/server" client &&
136 echo bar >>client/file.txt &&
137 git -C client blame file.txt
140 test_done