View Source mix git.test (ex_git_test v0.1.2)
Runs mix test
on the latest git commit, plus any staged changes.
Performs the following steps:
Creates a temporary directory (in the standard system location).
Runs
git diff --cached
(in the local tree) to extract staged changes.Clones the local tree into the temporary directory.
Applies the changes extracted in step 2.
Symlinks dependencies build directories from the local tree to cloned tree.
- This avoids needing to recompile dependencies, which aren't part of the check-in anyway.
Runs
mix test
, capturing the output (both stdout and stderr).- If it passes, great!
- If it fails, dumps the captured output and exits with a non-zero status.
Cleans up the temporary directory on exit.
This is intended to be used as part of a pre-commit hook, to help protect against forgetting to add new files, doing partial commits where some committed changes depend on changes not staged for commit, etc.
This task must be run in the test
environment, i.e. with
MIX_ENV=test
. In order to perform step 5, it needs an accurate list of
dependency build directories for the environment it will be testing in.
(Also, running the task itself in the test
environment ensures that all
dependencies will have been built beforehand.)
Use mix git.test.install
to install the default pre-commit hook.