You want to make a pull request to a Haskell project, which requires that each commit in your PR compiles fine individually.
Here is an easy, automated and fast way to check it:
git rebase --interactive HEAD~~~ --exec "! grep 'error:' <(stack ghci mylibrary:lib --ghci-options='-e 1' 2>&1)"Replace mylibrary:lib to put your Haskell package's name in. You can also give other targets like executables (see stack ide targets output).
Replace HEAD~~~ by how many commits you want to go back in history (this goes back 3).
If your Haskell project is in a subdirectory of your git repository, insert a cd like this: ... --exec 'cd subdirectory && ! grep ...
git rebase --interactiveallows you to go through the commit history of your branch and perform actions at each step.- One possible action is to run a command;
--execputs the given command after each commit. - The invocation above will pop up you editor to show what will be done; save and close that file to start the process. To abort at any time, use
git rebase --abort. - We use ghci's
-eoption to evaluate a simple expression (like-e 1to evaluate the number1) after all modules have been typechecked. This ensures ghci quits by itself after successful typechecking. - We use
grepas the command, searchin forerror:messages in the ghci output (with2>&1redirecting stderr to stdout so we can grep that too). - If there's a typechecking error, the interactive rebase will drop you in a shell at that commit, so you can fix it.
- Read the tutorials on interactive rebasing from git ready or from the Git book to learn how exactly interactive rebasing works.
I just discovered you can omit
--interactiveand then it doesn't bring up the initial editor.Also, you could use
HEAD~N(whereNis an integer) to go back further in history without having to addNtildes. Alternatively, you can use something likemaster@{u}..if your PR is targetting the upstream ofmaster.