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:

  1. Creates a temporary directory (in the standard system location).

  2. Runs git diff --cached (in the local tree) to extract staged changes.

  3. Clones the local tree into the temporary directory.

  4. Applies the changes extracted in step 2.

  5. 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.
  6. 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.
  7. 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.