git-bisect.example.sh

  1. 8.0.x examples/git-bisect.example.sh
  2. 7.x examples/git-bisect.example.sh
  3. master examples/git-bisect.example.sh
#!/usr/bin/env sh

#
# Git bisect is a helpful way to discover which commit an error
# occurred in.  This example file gives simple instructions for
# using git bisect with Drush to quickly find erroneous commits
# in Drush commands or Drupal modules, presuming that you can
# trigger the error condition via Drush (e.g. using `drush php-eval`).
#
# Follow these simple steps:
#
#   $ git bisect start
#   $ git bisect bad              # Tell git that the current commit does not work
#   $ git bisect good bcadd5a     # Tell drush that the commithash 12345 worked fine
#   $ git bisect run mytestscript.sh
#
# 'git bisect run' will continue to call 'git bisect good' and 'git bisect bad',
# based on whether the script's exit code was 0 or 1, respectively.
#
# Replace 'mytestscript.sh' in the example above with a custom script that you
# write yourself.  Use the example script at the end of this document as a
# guide.  Replace the example command with one that calls the Drush command
# that you would like to test, and replace the 'grep' string with a value
# that appears when the error exists in the commit, but does not appear when
# commit is okay.
#
# If you are using Drush to test Drupal or an external Drush module, use:
#
#   $ git bisect run drush mycommand --strict=2
#
# This presumes that there is one or more '[warning]' or '[error]'
# messages emitted when there is a problem, and no warnings or errors
# when the commit is okay.  Omit '--strict=2' to ignore warnings, and
# signal failure only when 'error' messages are emitted.
#
# If you need to test for an error condition explicitly, to find errors
# that do not return any warning or error log messages on their own, you
# can use the Drush php-eval command to force an error when `myfunction()`
# returns FALSE. Replace 'myfunction()' with the name of an appropriate
# function in your module that can be used to detect the error condition
# you are looking for.
#
#   $ git bisect run drush ev 'if(!myfunction()) { return drush_set_error("ERR"); }'
#
drush mycommand --myoption 2>&1 | grep -q 'string that indicates there was a problem'
if [ $? == 0 ] ; then
  exit 1
else
  exit 0
fi

File

examples/git-bisect.example.sh
View source
  1. #!/usr/bin/env sh
  2. #
  3. # Git bisect is a helpful way to discover which commit an error
  4. # occurred in. This example file gives simple instructions for
  5. # using git bisect with Drush to quickly find erroneous commits
  6. # in Drush commands or Drupal modules, presuming that you can
  7. # trigger the error condition via Drush (e.g. using `drush php-eval`).
  8. #
  9. # Follow these simple steps:
  10. #
  11. # $ git bisect start
  12. # $ git bisect bad # Tell git that the current commit does not work
  13. # $ git bisect good bcadd5a # Tell drush that the commithash 12345 worked fine
  14. # $ git bisect run mytestscript.sh
  15. #
  16. # 'git bisect run' will continue to call 'git bisect good' and 'git bisect bad',
  17. # based on whether the script's exit code was 0 or 1, respectively.
  18. #
  19. # Replace 'mytestscript.sh' in the example above with a custom script that you
  20. # write yourself. Use the example script at the end of this document as a
  21. # guide. Replace the example command with one that calls the Drush command
  22. # that you would like to test, and replace the 'grep' string with a value
  23. # that appears when the error exists in the commit, but does not appear when
  24. # commit is okay.
  25. #
  26. # If you are using Drush to test Drupal or an external Drush module, use:
  27. #
  28. # $ git bisect run drush mycommand --strict=2
  29. #
  30. # This presumes that there is one or more '[warning]' or '[error]'
  31. # messages emitted when there is a problem, and no warnings or errors
  32. # when the commit is okay. Omit '--strict=2' to ignore warnings, and
  33. # signal failure only when 'error' messages are emitted.
  34. #
  35. # If you need to test for an error condition explicitly, to find errors
  36. # that do not return any warning or error log messages on their own, you
  37. # can use the Drush php-eval command to force an error when `myfunction()`
  38. # returns FALSE. Replace 'myfunction()' with the name of an appropriate
  39. # function in your module that can be used to detect the error condition
  40. # you are looking for.
  41. #
  42. # $ git bisect run drush ev 'if(!myfunction()) { return drush_set_error("ERR"); }'
  43. #
  44. drush mycommand --myoption 2>&1 | grep -q 'string that indicates there was a problem'
  45. if [ $? == 0 ] ; then
  46. exit 1
  47. else
  48. exit 0
  49. fi