# HG changeset patch # User Stanislau Hlebik # Date 1475579208 25200 # Node ID 90a6c18a7c1d5ca827cf55a24ca242cf4630bc55 # Parent 7a3b59f0329ad7c3823a1c164d815a51411103b2 update: warn if cwd was deleted During update directories are deleted as soon as they have no entries. But if current working directory is deleted then it cause problems in complex commands like 'hg split'. This commit adds a warning that will help users figure the problem faster. diff -r 7a3b59f0329a -r 90a6c18a7c1d mercurial/merge.py --- a/mercurial/merge.py Thu Oct 13 13:34:53 2016 +0200 +++ b/mercurial/merge.py Tue Oct 04 04:06:48 2016 -0700 @@ -1038,6 +1038,12 @@ unlink = util.unlinkpath wjoin = repo.wjoin audit = repo.wvfs.audit + try: + cwd = os.getcwd() + except OSError as err: + if err.errno != errno.ENOENT: + raise + cwd = None i = 0 for f, args, msg in actions: repo.ui.debug(" %s: %s -> r\n" % (f, msg)) @@ -1055,6 +1061,18 @@ i += 1 if i > 0: yield i, f + if cwd: + # cwd was present before we started to remove files + # let's check if it is present after we removed them + try: + os.getcwd() + except OSError as err: + if err.errno != errno.ENOENT: + raise + # Print a warning if cwd was deleted + repo.ui.warn(_("current directory was removed\n" + "(consider changing to repo root: %s)\n") % + repo.root) def batchget(repo, mctx, actions): """apply gets to the working directory diff -r 7a3b59f0329a -r 90a6c18a7c1d tests/test-rebase-scenario-global.t --- a/tests/test-rebase-scenario-global.t Thu Oct 13 13:34:53 2016 +0200 +++ b/tests/test-rebase-scenario-global.t Tue Oct 04 04:06:48 2016 -0700 @@ -758,6 +758,8 @@ $ hg commit -m 'second source with subdir' $ hg rebase -b . -d 1 --traceback rebasing 2:779a07b1b7a0 "first source commit" + current directory was removed + (consider changing to repo root: $TESTTMP/cwd-vanish) rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip) saved backup bundle to $TESTTMP/cwd-vanish/.hg/strip-backup/779a07b1b7a0-853e0073-backup.hg (glob) diff -r 7a3b59f0329a -r 90a6c18a7c1d tests/test-update-names.t --- a/tests/test-update-names.t Thu Oct 13 13:34:53 2016 +0200 +++ b/tests/test-update-names.t Tue Oct 04 04:06:48 2016 -0700 @@ -72,3 +72,15 @@ $ cd .. #endif + +Test that warning is printed if cwd is deleted during update + $ hg init r4 && cd r4 + $ mkdir dir + $ cd dir + $ echo a > a + $ echo b > b + $ hg add a b + $ hg ci -m "file and dir" + $ hg up -q null + current directory was removed + (consider changing to repo root: $TESTTMP/r1/r4)