Skip to content

keep .git when cleaning dist - #980

Open
celex3 wants to merge 2 commits into
trunk-rs:mainfrom
celex3:main
Open

keep .git when cleaning dist#980
celex3 wants to merge 2 commits into
trunk-rs:mainfrom
celex3:main

Conversation

@celex3

@celex3 celex3 commented Apr 19, 2025

Copy link
Copy Markdown

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
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>>

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