t / t4213-log-tabexpand.shon commit fetch: make the --prune-tags work with <url> (6317972)
   1#!/bin/sh
   2
   3test_description='log/show --expand-tabs'
   4
   5. ./test-lib.sh
   6
   7HT="    "
   8title='tab indent at the beginning of the title line'
   9body='tab indent on a line in the body'
  10
  11# usage: count_expand $indent $numSP $numHT @format_args
  12count_expand ()
  13{
  14        expect=
  15        count=$(( $1 + $2 )) ;# expected spaces
  16        while test $count -gt 0
  17        do
  18                expect="$expect "
  19                count=$(( $count - 1 ))
  20        done
  21        shift 2
  22        count=$1 ;# expected tabs
  23        while test $count -gt 0
  24        do
  25                expect="$expect$HT"
  26                count=$(( $count - 1 ))
  27        done
  28        shift
  29
  30        # The remainder of the command line is "git show -s" options
  31        case " $* " in
  32        *' --pretty=short '*)
  33                line=$title ;;
  34        *)
  35                line=$body ;;
  36        esac
  37
  38        # Prefix the output with the command line arguments, and
  39        # replace SP with a dot both in the expecte and actual output
  40        # so that test_cmp would show the difference together with the
  41        # breakage in a way easier to consume by the debugging user.
  42        {
  43                echo "git show -s $*"
  44                echo "$expect$line"
  45        } | sed -e 's/ /./g' >expect
  46
  47        {
  48                echo "git show -s $*"
  49                git show -s "$@" |
  50                sed -n -e "/$line\$/p"
  51        } | sed -e 's/ /./g' >actual
  52
  53        test_cmp expect actual
  54}
  55
  56test_expand ()
  57{
  58        fmt=$1
  59        case "$fmt" in
  60        *=raw | *=short | *=email)
  61                default="0 1" ;;
  62        *)
  63                default="8 0" ;;
  64        esac
  65        case "$fmt" in
  66        *=email)
  67                in=0 ;;
  68        *)
  69                in=4 ;;
  70        esac
  71        test_expect_success "expand/no-expand${fmt:+ for $fmt}" '
  72                count_expand $in $default $fmt &&
  73                count_expand $in 8 0 $fmt --expand-tabs &&
  74                count_expand $in 8 0 --expand-tabs $fmt &&
  75                count_expand $in 8 0 $fmt --expand-tabs=8 &&
  76                count_expand $in 8 0 --expand-tabs=8 $fmt &&
  77                count_expand $in 0 1 $fmt --no-expand-tabs &&
  78                count_expand $in 0 1 --no-expand-tabs $fmt &&
  79                count_expand $in 0 1 $fmt --expand-tabs=0 &&
  80                count_expand $in 0 1 --expand-tabs=0 $fmt &&
  81                count_expand $in 4 0 $fmt --expand-tabs=4 &&
  82                count_expand $in 4 0 --expand-tabs=4 $fmt
  83        '
  84}
  85
  86test_expect_success 'setup' '
  87        test_tick &&
  88        sed -e "s/Q/$HT/g" <<-EOF >msg &&
  89        Q$title
  90
  91        Q$body
  92        EOF
  93        git commit --allow-empty -F msg
  94'
  95
  96test_expand ""
  97test_expand --pretty
  98test_expand --pretty=short
  99test_expand --pretty=medium
 100test_expand --pretty=full
 101test_expand --pretty=fuller
 102test_expand --pretty=raw
 103test_expand --pretty=email
 104
 105test_done