t / t4205-log-pretty-formats.shon commit Fix "git diff --stat" for interesting - but empty - file changes (74faaa1)
   1#!/bin/sh
   2#
   3# Copyright (c) 2010, Will Palmer
   4#
   5
   6test_description='Test pretty formats'
   7. ./test-lib.sh
   8
   9test_expect_success 'set up basic repos' '
  10        >foo &&
  11        >bar &&
  12        git add foo &&
  13        test_tick &&
  14        git commit -m initial &&
  15        git add bar &&
  16        test_tick &&
  17        git commit -m "add bar"
  18'
  19
  20test_expect_success 'alias builtin format' '
  21        git log --pretty=oneline >expected &&
  22        git config pretty.test-alias oneline &&
  23        git log --pretty=test-alias >actual &&
  24        test_cmp expected actual
  25'
  26
  27test_expect_success 'alias masking builtin format' '
  28        git log --pretty=oneline >expected &&
  29        git config pretty.oneline "%H" &&
  30        git log --pretty=oneline >actual &&
  31        test_cmp expected actual
  32'
  33
  34test_expect_success 'alias user-defined format' '
  35        git log --pretty="format:%h" >expected &&
  36        git config pretty.test-alias "format:%h" &&
  37        git log --pretty=test-alias >actual &&
  38        test_cmp expected actual
  39'
  40
  41test_expect_success 'alias user-defined tformat' '
  42        git log --pretty="tformat:%h" >expected &&
  43        git config pretty.test-alias "tformat:%h" &&
  44        git log --pretty=test-alias >actual &&
  45        test_cmp expected actual
  46'
  47
  48test_expect_success 'alias non-existent format' '
  49        git config pretty.test-alias format-that-will-never-exist &&
  50        test_must_fail git log --pretty=test-alias
  51'
  52
  53test_expect_success 'alias of an alias' '
  54        git log --pretty="tformat:%h" >expected &&
  55        git config pretty.test-foo "tformat:%h" &&
  56        git config pretty.test-bar test-foo &&
  57        git log --pretty=test-bar >actual && test_cmp expected actual
  58'
  59
  60test_expect_success 'alias masking an alias' '
  61        git log --pretty=format:"Two %H" >expected &&
  62        git config pretty.duplicate "format:One %H" &&
  63        git config --add pretty.duplicate "format:Two %H" &&
  64        git log --pretty=duplicate >actual &&
  65        test_cmp expected actual
  66'
  67
  68test_expect_success 'alias loop' '
  69        git config pretty.test-foo test-bar &&
  70        git config pretty.test-bar test-foo &&
  71        test_must_fail git log --pretty=test-foo
  72'
  73
  74test_expect_success 'NUL separation' '
  75        printf "add bar\0initial" >expected &&
  76        git log -z --pretty="format:%s" >actual &&
  77        test_cmp expected actual
  78'
  79
  80test_expect_success 'NUL termination' '
  81        printf "add bar\0initial\0" >expected &&
  82        git log -z --pretty="tformat:%s" >actual &&
  83        test_cmp expected actual
  84'
  85
  86test_expect_success 'NUL separation with --stat' '
  87        stat0_part=$(git diff --stat HEAD^ HEAD) &&
  88        stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
  89        printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n" >expected &&
  90        git log -z --stat --pretty="format:%s" >actual &&
  91        test_i18ncmp expected actual
  92'
  93
  94test_expect_failure 'NUL termination with --stat' '
  95        stat0_part=$(git diff --stat HEAD^ HEAD) &&
  96        stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
  97        printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n\0" >expected &&
  98        git log -z --stat --pretty="tformat:%s" >actual &&
  99        test_i18ncmp expected actual
 100'
 101
 102test_done