Skip to content

Commit

Permalink
Fix hooksPath when configured from a subdirectory
Browse files Browse the repository at this point in the history
Resolves #358.
  • Loading branch information
sandydoo committed Nov 15, 2023
1 parent ea758da commit e6442c7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,17 @@ in
else
pre-commit install
fi
${git}/bin/git config --local core.hooksPath "$(${git}/bin/git rev-parse --git-common-dir)/hooks"
# Fetch the relative path to the root of the git repository
cdup=''$(${git}/bin/git rev-parse --show-cdup)
# Fetch the relative path to the git common directory. Normally set to .git.
common_dir=''$(${git}/bin/git rev-parse --path-format=relative --git-common-dir)
# When run in a subdirectory, the common directory will be a relative path up from that subdirectory.
# What we want instead is a path to the common directory, relative to the root.
common_dir=''${common_dir#''$cdup}
${git}/bin/git config --local core.hooksPath "''$common_dir/hooks"
fi
fi
fi
Expand Down

0 comments on commit e6442c7

Please sign in to comment.