Skip to content

Commit

Permalink
feat: automatically add linked files to gitignore
Browse files Browse the repository at this point in the history
closes: #27
  • Loading branch information
blaggacao committed Jul 30, 2022
1 parent 1c8f4b3 commit e09d602
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
pkgs.nixpkgs-fmt
pkgs.nodePackages.prettier
pkgs.typos
pkgs.gitMinimal
];

# Define development tool configuration (with Nixago!)
Expand Down
18 changes: 18 additions & 0 deletions lib/hooks/link.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ configFile, hookConfig }:
let
inherit (hookConfig) output extra;

gitignore-sentinel = "ignore-linked-files";
in
''
# Check if the link is pointing to the existing derivation result
Expand All @@ -25,4 +27,20 @@ in
# 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 "${output} added to .gitignore"
fi
''

0 comments on commit e09d602

Please sign in to comment.