Repository navigation
feat: add native gitignore in fsutil - #10883
Conversation
ed8ad36 to
2a10ffd
Compare
0d564a3 to
88f9423
Compare
|
There's one failing check, that I'm unsure how to resolve. dagger/core/integration/module_test.go Lines 5094 to 5098 in 88f9423
|
If you try to access a directory that doesn't exist with our current API, it will error out, I think we should keep that DX to avoid inconsistency but maybe as you mention in option 2, with a specific error so the user can have a better understanding of why this dir/file is missing. |
88f9423 to
6df8034
Compare
| dagql.Arg("exclude").Doc(`Exclude artifacts that match the given pattern (e.g., ["node_modules/", ".git*"]).`), | ||
| dagql.Arg("include").Doc(`Include only artifacts that match the given pattern (e.g., ["app/", "package.*"]).`), | ||
| dagql.Arg("noCache").Doc(`If true, the directory will always be reloaded from the host.`), | ||
| dagql.Arg("noGitAutoIgnore").Doc(`Don't apply .gitignore filter rules inside the directory`), |
There was a problem hiding this comment.
Wondering about this.
I think this makes sense as the default, but it is a bit weird to me that users can't disable it when passing directories from the CLI.
Do we need a way to override it?
There was a problem hiding this comment.
I think we should have a way but how?
It may be simpler as a pragma so you can target a specific argument, because from the CLI it would be global to the dagger call cmd
func (e *Example) A(
//+noGitAutoIgnore
dir *dagger.Directory
) { ... } There was a problem hiding this comment.
Mm, yeah, but what about if it's not a contextual arg?
There was a problem hiding this comment.
Well that option can apply to any directory, even if it's not a contextual directory.
Because when we do dagger call a --dir /foo/bar, we look for the closest .git to see if we can apply git ignore, it's totally decouple from contextual argument in this case.
You may have //+noGitAutoIgnore but no //+defaultPath
There was a problem hiding this comment.
Sorry, my bad, I should have been clearer - what if it's not an arg at all - what if it's not a user function?
Like, what if it's a core function, or a function in a module you don't control?
We'd have to have weird flag syntax, something like --dir file:///foo/bar?noGitAutoIgnore=true.
I don't really love it, kind of why I'm suggesting #10883 (comment) in the meantime.
There was a problem hiding this comment.
Yeah I guess then no support for Host.directory except for module argument may be the solution.
I wonder what's @helderco opinion
There was a problem hiding this comment.
That's the problem with dagger call, but with shell there's no issue:
dagger -c 'a $(host | directory --no-git-auto-ignore /foo/bar)'
We could disable just for call, but then how would you enable it?
If it were up to me we'd deprecate dagger call in favor of shell instead of having this split.
There was a problem hiding this comment.
To clarify I think only in rare use cases people will want it off so my preference is to have it enabled by default as much as possible.
Also, dagger call is already more limited than shell in a lot of ways so it's not a deal breaker this is yet another thing, although I do understand if someone that needs it off already uses dagger call a lot it can be frustrating being forced to switch to shell syntax. That's why I'd rather not have this split in general. It creates friction.
There was a problem hiding this comment.
Yeah, okay, I'm happy with that answer 🎉
I'd consider this resolved!
|
Hm, mildly tempted to just have the default for Just do it for modules? That would resolve both the above issues for now. |
I think this should be split into two tests. In order to match func (t *Test) IgnoreDirButKeepFileInSubdir(
- // +ignore=["internal/telemetry", "!internal/telemetry/proxy.go"]
+ // +ignore=["internal/telemetry/**", "!internal/telemetry/proxy.go"]
// +defaultPath="./dagger"
dir *dagger.Directory,
) *dagger.Directory {
return dir
}But you raise an interesting question. What happens when you do have these patterns? I think like git, the second pattern should have no effect (basically |
|
Still struggling a bit here. I think I have two questions:
|
6df8034 to
cdc5f49
Compare
I think it’s reasonable. If it’s trivial it can be interesting to give a more specific error message but could be confusing if that doesn’t happen everywhere there’s exclude patterns filtering a directory (otherwise users may think that’s not the problem if the error doesn’t specify any exclude patterns).
Oh yeah, that’s a good point i.e., getting consistent behavior with git. How do you disallow overrides in
Agreed. I didn’t previously consider consistency with git here as far as the overrides are concerned, was just concerned about an escape hatch out of extreme caution. In that case, if an escape hatch ends up being necessary, I can support doing that through simply disabling the auto gitignore feature, as we already have (except on the CLI’s directory flag). |
TomChv
left a comment
There was a problem hiding this comment.
Left smalls comments, overall code is nice!
The tests part on fsxutil is 🔥
cdc5f49 to
bdb2f9b
Compare
|
Working on the failures, realized I had a misunderstanding of how the local/remote file interactions work |
Signed-off-by: Justin Chadwell <[email protected]>
bdb2f9b to
b6f41e3
Compare
|
There we go 😅 It needed the corresponding changes to Otherwise, we were syncing the remote -> local (using gitignore), but then filling up the snapshot using the entire contents of the local snapshot (not using the gitignore). Just required a little bit of hackery, but it works now! |
TomChv
left a comment
There was a problem hiding this comment.
Code LGTM, CI is green, I just left a question but I think we can merge that :D
I'll follow this up with a PR to dagOpFi host.Directory so we have better control on the option.
|
|
||
| includePatterns := make([]string, 0, 2+len(args.Include)) | ||
| if relPath != "." { | ||
| includePatterns = append(includePatterns, "!*", relPath) |
There was a problem hiding this comment.
It took me a while to understand how you could give the host path (context dir) but still make it work if we're important a children dir of that ctx dir but I get it with that line.
So just to be sure I understand, let's say we have a repo at /work and you import /work/bar/foo.
hostPath will be: /work
relpath will be : bar/foo
Include: ["!*", "bar/foo"] -> Everything is ignored except bar/foo
Then you do the rest of the logic with ignores etc...
Am I right or I misunderstood something?
There was a problem hiding this comment.
Yup, completely correct.
We also move the include/exclude paths to be "rebased".
I'll add a test for this, since it's a bit of a complex interaction. (edit: actually not needed, since all the existing include/exclude tests should cover this)
|
This change just broke my module constructor which refers to a file with a default name `"failed to get value for argument "args": select: failed to stat file' |
|
@jedevc Does this handle As a side note, git config's |
|
Adding another note (for me, most likely) - I don't think this works as expected if we have |
|
Pardon my ignorance, but how do I go from: // Sync files to S3 bucket
func (m *Aws) SyncToBucket(
ctx context.Context,
bucket string,
src *dagger.Directory,
...
ctr = ctr.WithMountedDirectory("/work", src)
...To this:
I don't know enough about Dagger to understand that yet 😅 ContextMkDocs static site, where the output dir is in I've worked around this by using a separate directory when running in Dagger locally vs fully automated, where I don't expect any accidental commits of the built files to happen. |
|
@staticaland You may be interested in #10994. You may be able to use the host functions directly to ensure the gitignore'd dir is available when needed. See |
Implements my suggestion in #10868 (comment).
We remove the original approach from #10736, which attempts to convert
gitignore-style patterns intodockerignore-style patterns (supported by buildkit, which uses mobypatternmatcher). Instead, we add agitignoreFS, which creates a filtered FS in the style offilterFS, but that automatically extracts gitignore filters from.gitignorefiles in the tree, and applies them using go-git.This has a couple of advantages:
go-gitensures we're as close togitas possible.