Patchwork [V2] update: warn if cwd was deleted

login
register
mail settings
Submitter Stanislau Hlebik
Date Sept. 2, 2016, 8:43 p.m.
Message ID <374caff3f6ba064070d0.1472849012@dev1918.lla1.facebook.com>
Download mbox | patch
Permalink /patch/16539/
State Superseded
Headers show

Comments

Stanislau Hlebik - Sept. 2, 2016, 8:43 p.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1472848944 25200
#      Fri Sep 02 13:42:24 2016 -0700
# Node ID 374caff3f6ba064070d01329eec1bd33a6a45370
# Parent  318e2b600b80e4ed3c6f37df46ec7544f60d4c0b
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.
timeless - Sept. 2, 2016, 10:40 p.m.
I'd suggest printing the absolute path to the repo root. Asking someone to
run a command from an imaginary directory is asking for trouble. "cd .."
Might fail...

On Sep 2, 2016 4:44 PM, "Stanislau Hlebik" <stash@fb.com> wrote:

> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1472848944 25200
> #      Fri Sep 02 13:42:24 2016 -0700
> # Node ID 374caff3f6ba064070d01329eec1bd33a6a45370
> # Parent  318e2b600b80e4ed3c6f37df46ec7544f60d4c0b
> 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 --git a/mercurial/merge.py b/mercurial/merge.py
> --- a/mercurial/merge.py
> +++ b/mercurial/merge.py
> @@ -1043,7 +1043,19 @@
>              repo.ui.note(_("removing %s\n") % f)
>          audit(f)
>          try:
> -            unlink(wjoin(f), ignoremissing=True)
> +            try:
> +                cwd = os.getcwd()
> +            except OSError:
> +                cwd = None
> +            path = wjoin(f)
> +            unlink(path, ignoremissing=True)
> +            try:
> +                os.getcwd()
> +            except OSError:
> +                # Print a warning if cwd was deleted
> +                if cwd and path.startswith(cwd):
> +                    repo.ui.warn(_("cwd was deleted - consider "
> +                                   "changing cwd to repo root\n"))
>          except OSError as inst:
>              repo.ui.warn(_("update failed to remove %s: %s!\n") %
>                           (f, inst.strerror))
> 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
> @@ -758,6 +758,7 @@
>    $ hg commit -m 'second source with subdir'
>    $ hg rebase -b . -d 1 --traceback
>    rebasing 2:779a07b1b7a0 "first source commit"
> +  cwd was deleted - consider changing cwd to repo root
>    rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
>    saved backup bundle to $TESTTMP/cwd-vanish/.hg/strip-
> backup/779a07b1b7a0-853e0073-backup.hg (glob)
>
> diff --git a/tests/test-update-names.t b/tests/test-update-names.t
> --- a/tests/test-update-names.t
> +++ b/tests/test-update-names.t
> @@ -72,3 +72,14 @@
>    $ 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
> +  cwd was deleted - consider changing cwd to repo root
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Pierre-Yves David - Sept. 6, 2016, 12:36 p.m.
On 09/02/2016 10:43 PM, Stanislau Hlebik wrote:
> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1472848944 25200
> #      Fri Sep 02 13:42:24 2016 -0700
> # Node ID 374caff3f6ba064070d01329eec1bd33a6a45370
> # Parent  318e2b600b80e4ed3c6f37df46ec7544f60d4c0b
> 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.

There is a precedence about this scenarion in 'rebase'. Did anyone 
checked it out. We should probably ensure we have a unify approach here.
Yuya Nishihara - Sept. 6, 2016, 12:54 p.m.
On Tue, 6 Sep 2016 14:36:58 +0200, Pierre-Yves David wrote:
> On 09/02/2016 10:43 PM, Stanislau Hlebik wrote:
> > # HG changeset patch
> > # User Stanislau Hlebik <stash@fb.com>
> > # Date 1472848944 25200
> > #      Fri Sep 02 13:42:24 2016 -0700
> > # Node ID 374caff3f6ba064070d01329eec1bd33a6a45370
> > # Parent  318e2b600b80e4ed3c6f37df46ec7544f60d4c0b
> > 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.
> 
> There is a precedence about this scenarion in 'rebase'. Did anyone
> checked it out. We should probably ensure we have a unify approach here.

