Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check_phase to pre-commit settings #415

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions modules/pre-commit.nix
Original file line number Diff line number Diff line change
@@ -69,14 +69,14 @@ let
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git commit -m "init"
if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]]
then
echo "Running: $ pre-commit run --hook-stage manual --all-files"
${cfg.package}/bin/pre-commit run --hook-stage manual --all-files
else
echo "Running: $ pre-commit run --all-files"
${cfg.package}/bin/pre-commit run --all-files
fi
local check_stage=${toString cfg.check_stage}
case $check_stage in
commit | merge-commit | push)
check_stage="pre-"$check_stage
;;
esac
echo "Running: $ pre-commit run --hook-stage $check_stage --all-files"
${cfg.package}/bin/pre-commit run --hook-stage $check_stage --all-files
exitcode=$?
git --no-pager diff --color
touch $out
@@ -263,6 +263,16 @@ in
default = [ "commit" ];
};

check_stage =
mkOption {
type = types.str;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be the enum part of supportedHooksLib.supportedHooksType

description = lib.mdDoc
''
This is pre-commit stage to be used in a nix `checkPhase`. `commit` maps to `pre-commit`, which is `pre-commit`'s default.
'';
default = "commit";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could set this to the first of default_stages and fallback to pre-commit

};

rawConfig =
mkOption {
type = types.attrs;
3 changes: 2 additions & 1 deletion nix/run.nix
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ builtinStuff@{ pkgs, tools, isFlakes, pre-commit, git, runCommand, writeText, wr
, hooks ? { }
, excludes ? [ ]
, tools ? { }
, check_stage ? "commit"
, default_stages ? [ "commit" ]
}:
let
@@ -18,7 +19,7 @@ let
{
_module.args.pkgs = pkgs;
_module.args.gitignore-nix-src = gitignore-nix-src;
inherit hooks excludes default_stages settings;
inherit hooks excludes default_stages check_stage settings;
tools = builtinStuff.tools // tools;
package = pre-commit;
} // (if isFlakes