Bug 5901 - when run from subdirectory, "hg rm *" deletes current working directory
Summary: when run from subdirectory, "hg rm *" deletes current working directory
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: 4.6
Hardware: PC Linux
: wish bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-29 17:33 UTC by Martin von Zweigbergk
Modified: 2018-07-11 00:00 UTC (History)
3 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin von Zweigbergk 2018-05-29 17:33 UTC
$ mkdir dir
  $ echo x > dir/x
  $ hg ci -Aqm add
  $ cd dir
  $ hg rm -q x
  $ hg st
  abort: error getting current working directory: $ENOENT$
  [255]
  $ cd $TESTTMP/a
  $ hg co -qC .
Comment 1 Yuya Nishihara 2018-05-30 07:54 UTC
Maybe we'll have to explicitly pin the cwd?
Comment 2 Kyle Lippincott 2018-06-05 20:45 UTC
I'm planning on making a patch to make the rmdir of empty directories configurable, so it can just be disabled regardless of whether the user is in the directory or not.  I think it's really weird that a somewhat equivalent set of commands, just without going into `dir` first, ends up deleting `dir`.  

I want a comprehensive set of tests for the various places that end up doing this (including histedit, rebase, rm, prune, etc.) so it's going to be a bit, if someone else wants to pick this up before then :P
Comment 3 Kyle Lippincott 2018-06-28 21:11 UTC
I've sent https://phab.mercurial-scm.org/D3859 to try to resolve this issue.
Comment 4 HG Bot 2018-07-03 12:05 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/da2a7d8354b2
Kyle Lippincott <spectral@google.com>
unlinkpath: make empty directory removal optional (issue5901) (issue5826)

There are known cases where performing operations such as rebase from a
directory that is newly created can fail or at least lead to being in a
directory handle that no longer exists.

This is even reproducible by just doing something as simple as:

    cd foo; hg rm *

The behavior is different if you use `hg addremove`, the directory is not
removed until we attempt to go back to the node after committing it:

    cd foo; rm *; hg addremove; hg ci -m'bye foo'; hg co .^; hg co tip

Differential Revision: https://phab.mercurial-scm.org/D3859

(please test the fix)
Comment 5 Bugzilla 2018-07-11 00:00 UTC
Bug was set to TESTING for 7 days, resolving