]>
Commit | Line | Data |
---|---|---|
8752d11d FK |
1 | #!/bin/sh |
2 | ||
5be60078 | 3 | test_description='git blame' |
747f6c68 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
8752d11d FK |
7 | . ./test-lib.sh |
8 | ||
9 | PROG='git blame -c' | |
bfdbee98 | 10 | . "$TEST_DIRECTORY"/annotate-tests.sh |
8752d11d | 11 | |
98de0b27 | 12 | test_expect_success 'setup' ' |
13 | hexsz=$(test_oid hexsz) | |
14 | ' | |
15 | ||
bc6b13a7 TG |
16 | test_expect_success 'blame untracked file in empty repo' ' |
17 | >untracked && | |
18 | test_must_fail git blame untracked | |
19 | ' | |
20 | ||
1b8cdce9 | 21 | PROG='git blame -c -e' |
e37f39c1 ES |
22 | test_expect_success 'blame --show-email' ' |
23 | check_count \ | |
24 | "<A@test.git>" 1 \ | |
25 | "<B@test.git>" 1 \ | |
26 | "<B1@test.git>" 1 \ | |
27 | "<B2@test.git>" 1 \ | |
28 | "<author@example.com>" 1 \ | |
29 | "<C@test.git>" 1 \ | |
30 | "<D@test.git>" 1 \ | |
31 | "<E at test dot git>" 1 | |
1b8cdce9 KB |
32 | ' |
33 | ||
8b504db3 QN |
34 | test_expect_success 'setup showEmail tests' ' |
35 | echo "bin: test number 1" >one && | |
36 | git add one && | |
37 | GIT_AUTHOR_NAME=name1 \ | |
38 | GIT_AUTHOR_EMAIL=email1@test.git \ | |
39 | git commit -m First --date="2010-01-01 01:00:00" && | |
40 | cat >expected_n <<-\EOF && | |
41 | (name1 2010-01-01 01:00:00 +0000 1) bin: test number 1 | |
42 | EOF | |
43 | cat >expected_e <<-\EOF | |
44 | (<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1 | |
45 | EOF | |
46 | ' | |
47 | ||
48 | find_blame () { | |
49 | sed -e 's/^[^(]*//' | |
50 | } | |
51 | ||
52 | test_expect_success 'blame with no options and no config' ' | |
53 | git blame one >blame && | |
54 | find_blame <blame >result && | |
55 | test_cmp expected_n result | |
56 | ' | |
57 | ||
58 | test_expect_success 'blame with showemail options' ' | |
59 | git blame --show-email one >blame1 && | |
60 | find_blame <blame1 >result && | |
61 | test_cmp expected_e result && | |
62 | git blame -e one >blame2 && | |
63 | find_blame <blame2 >result && | |
64 | test_cmp expected_e result && | |
65 | git blame --no-show-email one >blame3 && | |
66 | find_blame <blame3 >result && | |
67 | test_cmp expected_n result | |
68 | ' | |
69 | ||
70 | test_expect_success 'blame with showEmail config false' ' | |
71 | git config blame.showEmail false && | |
72 | git blame one >blame1 && | |
73 | find_blame <blame1 >result && | |
74 | test_cmp expected_n result && | |
75 | git blame --show-email one >blame2 && | |
76 | find_blame <blame2 >result && | |
77 | test_cmp expected_e result && | |
78 | git blame -e one >blame3 && | |
79 | find_blame <blame3 >result && | |
80 | test_cmp expected_e result && | |
81 | git blame --no-show-email one >blame4 && | |
82 | find_blame <blame4 >result && | |
83 | test_cmp expected_n result | |
84 | ' | |
85 | ||
86 | test_expect_success 'blame with showEmail config true' ' | |
87 | git config blame.showEmail true && | |
88 | git blame one >blame1 && | |
89 | find_blame <blame1 >result && | |
90 | test_cmp expected_e result && | |
91 | git blame --no-show-email one >blame2 && | |
92 | find_blame <blame2 >result && | |
93 | test_cmp expected_n result | |
94 | ' | |
95 | ||
91229834 JK |
96 | test_expect_success 'set up abbrev tests' ' |
97 | test_commit abbrev && | |
98 | sha1=$(git rev-parse --verify HEAD) && | |
99 | check_abbrev () { | |
100 | expect=$1; shift | |
101 | echo $sha1 | cut -c 1-$expect >expect && | |
102 | git blame "$@" abbrev.t >actual && | |
103 | perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha && | |
104 | test_cmp expect actual.sha | |
105 | } | |
106 | ' | |
107 | ||
108 | test_expect_success 'blame --abbrev=<n> works' ' | |
109 | # non-boundary commits get +1 for alignment | |
110 | check_abbrev 31 --abbrev=30 HEAD && | |
111 | check_abbrev 30 --abbrev=30 ^HEAD | |
112 | ' | |
113 | ||
114 | test_expect_success 'blame -l aligns regular and boundary commits' ' | |
98de0b27 | 115 | check_abbrev $hexsz -l HEAD && |
116 | check_abbrev $((hexsz - 1)) -l ^HEAD | |
91229834 JK |
117 | ' |
118 | ||
98de0b27 | 119 | test_expect_success 'blame --abbrev with full length behaves like -l' ' |
120 | check_abbrev $hexsz --abbrev=$hexsz HEAD && | |
121 | check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD | |
91229834 JK |
122 | ' |
123 | ||
98de0b27 | 124 | test_expect_success '--no-abbrev works like --abbrev with full length' ' |
125 | check_abbrev $hexsz --no-abbrev | |
ed58d808 JK |
126 | ' |
127 | ||
669b1d2a MD |
128 | test_expect_success '--exclude-promisor-objects does not BUG-crash' ' |
129 | test_must_fail git blame --exclude-promisor-objects one | |
130 | ' | |
131 | ||
a64d2aae JT |
132 | test_expect_success 'blame with uncommitted edits in partial clone does not crash' ' |
133 | git init server && | |
134 | echo foo >server/file.txt && | |
135 | git -C server add file.txt && | |
136 | git -C server commit -m file && | |
137 | ||
138 | git clone --filter=blob:none "file://$(pwd)/server" client && | |
139 | echo bar >>client/file.txt && | |
140 | git -C client blame file.txt | |
141 | ' | |
142 | ||
8752d11d | 143 | test_done |