Search code examples
mercurialclonepartial

Would like to do a mercurial clone with filter of patterns in hgignore


Over time a number of the developers have committed files that were then added to the .hgignore. From what I hear there is no way to remove items from the history of mercurial, which is ok. But I also heard that there is a way to do a clone, I think using the convert plugin, to clone/export a repo while specifying which files to not include in the conversion.

I can't help but think that someone out there has a script that does this export/filter/convert using the patterns from the .hgignore file.

Has anyone created such a beast?


Solution

  • You could create a filemap from .hgignore doing something like this:

    hg clone -U yourrepo temprepo # create a temp repo with no files in working dir
    cd tmprepo
    hg revert --all # put files in working dir
    hg forget **   # un-add the files
    hg status --ignored --no-status | sed 's/^/exclude /' > ../filemap
    

    that will get you a filemap you can pass into hg convert that removes all the added files that would be ignored given your .hgignore.

    Do understand though, that running convert creates a whole new repo that is unrelated to your previous repo. All existing clones will be unusable with the new one. It's not normally worth it.