ba9ea60d10032df507d84bb8e7faa9acbbd1ef30
   1#!/bin/sh
   2
   3test_description='test describe
   4
   5                       B
   6        .--------------o----o----o----x
   7       /                   /    /
   8 o----o----o----o----o----.    /
   9       \        A    c        /
  10        .------------o---o---o
  11                     D   e
  12'
  13. ./test-lib.sh
  14
  15check_describe () {
  16        expect="$1"
  17        shift
  18        R=$(git describe "$@")
  19        S=$?
  20        test_expect_success "describe $*" '
  21        test $S = 0 &&
  22        case "$R" in
  23        $expect)        echo happy ;;
  24        *)      echo "Oops - $R is not $expect";
  25                false ;;
  26        esac
  27        '
  28}
  29
  30test_expect_success setup '
  31
  32        test_tick &&
  33        echo one >file && git add file && git-commit -m initial &&
  34        one=$(git rev-parse HEAD) &&
  35
  36        test_tick &&
  37        echo two >file && git add file && git-commit -m second &&
  38        two=$(git rev-parse HEAD) &&
  39
  40        test_tick &&
  41        echo three >file && git add file && git-commit -m third &&
  42
  43        test_tick &&
  44        echo A >file && git add file && git-commit -m A &&
  45        test_tick &&
  46        git-tag -a -m A A &&
  47
  48        test_tick &&
  49        echo c >file && git add file && git-commit -m c &&
  50        test_tick &&
  51        git-tag c &&
  52
  53        git reset --hard $two &&
  54        test_tick &&
  55        echo B >side && git add side && git-commit -m B &&
  56        test_tick &&
  57        git-tag -a -m B B &&
  58
  59        test_tick &&
  60        git-merge -m Merged c &&
  61        merged=$(git rev-parse HEAD) &&
  62
  63        git reset --hard $two &&
  64        test_tick &&
  65        echo D >another && git add another && git-commit -m D &&
  66        test_tick &&
  67        git-tag -a -m D D &&
  68
  69        test_tick &&
  70        echo DD >another && git commit -a -m another &&
  71
  72        test_tick &&
  73        git-tag e &&
  74
  75        test_tick &&
  76        echo DDD >another && git commit -a -m "yet another" &&
  77
  78        test_tick &&
  79        git-merge -m Merged $merged &&
  80
  81        test_tick &&
  82        echo X >file && echo X >side && git add file side &&
  83        git-commit -m x
  84
  85'
  86
  87check_describe A-* HEAD
  88check_describe A-* HEAD^
  89check_describe D-* HEAD^^
  90check_describe A-* HEAD^^2
  91check_describe B HEAD^^2^
  92
  93check_describe A-* --tags HEAD
  94check_describe A-* --tags HEAD^
  95check_describe D-* --tags HEAD^^
  96check_describe A-* --tags HEAD^^2
  97check_describe B --tags HEAD^^2^
  98
  99check_describe B-0-* --long HEAD^^2^
 100
 101test_done