t / t8002-blame.shon commit Merge branch 'nd/packobjectshook-doc-fix' into maint (060d061)
   1#!/bin/sh
   2
   3test_description='git blame'
   4. ./test-lib.sh
   5
   6PROG='git blame -c'
   7. "$TEST_DIRECTORY"/annotate-tests.sh
   8
   9test_expect_success 'blame untracked file in empty repo' '
  10        >untracked &&
  11        test_must_fail git blame untracked
  12'
  13
  14PROG='git blame -c -e'
  15test_expect_success 'blame --show-email' '
  16        check_count \
  17                "<A@test.git>" 1 \
  18                "<B@test.git>" 1 \
  19                "<B1@test.git>" 1 \
  20                "<B2@test.git>" 1 \
  21                "<author@example.com>" 1 \
  22                "<C@test.git>" 1 \
  23                "<D@test.git>" 1 \
  24                "<E at test dot git>" 1
  25'
  26
  27test_expect_success 'setup showEmail tests' '
  28        echo "bin: test number 1" >one &&
  29        git add one &&
  30        GIT_AUTHOR_NAME=name1 \
  31        GIT_AUTHOR_EMAIL=email1@test.git \
  32        git commit -m First --date="2010-01-01 01:00:00" &&
  33        cat >expected_n <<-\EOF &&
  34        (name1 2010-01-01 01:00:00 +0000 1) bin: test number 1
  35        EOF
  36        cat >expected_e <<-\EOF
  37        (<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1
  38        EOF
  39'
  40
  41find_blame () {
  42        sed -e 's/^[^(]*//'
  43}
  44
  45test_expect_success 'blame with no options and no config' '
  46        git blame one >blame &&
  47        find_blame <blame >result &&
  48        test_cmp expected_n result
  49'
  50
  51test_expect_success 'blame with showemail options' '
  52        git blame --show-email one >blame1 &&
  53        find_blame <blame1 >result &&
  54        test_cmp expected_e result &&
  55        git blame -e one >blame2 &&
  56        find_blame <blame2 >result &&
  57        test_cmp expected_e result &&
  58        git blame --no-show-email one >blame3 &&
  59        find_blame <blame3 >result &&
  60        test_cmp expected_n result
  61'
  62
  63test_expect_success 'blame with showEmail config false' '
  64        git config blame.showEmail false &&
  65        git blame one >blame1 &&
  66        find_blame <blame1 >result &&
  67        test_cmp expected_n result &&
  68        git blame --show-email one >blame2 &&
  69        find_blame <blame2 >result &&
  70        test_cmp expected_e result &&
  71        git blame -e one >blame3 &&
  72        find_blame <blame3 >result &&
  73        test_cmp expected_e result &&
  74        git blame --no-show-email one >blame4 &&
  75        find_blame <blame4 >result &&
  76        test_cmp expected_n result
  77'
  78
  79test_expect_success 'blame with showEmail config true' '
  80        git config blame.showEmail true &&
  81        git blame one >blame1 &&
  82        find_blame <blame1 >result &&
  83        test_cmp expected_e result &&
  84        git blame --no-show-email one >blame2 &&
  85        find_blame <blame2 >result &&
  86        test_cmp expected_n result
  87'
  88
  89test_expect_success 'set up abbrev tests' '
  90        test_commit abbrev &&
  91        sha1=$(git rev-parse --verify HEAD) &&
  92        check_abbrev () {
  93                expect=$1; shift
  94                echo $sha1 | cut -c 1-$expect >expect &&
  95                git blame "$@" abbrev.t >actual &&
  96                perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&
  97                test_cmp expect actual.sha
  98        }
  99'
 100
 101test_expect_success 'blame --abbrev=<n> works' '
 102        # non-boundary commits get +1 for alignment
 103        check_abbrev 31 --abbrev=30 HEAD &&
 104        check_abbrev 30 --abbrev=30 ^HEAD
 105'
 106
 107test_expect_success 'blame -l aligns regular and boundary commits' '
 108        check_abbrev 40 -l HEAD &&
 109        check_abbrev 39 -l ^HEAD
 110'
 111
 112test_expect_success 'blame --abbrev=40 behaves like -l' '
 113        check_abbrev 40 --abbrev=40 HEAD &&
 114        check_abbrev 39 --abbrev=40 ^HEAD
 115'
 116
 117test_expect_success '--no-abbrev works like --abbrev=40' '
 118        check_abbrev 40 --no-abbrev
 119'
 120
 121test_expect_success '--exclude-promisor-objects does not BUG-crash' '
 122        test_must_fail git blame --exclude-promisor-objects one
 123'
 124
 125test_done