threads / discuss / 2690

git-mv: fully detect 'directory moved into itself'

Subject: git-mv: fully detect 'directory moved into itself'

## tl;dr

4 messages between Nov 27, 2005 and Nov 28, 2005.

replies: 3people: 3as markdown or json

Josef Weidendorfer· Nov 27, 2005, 21:06 UTC · lore

This gives a better error message when trying to move a directory into some subdirectory of itself; ie. no real bug fix: renaming already failed before, but with a strange "invalid argument".

Signed-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
---
 git-mv.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

applies-to: 5d83477de7a407ab0ef183c6676114e1a507cf86 29b01f820bf24c4b697765a2a117c880a730b205

diff --git a/git-mv.perl b/git-mv.perl
index ac19876..8d294d6 100755
--- a/git-mv.perl
+++ b/git-mv.perl
@@ -108,7 +108,7 @@ while(scalar @srcArgs > 0) {
 	}
     }
     
-    if (($bad eq "") && ($src eq $dstDir)) {
+    if (($bad eq "") && ($dst =~ /^$src\//)) {
 	$bad = "can not move directory '$src' into itself";
     }
 
---
0.99.9.GIT
Matthias Urlichs· Nov 28, 2005, 06:54 UTC · re: Josef Weidendorfer · lore

Re: git-mv: fully detect 'directory moved into itself'

Hi, Josef Weidendorfer wrote:
> +    if (($bad eq "") && ($dst =~ /^$src\//)) {
That should be
> +    if (($bad eq "") && ($dst =~ /^\Q$src\E\//)) {
otherwise you will mistakenly match "foo-bar" with "foo.bar".
-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de
 - -
If people drank ink instead of Schlitz, they'd be better off.
		-- Edward E. Hippensteel

[What brand of ink?  Ed.]
Josef Weidendorfer· Nov 28, 2005, 09:15 UTC · re: Matthias Urlichs · lore

[PATCH] git-mv: fully detect 'directory moved into itself'

This gives a better error message when trying to move a directory into some subdirectory of itself; ie. no real bug fix: renaming already failed before, but with a strange "invalid argument".

Signed-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
---
This is a corrected version.
On Monday 28 November 2005 07:54, Matthias Urlichs wrote:
Show 10 quoted lines
> Hi, Josef Weidendorfer wrote:
> 
> > +    if (($bad eq "") && ($dst =~ /^$src\//)) {
> 
> That should be
> 
> > +    if (($bad eq "") && ($dst =~ /^\Q$src\E\//)) {
> 
> otherwise you will mistakenly match "foo-bar" with "foo.bar".
> 

Ah, thanks. You never end learning.

Josef
 git-mv.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

applies-to: 5d83477de7a407ab0ef183c6676114e1a507cf86 3c1ed8adaff3f7492ef2afdb5585ae7412a02817

diff --git a/git-mv.perl b/git-mv.perl
index ac19876..bfe3c29 100755
--- a/git-mv.perl
+++ b/git-mv.perl
@@ -108,7 +108,7 @@ while(scalar @srcArgs > 0) {
 	}
     }
     
-    if (($bad eq "") && ($src eq $dstDir)) {
+    if (($bad eq "") && ($dst =~ /^\Q$src\E\//)) {
 	$bad = "can not move directory '$src' into itself";
     }
 
---
0.99.9.GIT
Junio C Hamano· Nov 28, 2005, 09:24 UTC · re: Josef Weidendorfer · lore

Re: [PATCH] git-mv: fully detect 'directory moved into itself'

Josef Weidendorfer <Josef.Weidendorfer@gmx.de> writes:
Show 15 quoted lines
> This is a corrected version.
>
> On Monday 28 November 2005 07:54, Matthias Urlichs wrote:
>> Hi, Josef Weidendorfer wrote:
>> 
>> > +    if (($bad eq "") && ($dst =~ /^$src\//)) {
>> 
>> That should be
>> 
>> > +    if (($bad eq "") && ($dst =~ /^\Q$src\E\//)) {
>> 
>> otherwise you will mistakenly match "foo-bar" with "foo.bar".
>
> Ah, thanks.
> You never end learning.
Why not use $safesrc you already have for this exact purpose?

← back to recent threads