t / t6006-rev-list-format.shon commit Merge branch 'pb/maint-git-pm-false-dir' (4d8e6e1)
   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
 104cat >commit-msg <<'EOF'
 105Test printing of complex bodies
 106
 107This commit message is much longer than the others,
 108and it will be encoded in iso8859-1. We should therefore
 109include an iso8859 character: ¡bueno!
 110EOF
 111test_expect_success 'setup complex body' '
 112git config i18n.commitencoding iso8859-1 &&
 113  echo change2 >foo && git commit -a -F commit-msg
 114'
 115
 116test_format complex-encoding %e <<'EOF'
 117commit f58db70b055c5718631e5c61528b28b12090cdea
 118iso8859-1
 119commit 131a310eb913d107dd3c09a65d1651175898735d
 120commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 121EOF
 122
 123test_format complex-subject %s <<'EOF'
 124commit f58db70b055c5718631e5c61528b28b12090cdea
 125Test printing of complex bodies
 126commit 131a310eb913d107dd3c09a65d1651175898735d
 127changed foo
 128commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 129added foo
 130EOF
 131
 132test_format complex-body %b <<'EOF'
 133commit f58db70b055c5718631e5c61528b28b12090cdea
 134This commit message is much longer than the others,
 135and it will be encoded in iso8859-1. We should therefore
 136include an iso8859 character: ¡bueno!
 137
 138commit 131a310eb913d107dd3c09a65d1651175898735d
 139commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 140EOF
 141
 142test_expect_success '%ad respects --date=' '
 143        echo 2005-04-07 >expect.ad-short &&
 144        git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
 145        test_cmp expect.ad-short output.ad-short
 146'
 147
 148test_expect_success 'empty email' '
 149        test_tick &&
 150        C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
 151        A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
 152        test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
 153                echo "Eh? $A" >failure
 154                false
 155        }
 156'
 157
 158test_done