| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='blame output in various formats on a simple case' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup' ' |
| 8 | echo a >file && |
| 9 | git add file && |
| 10 | test_tick && |
| 11 | git commit -m one && |
| 12 | echo b >>file && |
| 13 | echo c >>file && |
| 14 | echo d >>file && |
| 15 | test_tick && |
| 16 | git commit -a -m two && |
| 17 | ID1=$(git rev-parse HEAD^) && |
| 18 | shortID1="^$(git rev-parse HEAD^ |cut -c 1-17)" && |
| 19 | ID2=$(git rev-parse HEAD) && |
| 20 | shortID2="$(git rev-parse HEAD |cut -c 1-18)" |
| 21 | ' |
| 22 | |
| 23 | cat >expect <<EOF |
| 24 | $shortID1 (A U Thor 2005-04-07 15:13:13 -0700 1) a |
| 25 | $shortID2 (A U Thor 2005-04-07 15:14:13 -0700 2) b |
| 26 | $shortID2 (A U Thor 2005-04-07 15:14:13 -0700 3) c |
| 27 | $shortID2 (A U Thor 2005-04-07 15:14:13 -0700 4) d |
| 28 | EOF |
| 29 | test_expect_success 'normal blame output' ' |
| 30 | git blame --abbrev=17 file >actual && |
| 31 | test_cmp expect actual |
| 32 | ' |
| 33 | |
| 34 | COMMIT1="author A U Thor |
| 35 | author-mail <author@example.com> |
| 36 | author-time 1112911993 |
| 37 | author-tz -0700 |
| 38 | committer C O Mitter |
| 39 | committer-mail <committer@example.com> |
| 40 | committer-time 1112911993 |
| 41 | committer-tz -0700 |
| 42 | summary one |
| 43 | boundary |
| 44 | filename file" |
| 45 | COMMIT2="author A U Thor |
| 46 | author-mail <author@example.com> |
| 47 | author-time 1112912053 |
| 48 | author-tz -0700 |
| 49 | committer C O Mitter |
| 50 | committer-mail <committer@example.com> |
| 51 | committer-time 1112912053 |
| 52 | committer-tz -0700 |
| 53 | summary two |
| 54 | previous $ID1 file |
| 55 | filename file" |
| 56 | |
| 57 | cat >expect <<EOF |
| 58 | $ID1 1 1 1 |
| 59 | $COMMIT1 |
| 60 | a |
| 61 | $ID2 2 2 3 |
| 62 | $COMMIT2 |
| 63 | b |
| 64 | $ID2 3 3 |
| 65 | c |
| 66 | $ID2 4 4 |
| 67 | d |
| 68 | EOF |
| 69 | test_expect_success 'blame --porcelain output' ' |
| 70 | git blame --porcelain file >actual && |
| 71 | test_cmp expect actual |
| 72 | ' |
| 73 | |
| 74 | cat >expect <<EOF |
| 75 | $ID1 1 1 1 |
| 76 | $COMMIT1 |
| 77 | a |
| 78 | $ID2 2 2 3 |
| 79 | $COMMIT2 |
| 80 | b |
| 81 | $ID2 3 3 |
| 82 | $COMMIT2 |
| 83 | c |
| 84 | $ID2 4 4 |
| 85 | $COMMIT2 |
| 86 | d |
| 87 | EOF |
| 88 | test_expect_success 'blame --line-porcelain output' ' |
| 89 | git blame --line-porcelain file >actual && |
| 90 | test_cmp expect actual |
| 91 | ' |
| 92 | |
| 93 | test_expect_success '--porcelain detects first non-blank line as subject' ' |
| 94 | ( |
| 95 | GIT_INDEX_FILE=.git/tmp-index && |
| 96 | export GIT_INDEX_FILE && |
| 97 | echo "This is it" >single-file && |
| 98 | git add single-file && |
| 99 | tree=$(git write-tree) && |
| 100 | commit=$(printf "%s\n%s\n%s\n\n\n \noneline\n\nbody\n" \ |
| 101 | "tree $tree" \ |
| 102 | "author A <a@b.c> 123456789 +0000" \ |
| 103 | "committer C <c@d.e> 123456789 +0000" | |
| 104 | git hash-object -w -t commit --stdin) && |
| 105 | git blame --porcelain $commit -- single-file >output && |
| 106 | grep "^summary oneline$" output |
| 107 | ) |
| 108 | ' |
| 109 | |
| 110 | test_done |