Patchwork [2,of,2] rebase: do not crash in panic when cwd disapear in the process (issue4121)

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 31, 2014, 11:23 p.m.
Message ID <b7814e8698c16c61dfb3.1391210606@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3424/
State Accepted
Commit e40520642e643a907899bab70ef8409754418a28
Headers show

Comments

Pierre-Yves David - Jan. 31, 2014, 11:23 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1391209995 28800
#      Fri Jan 31 15:13:15 2014 -0800
# Branch stable
# Node ID b7814e8698c16c61dfb3c0cbfe722bd78b6a4bdb
# Parent  33b269ec18fc46efd5616ce6ba98e189d7cd8923
rebase: do not crash in panic when cwd disapear in the process (issue4121)

Before this patch rebase crashed badly when it happend. (not abort, crash).

Fix courtesy of Matt Mackall.
Matt Mackall - Jan. 31, 2014, 11:35 p.m.
On Fri, 2014-01-31 at 15:23 -0800, pierre-yves.david@ens-lyon.org wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@logilab.fr>
> # Date 1391209995 28800
> #      Fri Jan 31 15:13:15 2014 -0800
> # Branch stable
> # Node ID b7814e8698c16c61dfb3c0cbfe722bd78b6a4bdb
> # Parent  33b269ec18fc46efd5616ce6ba98e189d7cd8923
> rebase: do not crash in panic when cwd disapear in the process (issue4121)

These are queued for stable, thanks.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -160,12 +160,16 @@  class dirstate(object):
                 return ''
             return f
         else:
             return fallback
 
+    @propertycache
+    def _cwd(self):
+        return os.getcwd()
+
     def getcwd(self):
-        cwd = os.getcwd()
+        cwd = self._cwd
         if cwd == self._root:
             return ''
         # self._root ends with a path separator if self._root is '/' or 'C:\'
         rootsep = self._root
         if not util.endswithsep(rootsep):
diff --git a/tests/test-rebase-scenario-global.t b/tests/test-rebase-scenario-global.t
--- a/tests/test-rebase-scenario-global.t
+++ b/tests/test-rebase-scenario-global.t
@@ -647,5 +647,30 @@  each root have a different common ancest
   | |
   | o  1: 'B'
   |/
   o  0: 'A'
   
+
+Test that rebase is not confused by $CWD disapearing during rebase (issue 4121)
+
+  $ cd ..
+  $ hg init cwd-vanish
+  $ cd cwd-vanish
+  $ touch initial-file
+  $ hg add initial-file
+  $ hg commit -m 'initial commit'
+  $ touch dest-file
+  $ hg add dest-file
+  $ hg commit -m 'dest commit'
+  $ hg up 0
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ touch other-file
+  $ hg add other-file
+  $ hg commit -m 'first source commit'
+  created new head
+  $ mkdir subdir
+  $ cd subdir
+  $ touch subfile
+  $ hg add subfile
+  $ hg commit -m 'second source with subdir'
+  $ hg rebase -b . -d 1 --traceback
+  saved backup bundle to $TESTTMP/cwd-vanish/.hg/strip-backup/779a07b1b7a0-backup.hg (glob)