t / t7007-show.shon commit format-patch: respect --stat in cover letter's diffstat (284aeb7)
   1#!/bin/sh
   2
   3test_description='git show'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8        echo hello world >foo &&
   9        H=$(git hash-object -w foo) &&
  10        git tag -a foo-tag -m "Tags $H" $H &&
  11        HH=$(expr "$H" : "\(..\)") &&
  12        H38=$(expr "$H" : "..\(.*\)") &&
  13        rm -f .git/objects/$HH/$H38
  14'
  15
  16test_expect_success 'showing a tag that point at a missing object' '
  17        test_must_fail git --no-pager show foo-tag
  18'
  19
  20test_expect_success 'set up a bit of history' '
  21        test_commit main1 &&
  22        test_commit main2 &&
  23        test_commit main3 &&
  24        git tag -m "annotated tag" annotated &&
  25        git checkout -b side HEAD^^ &&
  26        test_commit side2 &&
  27        test_commit side3 &&
  28        test_merge merge main3
  29'
  30
  31test_expect_success 'showing two commits' '
  32        cat >expect <<-EOF &&
  33        commit $(git rev-parse main2)
  34        commit $(git rev-parse main3)
  35        EOF
  36        git show main2 main3 >actual &&
  37        grep ^commit actual >actual.filtered &&
  38        test_cmp expect actual.filtered
  39'
  40
  41test_expect_success 'showing a range walks (linear)' '
  42        cat >expect <<-EOF &&
  43        commit $(git rev-parse main3)
  44        commit $(git rev-parse main2)
  45        EOF
  46        git show main1..main3 >actual &&
  47        grep ^commit actual >actual.filtered &&
  48        test_cmp expect actual.filtered
  49'
  50
  51test_expect_success 'showing a range walks (Y shape, ^ first)' '
  52        cat >expect <<-EOF &&
  53        commit $(git rev-parse main3)
  54        commit $(git rev-parse main2)
  55        EOF
  56        git show ^side3 main3 >actual &&
  57        grep ^commit actual >actual.filtered &&
  58        test_cmp expect actual.filtered
  59'
  60
  61test_expect_success 'showing a range walks (Y shape, ^ last)' '
  62        cat >expect <<-EOF &&
  63        commit $(git rev-parse main3)
  64        commit $(git rev-parse main2)
  65        EOF
  66        git show main3 ^side3 >actual &&
  67        grep ^commit actual >actual.filtered &&
  68        test_cmp expect actual.filtered
  69'
  70
  71test_expect_success 'showing with -N walks' '
  72        cat >expect <<-EOF &&
  73        commit $(git rev-parse main3)
  74        commit $(git rev-parse main2)
  75        EOF
  76        git show -2 main3 >actual &&
  77        grep ^commit actual >actual.filtered &&
  78        test_cmp expect actual.filtered
  79'
  80
  81test_expect_success 'showing annotated tag' '
  82        cat >expect <<-EOF &&
  83        tag annotated
  84        commit $(git rev-parse annotated^{commit})
  85        EOF
  86        git show annotated >actual &&
  87        grep -E "^(commit|tag)" actual >actual.filtered &&
  88        test_cmp expect actual.filtered
  89'
  90
  91test_expect_success 'showing annotated tag plus commit' '
  92        cat >expect <<-EOF &&
  93        tag annotated
  94        commit $(git rev-parse annotated^{commit})
  95        commit $(git rev-parse side3)
  96        EOF
  97        git show annotated side3 >actual &&
  98        grep -E "^(commit|tag)" actual >actual.filtered &&
  99        test_cmp expect actual.filtered
 100'
 101
 102test_expect_success 'showing range' '
 103        cat >expect <<-EOF &&
 104        commit $(git rev-parse main3)
 105        commit $(git rev-parse main2)
 106        EOF
 107        git show ^side3 annotated >actual &&
 108        grep -E "^(commit|tag)" actual >actual.filtered &&
 109        test_cmp expect actual.filtered
 110'
 111
 112test_expect_success '-s suppresses diff' '
 113        cat >expect <<-\EOF &&
 114        merge
 115        main3
 116        EOF
 117        git show -s --format=%s merge main3 >actual &&
 118        test_cmp expect actual
 119'
 120
 121test_expect_success '--quiet suppresses diff' '
 122        echo main3 >expect &&
 123        git show --quiet --format=%s main3 >actual &&
 124        test_cmp expect actual
 125'
 126
 127test_expect_success 'show --graph is forbidden' '
 128  test_must_fail git show --graph HEAD
 129'
 130
 131test_done