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 3f20a39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
devShells = {
default = pkgs.mkShell {
shellHook = (lib.makeAll configs).shellHook;
packages = tools.all;
packages = tools.all ++ [ pkgs.gitMinimal ];
};
};
}
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 3f20a39

Please sign in to comment.