Junio C Hamano | d2dadfe | 2008-12-15 00:36:56 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git show' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_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 | |
| 16 | test_expect_success 'showing a tag that point at a missing object' ' |
| 17 | test_must_fail git --no-pager show foo-tag |
| 18 | ' |
| 19 | |
Thomas Rast | b0082b9 | 2012-06-19 22:04:57 +0200 | [diff] [blame] | 20 | test_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 && |
Max Kirillov | ad2f725 | 2014-05-15 01:12:45 +0300 | [diff] [blame] | 27 | test_commit side3 && |
| 28 | test_merge merge main3 |
Thomas Rast | b0082b9 | 2012-06-19 22:04:57 +0200 | [diff] [blame] | 29 | ' |
| 30 | |
| 31 | test_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 | |
| 41 | test_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 | |
| 51 | test_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 | |
Junio C Hamano | c5941f1 | 2012-06-19 14:15:57 -0700 | [diff] [blame] | 61 | test_expect_success 'showing a range walks (Y shape, ^ last)' ' |
Thomas Rast | b0082b9 | 2012-06-19 22:04:57 +0200 | [diff] [blame] | 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 | |
| 71 | test_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 | |
| 81 | test_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 | |
| 91 | test_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 | |
Junio C Hamano | c5941f1 | 2012-06-19 14:15:57 -0700 | [diff] [blame] | 102 | test_expect_success 'showing range' ' |
Thomas Rast | b0082b9 | 2012-06-19 22:04:57 +0200 | [diff] [blame] | 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 | |
Jeff King | f9c75d8 | 2012-08-28 17:29:34 -0400 | [diff] [blame] | 112 | test_expect_success '-s suppresses diff' ' |
Max Kirillov | ad2f725 | 2014-05-15 01:12:45 +0300 | [diff] [blame] | 113 | cat >expect <<-\EOF && |
| 114 | merge |
| 115 | main3 |
| 116 | EOF |
| 117 | git show -s --format=%s merge main3 >actual && |
Jeff King | f9c75d8 | 2012-08-28 17:29:34 -0400 | [diff] [blame] | 118 | test_cmp expect actual |
| 119 | ' |
| 120 | |
| 121 | test_expect_success '--quiet suppresses diff' ' |
| 122 | echo main3 >expect && |
| 123 | git show --quiet --format=%s main3 >actual && |
| 124 | test_cmp expect actual |
| 125 | ' |
| 126 | |
Dongcan Jiang | 695985f | 2015-03-11 10:13:02 +0800 | [diff] [blame] | 127 | test_expect_success 'show --graph is forbidden' ' |
| 128 | test_must_fail git show --graph HEAD |
| 129 | ' |
| 130 | |
Junio C Hamano | d2dadfe | 2008-12-15 00:36:56 -0800 | [diff] [blame] | 131 | test_done |