diff --git a/.config/flakebox/id b/.config/flakebox/id index dc3e52f..c082c0a 100644 --- a/.config/flakebox/id +++ b/.config/flakebox/id @@ -1 +1 @@ -8bb96192c03f0918867d33632de433abfa4729d089956f3bd74b46ca6947aeaa50692d77fcc909cceb6c5656814182a519f4ba6550a02996cb7aafc3e06281c0 +b9ad9ff04d98afd64227c97d2239109110e1c6eb8224763f33b22f0fbad9d1973063cd3a9a27fd3a94829ead5606baf251741ec51dafba229ad9035cf3d7ce22 diff --git a/.config/flakebox/shellHook.sh b/.config/flakebox/shellHook.sh index 0544bd0..22184d9 100644 --- a/.config/flakebox/shellHook.sh +++ b/.config/flakebox/shellHook.sh @@ -13,20 +13,34 @@ root="$(git rev-parse --show-toplevel)" dot_git="$(git rev-parse --git-common-dir)" if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi # fix old bug -rm -f "${dot_git}/hooks/comit-msg" -rm -f "${dot_git}/hooks/commit-msg" -ln -sf "${root}/misc/git-hooks/commit-msg" "${dot_git}/hooks/commit-msg" +if [[ -e "${dot_git}/hooks/comit-msg" || -L "${dot_git}/hooks/comit-msg" ]]; then + rm -f "${dot_git}/hooks/comit-msg" +fi +hook="${dot_git}/hooks/commit-msg" +source="${root}/misc/git-hooks/commit-msg" +if [[ ! -e "${hook}" ]] || ! cmp -s "${source}" "${hook}"; then + rm -f "${hook}" + ln -sf "${source}" "${hook}" +fi root="$(git rev-parse --show-toplevel)" dot_git="$(git rev-parse --git-common-dir)" if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi # fix old bug -rm -f "${dot_git}/hooks/pre-comit" -rm -f "${dot_git}/hooks/pre-commit" -ln -sf "${root}/misc/git-hooks/pre-commit" "${dot_git}/hooks/pre-commit" +if [[ -e "${dot_git}/hooks/pre-comit" || -L "${dot_git}/hooks/pre-comit" ]]; then + rm -f "${dot_git}/hooks/pre-comit" +fi +hook="${dot_git}/hooks/pre-commit" +source="${root}/misc/git-hooks/pre-commit" +if [[ ! -e "${hook}" ]] || ! cmp -s "${source}" "${hook}"; then + rm -f "${hook}" + ln -sf "${source}" "${hook}" +fi # set template -git config commit.template misc/git-hooks/commit-template.txt +if [[ "$(git config --get commit.template || true)" != "misc/git-hooks/commit-template.txt" ]]; then + git config commit.template misc/git-hooks/commit-template.txt +fi if ! flakebox lint --silent; then >&2 echo "ℹ️ Project recommendations detected. Run 'flakebox lint' for more info." diff --git a/lib/modules/git.nix b/lib/modules/git.nix index 89204a5..0f9e7a0 100644 --- a/lib/modules/git.nix +++ b/lib/modules/git.nix @@ -132,9 +132,15 @@ in dot_git="$(git rev-parse --git-common-dir)" if [[ ! -d "''${dot_git}/hooks" ]]; then mkdir -p "''${dot_git}/hooks"; fi # fix old bug - rm -f "''${dot_git}/hooks/comit-msg" - rm -f "''${dot_git}/hooks/commit-msg" - ln -sf "''${root}/misc/git-hooks/commit-msg" "''${dot_git}/hooks/commit-msg" + if [[ -e "''${dot_git}/hooks/comit-msg" || -L "''${dot_git}/hooks/comit-msg" ]]; then + rm -f "''${dot_git}/hooks/comit-msg" + fi + hook="''${dot_git}/hooks/commit-msg" + source="''${root}/misc/git-hooks/commit-msg" + if [[ ! -e "''${hook}" ]] || ! cmp -s "''${source}" "''${hook}"; then + rm -f "''${hook}" + ln -sf "''${source}" "''${hook}" + fi '' ]; @@ -215,9 +221,15 @@ in dot_git="$(git rev-parse --git-common-dir)" if [[ ! -d "''${dot_git}/hooks" ]]; then mkdir -p "''${dot_git}/hooks"; fi # fix old bug - rm -f "''${dot_git}/hooks/pre-comit" - rm -f "''${dot_git}/hooks/pre-commit" - ln -sf "''${root}/misc/git-hooks/pre-commit" "''${dot_git}/hooks/pre-commit" + if [[ -e "''${dot_git}/hooks/pre-comit" || -L "''${dot_git}/hooks/pre-comit" ]]; then + rm -f "''${dot_git}/hooks/pre-comit" + fi + hook="''${dot_git}/hooks/pre-commit" + source="''${root}/misc/git-hooks/pre-commit" + if [[ ! -e "''${hook}" ]] || ! cmp -s "''${source}" "''${hook}"; then + rm -f "''${hook}" + ln -sf "''${source}" "''${hook}" + fi '' ]; @@ -236,7 +248,9 @@ in env.shellHooks = [ '' # set template - git config commit.template misc/git-hooks/commit-template.txt + if [[ "$(git config --get commit.template || true)" != "misc/git-hooks/commit-template.txt" ]]; then + git config commit.template misc/git-hooks/commit-template.txt + fi '' ];