1. Bill_Barry
  2. hgattic
Issue #2 open

shelving/unshelving file adds trips over itself

Joel Mohler
created an issue

If you have an added file (with 'hg add') and shelve it properly includes the added file in the patch. However, it leaves that file sitting in the repo. This in itself is not a bug, but the unshelve of that patch then complains because the file prevents the patch from being applied.

I think it would be ideal if the 'A' status files were removed when they are shelve'd.

{{{ c:\builds\test>cat file2.txt Line 1 of file 2 c:\builds\test>hg add file2.txt c:\builds\test>hg shelve a_patch.patch patch a_patch.patch shelved c:\builds\test>hg status ? file2.txt c:\builds\test>hg unshelve a_patch.patch file file2.txt already exists 1 out of 1 hunks FAILED -- saving rejects to file file2.txt.rej patch failed, unable to continue (try -v) }}}

Comments (7)

  1. Anonymous

    There seem to be two cases for an added file being shelved:

    1) You just created this file, and it is related to the other changes for an upcoming commit.

    2) This file has been around for a while, and you just got around to letting mercurial know about it.

    For case 1, automatically deleting added files during 'hg shelve' seems to be the logical answer, leaving the working dir as it was during the last commit.

    For case 2, we might still want to have this file around, and it's deletion would be annoying, and a patch to 'hg unshelve' would be preferable.

    Personally, I think case 2 would be extremely rare and the behavior I expected would be for the shelve command to delete added files.

    As for implementing this fix, a quick glance at the code shows cleanup calling one of hg.clean or commands.revert, both of which forget about added files instead of deleting them. A quick glance at those does not reveal a simple option to delete added files.

  2. Anonymous

    Another option:

    file this as a bug upstream with revert.

    Current revert functionality: added file -> untracted file

    Proposed functionality: added file -> untracted file.orig

    shelve's default behavior of reverting without backups would then do the right thing and remove the file.

  3. Martin Geisler

    We were just discussing this on IRC today: I pointed a new user to your extension and you can imagine his surprice when he saw that his newly added files were not shelved away correctly.

    Please incorporate the functionality from mq.py lines 1085-1100:

                    m, a, r, d = repo.status(qp, top)[:4]
                    if d:
                        raise util.Abort(_("deletions found between repo revs"))
                    for f in m:
                        getfile(f, mmap[f], mmap.flags(f))
                    for f in r:
                        getfile(f, mmap[f], mmap.flags(f))
                    for f in m + r:
                        repo.dirstate.normal(f)
                    for f in a:
                        try:
                            os.unlink(repo.wjoin(f))
                        except OSError, e:
                            if e.errno != errno.ENOENT:
                                raise
                        try: os.removedirs(os.path.dirname(repo.wjoin(f)))
                        except: pass
                        repo.dirstate.forget(f)
    
  4. Anonymous

    First time usage of this extension and run in this error at first. I am not amused ;)

    I think to clone the repos as a copy, and pull the changes from the origin repos and push the changes to the main-repos, may be the safer way. I thought this is what this extension should do.

  5. Log in to comment