Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for automatically gitignoring generated files #157

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

thufschmitt
Copy link
Member

Add a light gitignore abstraction allowing to define a set of gitignore patterns from Nickel, and plug that in to the file generation interface so that a generated file can also be git ignored by simply setting files.foo.gitignore = true

Théophane Hufschmitt added 2 commits October 17, 2023 14:25
Running `nix run .\#regenerate-files` now generates files locally
according to the `files` option in `project.ncl`.

This is still rather crude in a number of ways, but it is already
working (and used to generate this project's own `.gitignore`).

Fixes #144
Add a light `gitignore` abstraction allowing to define a set of
gitignore patterns from Nickel, and plug that in to the file generation
interface so that a generated file can also be git ignored by simply
setting `files.foo.gitignore = true`
@@ -0,0 +1,52 @@
# let nix = import "./nix-interop/nix.ncl" in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# let nix = import "./nix-interop/nix.ncl" in

: Bool
| doc "Whether to gitignore the file"
| default
= false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that each generated file will be added to .gitignore in one way or another. I think we should have a default option here that doesn't add it to .gitignore at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they aren't, the ones with gitignore = true are filtered out here.

But that indeed makes some slightly confusing semantics as it means that files.foo.gitignore has a different semantics than git.ignore."/foo".

|> std.array.map (fun { value = { target, .. }, .. } => { field = target, value = true })
|> std.record.from_array
in
let gitignore_content | { _ : Bool } -> String = fun ignores =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these functions should be in the final record so that users can add more .gitignore files to their repos.

fun pattern is_ignored =>
"%{if is_ignored then "" else "!"}%{pattern}"
)
|> std.record.values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should somehow provide a way to order these lines, because order is important in .gitignore

# let nix = import "./nix-interop/nix.ncl" in
let filegen = import "./files.ncl" in
let Gitignorable = {
gitignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be nested like git.ignore in case we want to add, for example, .gitattributes support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants