Skip to content

🐞 defaultPath cannot use files ignored by .gitignore on dagger call #10994

Closed

Description

@TomChv

What is the issue?

With the new dagger version v0.18.17, we are automatically applying .gitignore when calling host.Directory.
But that means you can't use an ignored file as a argument anymore:

func (e *Example) Example(
  ctx context.Context

  //+defaultPath=./foo.txt
  foo *dagger.File,
  ...
) (...)
# .gitignore
foo.txt

See for the full context: https://discord.com/channels/707636530424053791/1413511775546118215

We need a way to bypass the .gitignore for specific argument or add the defaultPath to the list of include.
That may be the right quick fix

Dagger version

dagger v0.18.17

Steps to reproduce

No response

Log output

No response

Activity

  1. added
    kind/bug
    on Sep 5, 2025
  2. changed the title [-]🐞 Cannot use files ignored by .gitignore on `dagger call`[/-] [+]🐞 defaultPath cannot use files ignored by .gitignore on `dagger call`[/+] on Sep 5, 2025
  3. danielgafni commented on Sep 5, 2025

    @danielgafni

    Lol mine was 4 minutes later #10996. I guess I'll close it. Here is my original issue:

    This erroneously affects files that are already added staged (for ex with git add --force, or added prior to .gitignore modifications), but would have fallen under .gitignore if they wouldn't.

    I have a few small .mp4 files checked into the repo for testing purposes. My .gitignore also ignores **/.mp4. My tests in Dagger now started failing after an upgrade to 0.8.17.

    Files explicitly added to git should not be excluded from COPY operations - that's valid source code!

  4. TomChv commented on Sep 8, 2025

    @TomChv
    MemberAuthor

    I opened this PR to ensure we won't break old modules with the gitignore changes: #11011, I should have been done before the release but better later than never.

    I also did some tests and it seems it's absolutely impossible to bypass the auto ignore from a dagger call.
    But it's totally possible from dagger shell, here's an example:

    package main
    
    import (
    	"dagger/test/internal/dagger"
    )
    
    type Test struct{}
    
    func (m *Test) Repo(
    	//+defaultPath="/LICENSE"
    	file *dagger.File,
    ) *dagger.File {
    	return file
    }
    #.gitignore
    /dagger.gen.go
    /internal/dagger
    /internal/querybuilder
    /internal/telemetry
    /.env
    LICENSE
    

    🔴 FAIL:

    dagger call repo --file=./LICENSE contents 
    # failed to stat file /LICENSE: lstat /LICENSE: no such file or directory

    🟢 Work:

    dagger -c 'repo --file $(host | directory . --no-git-auto-ignore | file /LICENSE) | contents'
    #  Apache License
    # Version 2.0, January 2004
    # http://www.apache.org/licenses/
    # ...

    For a cleaner notation it's also possible to write it with variable directly from the CLI:

    dagger -c 'file=$(host | directory . --no-git-auto-ignore | file /LICENSE)
    repo --file $file | contents'
    
  5. shykes commented on Sep 8, 2025

    @shykes
    Contributor

    @jedevc @TomChv should we narrow the scope of auto-gitignore to only module loading, and not default arguments? It seems like a reasonable short-term fix:

    • It appears it would fix all real-world regressions we know about
    • It leaves the door open to expanding it later (without rushing)
    • We still get a major benefit with faster module loading

    wdyt?

  6. danielgafni commented on Sep 9, 2025

    @danielgafni

    @shykes it won't fix my issue: #10996

    Again, how come files added to git are ignored as well?

    It makes complete sense to auto-ignore random files that are not part of the source code (not added to git), but there may be legit source code files that overlap with .gitignore (git add --force, added before the .gitignore rule matching them was added)!

  7. shykes commented on Sep 9, 2025

    @shykes
    Contributor

    @shykes it won't fix my issue: #10996

    @danielgafni I wasn't sure, based on your issue, how exactly you consume those mp4 files. I assumed it was via an argument of type Directory or File, using +defaultPath. If that's the case, then the fix I propose would fix it, since .gitignore wouldn't apply to those files at all.

    Again, how come files added to git are ignored as well?

    It makes complete sense to auto-ignore random files that are not part of the source code (not added to git), but there may be legit source code files that overlap with .gitignore (git add --force, added before the .gitignore rule matching them was added)!

    That makes sense to me as well.

  8. danielgafni commented on Sep 9, 2025

    @danielgafni

    Oh sorry, I didn't pay attention, indeed I'm doing it with a Directory:

    IGNORE = Ignore(
        [
            ".env",
            ".git",
            "**/.venv",
            "**__pycache__**",
            ".dagger/sdk",
            "**/.pytest_cache",
            "**/.ruff_cache",
            "**/node_modules",
        ]
    )
    RootDir: TypeAlias = Annotated[
        dagger.Directory,
        IGNORE,
        DefaultPath("."),
    ]

    By the way, I find DefaultPath not working for me at all, I can't omit it in my commands. I still always have to pass --root-dir . Is something wrong with my code? 🤔

  9. TomChv commented on Sep 9, 2025

    @TomChv
    MemberAuthor

    By the way, I find DefaultPath not working for me at all, I can't omit it in my commands. I still always have to pass --root-dir . Is something wrong with my code? 🤔

    Default path is applied to function arguments, in your case it's seems that it's a field?

  10. danielgafni commented on Sep 9, 2025

    @danielgafni

    It's used as a function argument:

    @object_type
    class MyDaggerModule:
        @function
        async def build(
            self,
            root_dir: RootDir,
            project: str,
        ) -> Container:
  11. TomChv commented on Sep 9, 2025

    @TomChv
    MemberAuthor

    Try to inline it as a function argument instead of creating an external type, I'm not sure we support that kind of syntax.

  12. danielgafni commented on Sep 9, 2025

    @danielgafni

    I've tried that, it doesn't work as well. Very strange.

    From Python's perspective there shouldn't be a difference anyway, type annotations can be defined anywhere, there is no "inlining" concept.

    Btw let me know if you think this problem shouldn't be discussed in this particular issue.

  13. jedevc commented on Sep 9, 2025

    @jedevc
    Contributor

    Yes, please open a separate issue to discuss the python defaultPath issue.

  14. jedevc commented on Sep 10, 2025

    @jedevc
    Contributor

    Agree with @shykes here: #10994 (comment)

    There are fairly legitimate issues with the gitignore support right now, and I'm not sure applying them by default in all cases works.

    We've found why it's hard to do, but for module loading itself, we should be safe.

  15. sheldonhull commented on Sep 10, 2025

    @sheldonhull

    This snagged me yesterday as I tried to pass explicit paths that were in gitignore for post processing and encryption (.artifacts , .cache).

    While I love that by default more filtering is done, I'm attempting to produce artifacts and process items I want to cache/reload in next dagger call, such as testing pgp certs, yaml artifacts to further process, and others.

    The behavior I expected was letting me pass in a specific directory, and not filtering that. However, I think I'd be fine with it being filtered if I had some type of option that was something like // +no-auto-ignores so I could opt in to including files.

    In general I do think the behavior of respecting gitignore is actually really good.
    I corrupted a repo once because of a glitch because it was touching the .git directory and didn't end up copying the contents back out.
    Knowing the ignored content like git directory is excluded without me having to specify on every directory mounting of the repo is a good thing to me, as long as I can still choose to pass in options explicitly.

  16. added this to the v0.18.18 milestone on Sep 15, 2025
  17. nipuna-perera commented on Sep 15, 2025

    @nipuna-perera
    Contributor

    This just broke me so I also want to throw in my upvote here :). I have intermediate steps in a pipeline that produce artifacts that I don't want to be pushed to git but are still needed for pipeline functionality.

    Eg: lint reports and unit test coverage reports that I push to sonar. They are generated in separate dagger calls and written to local workspace. I need them to be loaded when my +defaultPath=. loads my workspace.

    From what I understand with #11017, the autoGitIgnore is going to be opt in right? That would be sufficient for me.

  18. shykes commented on Sep 15, 2025

    @shykes
    Contributor

    I already agree with the change, but for the record, I got bit by this again today 😭 While testing our handling of .env, my test environments were mysteriously losing .env files, the reason was, of course: .env is in .gitignore 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions