Skip to content

keep .git when cleaning dist - #980

Merged
ctron merged 1 commit into
trunk-rs:mainfrom
celex3:main
Nov 3, 2026
Merged

ctron merged 1 commit into
trunk-rs:mainfrom
celex3:main

Conversation

@celex3

@celex3 celex3 commented Apr 19, 2025

Copy link
Copy Markdown
Contributor

When cleaning the dist directory before moving build artifacts from the staging area, if a .git file exists, it should not be removed. This allows Trunk to build into a git worktree, for example.

This behavior also exists in Vite which was introduced in this PR. Part of their justification is that a .git file could not be generated by Vite, but I'm not sure if this invariant holds for Trunk.

@ctron ctron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sounds reasonable and looks good to me.

Might be cool to have a list instead of "or".

@celex3

celex3 commented Apr 22, 2025

Copy link
Copy Markdown
Contributor Author

Something like this?

if [STAGE_DIR, ".git"].iter().any(|s| entry.file_name() == *s) {
    continue;
}

I also tried using contains but converting the OsString to a &&str is a little cumbersome:

if [STAGE_DIR, ".git"].contains(&&*entry.file_name().to_string_lossy()) {
    continue;
}

I feel like the "or" is a little more readable than either of these, but there might be a better way that what I have here.

@ctron

ctron commented Apr 24, 2025

Copy link
Copy Markdown
Collaborator

I though about adding a const list, and the using that list. So that, later on, that can easily be extended.

@duke-m

duke-m commented May 12, 2025 •

Copy link
Copy Markdown
Contributor

what about having something (sketched) like this in pub struct clean and using it here:

    #[arg(short, long, env = "TRUNK_CLEAN_PRESERVE_FILES")]
    pub preserve_files: Option<Vec<String>>

ctron added a commit to celex3/trunk that referenced this pull request Nov 3, 2026
Revives trunk-rs#980 with opt-in preservation for builds and clean.

Co-authored-by: Lucas Clark <[email protected]>
ctron added a commit to celex3/trunk that referenced this pull request Nov 3, 2026
Revives trunk-rs#980 with opt-in preservation for builds and clean.

Co-authored-by: Lucas Clark <[email protected]>
Revives trunk-rs#980 with opt-in preservation for builds and clean.

Co-authored-by: Lucas Clark <[email protected]>
@ctron
ctron enabled auto-merge November 3, 2026 07:03
@ctron
ctron added this pull request to the merge queue Nov 3, 2026
Merged via the queue into trunk-rs:main with commit d9d2811 Nov 3, 2026
63 checks passed
@ctron

ctron commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Sorry, it took me a bit to come back to this. should be in the next release.

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