t / t1503-rev-parse-verify.shon commit t9138: remove stray dot in test which broke bash (2317d28)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Christian Couder
   4#
   5test_description='test git rev-parse --verify'
   6
   7exec </dev/null
   8
   9. ./test-lib.sh
  10
  11add_line_into_file()
  12{
  13    _line=$1
  14    _file=$2
  15
  16    if [ -f "$_file" ]; then
  17        echo "$_line" >> $_file || return $?
  18        MSG="Add <$_line> into <$_file>."
  19    else
  20        echo "$_line" > $_file || return $?
  21        git add $_file || return $?
  22        MSG="Create file <$_file> with <$_line> inside."
  23    fi
  24
  25    test_tick
  26    git commit --quiet -m "$MSG" $_file
  27}
  28
  29HASH1=
  30HASH2=
  31HASH3=
  32HASH4=
  33
  34test_expect_success 'set up basic repo with 1 file (hello) and 4 commits' '
  35        add_line_into_file "1: Hello World" hello &&
  36        HASH1=$(git rev-parse --verify HEAD) &&
  37        add_line_into_file "2: A new day for git" hello &&
  38        HASH2=$(git rev-parse --verify HEAD) &&
  39        add_line_into_file "3: Another new day for git" hello &&
  40        HASH3=$(git rev-parse --verify HEAD) &&
  41        add_line_into_file "4: Ciao for now" hello &&
  42        HASH4=$(git rev-parse --verify HEAD)
  43'
  44
  45test_expect_success 'works with one good rev' '
  46        rev_hash1=$(git rev-parse --verify $HASH1) &&
  47        test "$rev_hash1" = "$HASH1" &&
  48        rev_hash2=$(git rev-parse --verify $HASH2) &&
  49        test "$rev_hash2" = "$HASH2" &&
  50        rev_hash3=$(git rev-parse --verify $HASH3) &&
  51        test "$rev_hash3" = "$HASH3" &&
  52        rev_hash4=$(git rev-parse --verify $HASH4) &&
  53        test "$rev_hash4" = "$HASH4" &&
  54        rev_master=$(git rev-parse --verify master) &&
  55        test "$rev_master" = "$HASH4" &&
  56        rev_head=$(git rev-parse --verify HEAD) &&
  57        test "$rev_head" = "$HASH4"
  58'
  59
  60test_expect_success 'fails with any bad rev or many good revs' '
  61        test_must_fail git rev-parse --verify 2>error &&
  62        grep "single revision" error &&
  63        test_must_fail git rev-parse --verify foo 2>error &&
  64        grep "single revision" error &&
  65        test_must_fail git rev-parse --verify HEAD bar 2>error &&
  66        grep "single revision" error &&
  67        test_must_fail git rev-parse --verify baz HEAD 2>error &&
  68        grep "single revision" error &&
  69        test_must_fail git rev-parse --verify $HASH2 HEAD 2>error &&
  70        grep "single revision" error
  71'
  72
  73test_expect_success 'fails silently when using -q' '
  74        test_must_fail git rev-parse --verify --quiet 2>error &&
  75        test -z "$(cat error)" &&
  76        test_must_fail git rev-parse -q --verify foo 2>error &&
  77        test -z "$(cat error)" &&
  78        test_must_fail git rev-parse --verify -q HEAD bar 2>error &&
  79        test -z "$(cat error)" &&
  80        test_must_fail git rev-parse --quiet --verify baz HEAD 2>error &&
  81        test -z "$(cat error)" &&
  82        test_must_fail git rev-parse -q --verify $HASH2 HEAD 2>error &&
  83        test -z "$(cat error)"
  84'
  85
  86test_expect_success 'no stdout output on error' '
  87        test -z "$(git rev-parse --verify)" &&
  88        test -z "$(git rev-parse --verify foo)" &&
  89        test -z "$(git rev-parse --verify baz HEAD)" &&
  90        test -z "$(git rev-parse --verify HEAD bar)" &&
  91        test -z "$(git rev-parse --verify $HASH2 HEAD)"
  92'
  93
  94test_expect_success 'use --default' '
  95        git rev-parse --verify --default master &&
  96        git rev-parse --verify --default master HEAD &&
  97        git rev-parse --default master --verify &&
  98        git rev-parse --default master --verify HEAD &&
  99        git rev-parse --verify HEAD --default master &&
 100        test_must_fail git rev-parse --verify foo --default master &&
 101        test_must_fail git rev-parse --default HEAD --verify bar &&
 102        test_must_fail git rev-parse --verify --default HEAD baz &&
 103        test_must_fail git rev-parse --default foo --verify &&
 104        test_must_fail git rev-parse --verify --default bar
 105'
 106
 107test_done