When using [Sapling SCM](https://sapling-scm.com/) with a Git
repository, precommit expectedly fails today because it shells
out to `git` to get the list of modified files in the working
copy. In a Sapling clone of a Git repository, these calls will
fail.
While most of the logic in precommit that deals with talking
to Git today is encapsulated in `git.py`, calls to `git` are
sprinkled throughout the project and are called directly. In
order to support alternative SCMs, such as Sapling, ideally
there would be a more generic "SCM" interface that business
logic would call into with both Git and Sapling implementations.
Though this PR does not attempt to introduce such an interface.
Instead, it is just a basic PoC to provide evidence that
something like this could be made to work. For the moment, it
takes a shortcut and simply sprinkles "if Sapling" checks
in `git.py` in enough places that I could get precommit to
run in a Sapling working copy in the simple case where I had
only one file modified locally.
My higher-level question is whether the precommit project
would be open to accepting changes to support Sapling,
either via the introduction of an SCM-agnostic interface or
some other means.
When git status runs in a repo with submodules, it'll recursively run
git status in every submodule as well by default (sequentially).
git status is substantially slower on Windows than on Linux. git diff
behaves similarly to git status in terms of running recursively within
all submodules. In repos with hundreds of submodules, this quickly adds
up when git status/diff are called multiple times. Pre-commit runs
git status once at the beginning of an operation and then runs git diff
before and after each hook. These calls quickly add up and make
pre-commit unusable in large repos with lots of submodules.
This commit drastically improves performance in repos with lots of
submodules and fixes#1701 by telling git status and git diff to ignore
submodules. This change is not expected to have any negative effect on
existing hooks because each submodule should manage its own hooks
instead of relying on superproject hooks to manipulate their contents.
If using the prepare-commit-msg and commit-msg stages specifically (such
as with the try-repo command), the `--commit-msg-filename` arg must be
provided.
[fixes#1336]
chore: improve error message for hook stage check