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 --interactive
allows you to go through the commit history of your branch and perform actions at each step.- One possible action is to run a command;
--exec
puts 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
-e
option to evaluate a simple expression (like-e 1
to evaluate the number1
) after all modules have been typechecked. This ensures ghci quits by itself after successful typechecking. - We use
grep
as the command, searchin forerror:
messages in the ghci output (with2>&1
redirecting 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.
Also relevant for non-interactive use:
https://stackoverflow.com/questions/12394166/how-do-i-run-git-rebase-interactive-in-non-interactive-manner/37224000#37224000