t / t6006-rev-list-format.shon commit Merge branch 'sr/blame-incomplete' (25dfd1b)
   1#!/bin/sh
   2
   3test_description='git rev-list --pretty=format test'
   4
   5. ./test-lib.sh
   6
   7test_tick
   8test_expect_success 'setup' '
   9touch foo && git add foo && git commit -m "added foo" &&
  10  echo changed >foo && git commit -a -m "changed foo"
  11'
  12
  13# usage: test_format name format_string <expected_output
  14test_format() {
  15        cat >expect.$1
  16        test_expect_success "format $1" "
  17git rev-list --pretty=format:'$2' master >output.$1 &&
  18test_cmp expect.$1 output.$1
  19"
  20}
  21
  22test_format hash %H%n%h <<'EOF'
  23commit 131a310eb913d107dd3c09a65d1651175898735d
  24131a310eb913d107dd3c09a65d1651175898735d
  25131a310
  26commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
  2786c75cfd708a0e5868dc876ed5b8bb66c80b4873
  2886c75cf
  29EOF
  30
  31test_format tree %T%n%t <<'EOF'
  32commit 131a310eb913d107dd3c09a65d1651175898735d
  33fe722612f26da5064c32ca3843aa154bdb0b08a0
  34fe72261
  35commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
  364d5fcadc293a348e88f777dc0920f11e7d71441c
  374d5fcad
  38EOF
  39
  40test_format parents %P%n%p <<'EOF'
  41commit 131a310eb913d107dd3c09a65d1651175898735d
  4286c75cfd708a0e5868dc876ed5b8bb66c80b4873
  4386c75cf
  44commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
  45
  46
  47EOF
  48
  49# we don't test relative here
  50test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
  51commit 131a310eb913d107dd3c09a65d1651175898735d
  52A U Thor
  53author@example.com
  54Thu Apr 7 15:13:13 2005 -0700
  55Thu, 7 Apr 2005 15:13:13 -0700
  561112911993
  57commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
  58A U Thor
  59author@example.com
  60Thu Apr 7 15:13:13 2005 -0700
  61Thu, 7 Apr 2005 15:13:13 -0700
  621112911993
  63EOF
  64
  65test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
  66commit 131a310eb913d107dd3c09a65d1651175898735d
  67C O Mitter
  68committer@example.com
  69Thu Apr 7 15:13:13 2005 -0700
  70Thu, 7 Apr 2005 15:13:13 -0700
  711112911993
  72commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
  73C O Mitter
  74committer@example.com
  75Thu Apr 7 15:13:13 2005 -0700
  76Thu, 7 Apr 2005 15:13:13 -0700
  771112911993
  78EOF
  79
  80test_format encoding %e <<'EOF'
  81commit 131a310eb913d107dd3c09a65d1651175898735d
  82commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
  83EOF
  84
  85test_format subject %s <<'EOF'
  86commit 131a310eb913d107dd3c09a65d1651175898735d
  87changed foo
  88commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
  89added foo
  90EOF
  91
  92test_format body %b <<'EOF'
  93commit 131a310eb913d107dd3c09a65d1651175898735d
  94commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
  95EOF
  96
  97test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
  98commit 131a310eb913d107dd3c09a65d1651175898735d
  99\e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
 100commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 101\e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
 102EOF
 103
 104test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
 105commit 131a310eb913d107dd3c09a65d1651175898735d
 106\e[1;31;43mfoo\e[m
 107commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 108\e[1;31;43mfoo\e[m
 109EOF
 110
 111cat >commit-msg <<'EOF'
 112Test printing of complex bodies
 113
 114This commit message is much longer than the others,
 115and it will be encoded in iso8859-1. We should therefore
 116include an iso8859 character: ¡bueno!
 117EOF
 118test_expect_success 'setup complex body' '
 119git config i18n.commitencoding iso8859-1 &&
 120  echo change2 >foo && git commit -a -F commit-msg
 121'
 122
 123test_format complex-encoding %e <<'EOF'
 124commit f58db70b055c5718631e5c61528b28b12090cdea
 125iso8859-1
 126commit 131a310eb913d107dd3c09a65d1651175898735d
 127commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 128EOF
 129
 130test_format complex-subject %s <<'EOF'
 131commit f58db70b055c5718631e5c61528b28b12090cdea
 132Test printing of complex bodies
 133commit 131a310eb913d107dd3c09a65d1651175898735d
 134changed foo
 135commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 136added foo
 137EOF
 138
 139test_format complex-body %b <<'EOF'
 140commit f58db70b055c5718631e5c61528b28b12090cdea
 141This commit message is much longer than the others,
 142and it will be encoded in iso8859-1. We should therefore
 143include an iso8859 character: ¡bueno!
 144
 145commit 131a310eb913d107dd3c09a65d1651175898735d
 146commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 147EOF
 148
 149test_expect_success '%ad respects --date=' '
 150        echo 2005-04-07 >expect.ad-short &&
 151        git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
 152        test_cmp expect.ad-short output.ad-short
 153'
 154
 155test_expect_success 'empty email' '
 156        test_tick &&
 157        C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
 158        A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
 159        test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
 160                echo "Eh? $A" >failure
 161                false
 162        }
 163'
 164
 165test_expect_success '"%h %gD: %gs" is same as git-reflog' '
 166        git reflog >expect &&
 167        git log -g --format="%h %gD: %gs" >actual &&
 168        test_cmp expect actual
 169'
 170
 171test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
 172        git reflog --date=raw >expect &&
 173        git log -g --format="%h %gD: %gs" --date=raw >actual &&
 174        test_cmp expect actual
 175'
 176
 177test_expect_success '%gd shortens ref name' '
 178        echo "master@{0}" >expect.gd-short &&
 179        git log -g -1 --format=%gd refs/heads/master >actual.gd-short &&
 180        test_cmp expect.gd-short actual.gd-short
 181'
 182
 183test_done