t / t6030-bisect-run.shon commit Merge branch 'maint' (e881192)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Christian Couder
   4#
   5test_description='Tests git-bisect run functionality'
   6
   7. ./test-lib.sh
   8
   9add_line_into_file()
  10{
  11    _line=$1
  12    _file=$2
  13
  14    if [ -f "$_file" ]; then
  15        echo "$_line" >> $_file || return $?
  16        MSG="Add <$_line> into <$_file>."
  17    else
  18        echo "$_line" > $_file || return $?
  19        git add $_file || return $?
  20        MSG="Create file <$_file> with <$_line> inside."
  21    fi
  22
  23    git-commit -m "$MSG" $_file
  24}
  25
  26HASH1=
  27HASH3=
  28HASH4=
  29
  30test_expect_success \
  31    'set up basic repo with 1 file (hello) and 4 commits' \
  32    'add_line_into_file "1: Hello World" hello &&
  33     add_line_into_file "2: A new day for git" hello &&
  34     add_line_into_file "3: Another new day for git" hello &&
  35     add_line_into_file "4: Ciao for now" hello &&
  36     HASH1=$(git rev-list HEAD | tail -1) &&
  37     HASH3=$(git rev-list HEAD | head -2 | tail -1) &&
  38     HASH4=$(git rev-list HEAD | head -1)'
  39
  40# We want to automatically find the commit that
  41# introduced "Another" into hello.
  42test_expect_success \
  43    'git bisect run simple case' \
  44    'echo "#!/bin/sh" > test_script.sh &&
  45     echo "grep Another hello > /dev/null" >> test_script.sh &&
  46     echo "test \$? -ne 0" >> test_script.sh &&
  47     chmod +x test_script.sh &&
  48     git bisect start &&
  49     git bisect good $HASH1 &&
  50     git bisect bad $HASH4 &&
  51     git bisect run ./test_script.sh > my_bisect_log.txt &&
  52     grep "$HASH3 is first bad commit" my_bisect_log.txt'
  53
  54#
  55#
  56test_done
  57