Search code examples
bashgitgit-bisect

`git bisect run` with a bash function


Is there a convenient way to write a bash script to run git bisect run, where the bisect command used is itself a bash function? If my function is named step, it appears that git bisect run step and git bisect run bash -c step are both unable to see the function.

My script currently looks something like

function step {
  # Do a bunch of steps here
}

if [[ $_ == $0 ]]  # Test if the script is being sourced
then
  git bisect start
  git bisect bad bad-commit
  git bisect good good-commit
  git bisect run bash -c ". $0 && step"
  git bisect log
fi

This uses a gross hack of making the script source itself in the command passed to git bisect run, and which means I have to check if the script is currently being sourced before attempting to execute the git bisect commands.

I suppose I could just split the bash function into a seperate script, buts there a better way to do this all in one file?


Solution

  • You can either export the function with export -f step or you can use set -a to export everything in your script.