Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 3 | test_description='git blame' |
Johannes Schindelin | 747f6c6 | 2020-11-18 23:44:41 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
| 9 | PROG='git blame -c' |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 10 | . "$TEST_DIRECTORY"/annotate-tests.sh |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 11 | |
brian m. carlson | 98de0b2 | 2020-07-29 23:14:07 +0000 | [diff] [blame] | 12 | test_expect_success 'setup' ' |
| 13 | hexsz=$(test_oid hexsz) |
| 14 | ' |
| 15 | |
Thomas Gummerer | bc6b13a | 2016-08-27 21:01:50 +0100 | [diff] [blame] | 16 | test_expect_success 'blame untracked file in empty repo' ' |
| 17 | >untracked && |
| 18 | test_must_fail git blame untracked |
| 19 | ' |
| 20 | |
Kevin Ballard | 1b8cdce | 2010-10-15 23:57:51 -0700 | [diff] [blame] | 21 | PROG='git blame -c -e' |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 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 |
Kevin Ballard | 1b8cdce | 2010-10-15 23:57:51 -0700 | [diff] [blame] | 32 | ' |
| 33 | |
Quentin Neill | 8b504db | 2015-05-31 14:27:37 -0500 | [diff] [blame] | 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 | |
Jeff King | 9122983 | 2017-01-05 23:17:40 -0500 | [diff] [blame] | 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' ' |
brian m. carlson | 98de0b2 | 2020-07-29 23:14:07 +0000 | [diff] [blame] | 115 | check_abbrev $hexsz -l HEAD && |
| 116 | check_abbrev $((hexsz - 1)) -l ^HEAD |
Jeff King | 9122983 | 2017-01-05 23:17:40 -0500 | [diff] [blame] | 117 | ' |
| 118 | |
brian m. carlson | 98de0b2 | 2020-07-29 23:14:07 +0000 | [diff] [blame] | 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 |
Jeff King | 9122983 | 2017-01-05 23:17:40 -0500 | [diff] [blame] | 122 | ' |
| 123 | |
brian m. carlson | 98de0b2 | 2020-07-29 23:14:07 +0000 | [diff] [blame] | 124 | test_expect_success '--no-abbrev works like --abbrev with full length' ' |
| 125 | check_abbrev $hexsz --no-abbrev |
Jeff King | ed58d80 | 2017-01-05 23:18:08 -0500 | [diff] [blame] | 126 | ' |
| 127 | |
Matthew DeVore | 669b1d2 | 2018-10-22 18:13:42 -0700 | [diff] [blame] | 128 | test_expect_success '--exclude-promisor-objects does not BUG-crash' ' |
| 129 | test_must_fail git blame --exclude-promisor-objects one |
| 130 | ' |
| 131 | |
Jonathan Tan | a64d2aa | 2020-07-21 15:50:20 -0700 | [diff] [blame] | 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 | |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 143 | test_done |