From 5133633e9fe6b144c8e00e3b212cdbd5a173b63d Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Thu, 25 Apr 2024 16:05:54 -0700 Subject: [PATCH] fix: Only update .gitignore when a link is indeed created (#56) --- lib/hooks/link.nix | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/hooks/link.nix b/lib/hooks/link.nix index ac9d8ec..546a3d4 100644 --- a/lib/hooks/link.nix +++ b/lib/hooks/link.nix @@ -29,24 +29,25 @@ in # Run extra shell hook extra_hook + + # Add this output to gitignore if not already + if ! test -f .gitignore + then + touch .gitignore + fi + if ! grep -qF "/${output}" .gitignore + then + if ! grep -qF "${gitignore-sentinel}" .gitignore + then + echo -e "\n# nixago: ${gitignore-sentinel}" >> .gitignore + fi + newgitignore="$(awk '1;/${gitignore-sentinel}/{ print "/${output}"; }' .gitignore)" + echo -e -n "$newgitignore" > .gitignore + git add .gitignore + log "${ansi.bold}${ansi."11"}'/${output}' added to .gitignore${ansi.reset}" + fi else # this was an existing file error "refusing to overwrite '${output}'" fi - # Add this output to gitignore if not already - if ! test -f .gitignore - then - touch .gitignore - fi - if ! grep -qF "/${output}" .gitignore - then - if ! grep -qF "${gitignore-sentinel}" .gitignore - then - echo -e "\n# nixago: ${gitignore-sentinel}" >> .gitignore - fi - newgitignore="$(awk '1;/${gitignore-sentinel}/{ print "/${output}"; }' .gitignore)" - echo -e -n "$newgitignore" > .gitignore - git add .gitignore - log "${ansi.bold}${ansi."11"}'/${output}' added to .gitignore${ansi.reset}" - fi ''