Er, this?

https://selenic.com/repo/hg/rev/e40520642e64
Pierre-Yves David - Sept. 6, 2016, 1:05 p.m.
On 09/06/2016 02:54 PM, Yuya Nishihara wrote:
> On Tue, 6 Sep 2016 14:36:58 +0200, Pierre-Yves David wrote:
>> On 09/02/2016 10:43 PM, Stanislau Hlebik wrote:
>>> # HG changeset patch
>>> # User Stanislau Hlebik <stash@fb.com>
>>> # Date 1472848944 25200
>>> #      Fri Sep 02 13:42:24 2016 -0700
>>> # Node ID 374caff3f6ba064070d01329eec1bd33a6a45370
>>> # Parent  318e2b600b80e4ed3c6f37df46ec7544f60d4c0b
>>> 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.
>>
>> There is a precedence about this scenarion in 'rebase'. Did anyone
>> checked it out. We should probably ensure we have a unify approach here.
>
> Er, this?
>
> https://selenic.com/repo/hg/rev/e40520642e64

Yep
Pierre-Yves David - Sept. 6, 2016, 4:01 p.m.
On 09/06/2016 06:00 PM, Kevin Bullock wrote:
>> On Sep 2, 2016, at 15:43, Stanislau Hlebik <stash@fb.com> wrote:
>>
>> # HG changeset patch
>> # User Stanislau Hlebik <stash@fb.com>
>> # Date 1472848944 25200
>> #      Fri Sep 02 13:42:24 2016 -0700
>> # Node ID 374caff3f6ba064070d01329eec1bd33a6a45370
>> # Parent  318e2b600b80e4ed3c6f37df46ec7544f60d4c0b
>> 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 --git a/mercurial/merge.py b/mercurial/merge.py
>> --- a/mercurial/merge.py
>> +++ b/mercurial/merge.py
>> @@ -1043,7 +1043,19 @@
>>             repo.ui.note(_("removing %s\n") % f)
>>         audit(f)
>>         try:
>> -            unlink(wjoin(f), ignoremissing=True)
>> +            try:
>> +                cwd = os.getcwd()
>> +            except OSError:
>> +                cwd = None
>> +            path = wjoin(f)
>> +            unlink(path, ignoremissing=True)
>> +            try:
>> +                os.getcwd()
>> +            except OSError:
>> +                # Print a warning if cwd was deleted
>> +                if cwd and path.startswith(cwd):
>> +                    repo.ui.warn(_("cwd was deleted - consider "
>> +                                   "changing cwd to repo root\n"))
>
> I'd much rather have "current working directory" spelled out. Not all users are going to be familiar with Unix's often questionably-sensible abbreviations for things.

+1

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1043,7 +1043,19 @@ 
             repo.ui.note(_("removing %s\n") % f)
         audit(f)
         try:
-            unlink(wjoin(f), ignoremissing=True)
+            try:
+                cwd = os.getcwd()
+            except OSError:
+                cwd = None
+            path = wjoin(f)
+            unlink(path, ignoremissing=True)
+            try:
+                os.getcwd()
+            except OSError:
+                # Print a warning if cwd was deleted
+                if cwd and path.startswith(cwd):
+                    repo.ui.warn(_("cwd was deleted - consider "
+                                   "changing cwd to repo root\n"))
         except OSError as inst:
             repo.ui.warn(_("update failed to remove %s: %s!\n") %
                          (f, inst.strerror))
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
@@ -758,6 +758,7 @@ 
   $ hg commit -m 'second source with subdir'
   $ hg rebase -b . -d 1 --traceback
   rebasing 2:779a07b1b7a0 "first source commit"
+  cwd was deleted - consider changing cwd to repo root
   rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
   saved backup bundle to $TESTTMP/cwd-vanish/.hg/strip-backup/779a07b1b7a0-853e0073-backup.hg (glob)
 
diff --git a/tests/test-update-names.t b/tests/test-update-names.t
--- a/tests/test-update-names.t
+++ b/tests/test-update-names.t
@@ -72,3 +72,14 @@ 
   $ 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
+  cwd was deleted - consider changing cwd to repo root