mercurialpurgemercurial-extension

"hg purge" deleted tracked file


I know it is strange but I was updating my testcases and thought of removing all the untracked files from the testcase so ran hg purge, but apart from deleting untracked file it deleted tracked files for 230+ testcases too.

Is there any way to revert back to original or can I get the files back? These files are on the server so I can get it by pulling it from server, but this is not helpful as I have to update it again.


Solution

  • If you have modified Working Directory ("modified" by any way) you can easy discard changes and return to the state of clean "."-changeset using

    hg up -C -r .

    And yes, follow-up to @torek, hg purge must not touch tracked files, because, according to its wiki

    extension purges all files and directories not being tracked by Mercurial in the current repository

    but I can see one possible case, why its may happen. Next para in description sheds some light on topic:

    With the --all option, it will also remove ignored files

    (and some pure speculation below...)

    If you had files in .hgignore and added these files into repository by hand (you can hg add ignored files), purge probably may delete these files.

    You can (rather easy) verify my idea after returning to good state of repo

    1. Install|add hg-isignored extension (Bitbucket, will disapper soon due to BB-refugee from HG) and check ignorance state of versioned, but deleted by extension files (at least some of) - you'll see result and used pattern from .hgignore
    2. Try (again) hg purge --print in order to get list of purged files. If lists (deleted and ignored versoned files) will have intersections, then you'll get answer on question "Why?"

    I can't see any other reasons for such behavior of the extension.