Skip to content

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.

Base automatically changed from filegen to main October 18, 2023 12:28
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.

3 participants