Git development
 help / color / mirror / Atom feed
From: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
To: git@vger.kernel.org
Cc: Junio C Hamano <junkio@cox.net>, Alexander Litvinov <lan@ac-sw.com>
Subject: [PATCH] Fix cg-mv for moving directories with 1 file
Date: Wed, 23 Nov 2005 12:04:23 +0100	[thread overview]
Message-ID: <200511231204.24571.Josef.Weidendorfer@gmx.de> (raw)

This is fixed by putting the file into @changedfiles/@addedfiles,
and not the directory this file is in.

Additionally, this fixes the behavior for attempting to overwrite
a file with a directory, and gives a message for all cases where
overwriting is not possible (file->dir,dir->file,dir->dir).

Thanks for Alexander Litvinov for noting this problem.

Signed-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

---

This should fix the wrong behavior.
Alexander, can you confirm this?


 git-mv.perl |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

applies-to: 5bc7f67c535dbbbb9340285c82226a8dd6e4afec
5237e9ac4adc6bed0074ce1eeee6846e40f45d84
diff --git a/git-mv.perl b/git-mv.perl
index a21d87e..bf54c38 100755
--- a/git-mv.perl
+++ b/git-mv.perl
@@ -103,13 +103,22 @@ while(scalar @srcArgs > 0) {
 	$bad = "bad source '$src'";
     }
 
+    $safesrc = quotemeta($src);
+    @srcfiles = grep /^$safesrc(\/|$)/, @allfiles;
+
     $overwritten{$dst} = 0;
     if (($bad eq "") && -e $dst) {
 	$bad = "destination '$dst' already exists";
-	if (-f $dst && $opt_f) {
-	    print "Warning: $bad; will overwrite!\n";
-	    $bad = "";
-	    $overwritten{$dst} = 1;
+	if ($opt_f) {
+	    # only files can overwrite each other: check both source and destination
+	    if (-f $dst && (scalar @srcfiles == 1)) {
+		print "Warning: $bad; will overwrite!\n";
+		$bad = "";
+		$overwritten{$dst} = 1;
+	    }
+	    else {
+		$bad = "Can not overwrite '$src' with '$dst'";
+	    }
 	}
     }
     
@@ -118,8 +127,6 @@ while(scalar @srcArgs > 0) {
     }
 
     if ($bad eq "") {
-	$safesrc = quotemeta($src);
-	@srcfiles = grep /^$safesrc(\/|$)/, @allfiles;
         if (scalar @srcfiles == 0) {
 	    $bad = "'$src' not under version control";
 	}
@@ -166,10 +173,12 @@ while(scalar @srcs > 0) {
 
     push @deletedfiles, @srcfiles;
     if (scalar @srcfiles == 1) {
+	# $dst can be a directory with 1 file inside
 	if ($overwritten{$dst} ==1) {
-	    push @changedfiles, $dst;
+	    push @changedfiles, $dstfiles[0];
+
 	} else {
-	    push @addedfiles, $dst;
+	    push @addedfiles, $dstfiles[0];
 	}
     }
     else {
---
0.99.9.GIT

                 reply	other threads:[~2005-11-23 11:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200511231204.24571.Josef.Weidendorfer@gmx.de \
    --to=josef.weidendorfer@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=lan@ac-sw.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox