{"thread":{"id":"2660","subject":"[PATCH] Fix cg-mv for moving directories with 1 file","startedAt":"2005-11-23T11:04:23Z","lastAt":"2005-11-23T11:04:23Z","messageCount":1,"participants":["Josef Weidendorfer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"12607","messageId":"200511231204.24571.Josef.Weidendorfer@gmx.de","threadId":"2660","inReplyTo":null,"subject":"[PATCH] Fix cg-mv for moving directories with 1 file","fromName":"Josef Weidendorfer","fromEmail":"josef.weidendorfer@gmx.de","sentAt":"2005-11-23T11:04:23Z","receivedAt":"2005-11-23T11:04:23Z","isPatch":true,"sender":{"key":"josef.weidendorfer@gmx.de","avatar":null},"body":"This is fixed by putting the file into @changedfiles/@addedfiles,\nand not the directory this file is in.\n\nAdditionally, this fixes the behavior for attempting to overwrite\na file with a directory, and gives a message for all cases where\noverwriting is not possible (file->dir,dir->file,dir->dir).\n\nThanks for Alexander Litvinov for noting this problem.\n\nSigned-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>\n\n---\n\nThis should fix the wrong behavior.\nAlexander, can you confirm this?\n\n\n git-mv.perl |   25 +++++++++++++++++--------\n 1 files changed, 17 insertions(+), 8 deletions(-)\n\napplies-to: 5bc7f67c535dbbbb9340285c82226a8dd6e4afec\n5237e9ac4adc6bed0074ce1eeee6846e40f45d84\ndiff --git a/git-mv.perl b/git-mv.perl\nindex a21d87e..bf54c38 100755\n--- a/git-mv.perl\n+++ b/git-mv.perl\n@@ -103,13 +103,22 @@ while(scalar @srcArgs > 0) {\n \t$bad = \"bad source '$src'\";\n     }\n \n+    $safesrc = quotemeta($src);\n+    @srcfiles = grep /^$safesrc(\\/|$)/, @allfiles;\n+\n     $overwritten{$dst} = 0;\n     if (($bad eq \"\") && -e $dst) {\n \t$bad = \"destination '$dst' already exists\";\n-\tif (-f $dst && $opt_f) {\n-\t    print \"Warning: $bad; will overwrite!\\n\";\n-\t    $bad = \"\";\n-\t    $overwritten{$dst} = 1;\n+\tif ($opt_f) {\n+\t    # only files can overwrite each other: check both source and destination\n+\t    if (-f $dst && (scalar @srcfiles == 1)) {\n+\t\tprint \"Warning: $bad; will overwrite!\\n\";\n+\t\t$bad = \"\";\n+\t\t$overwritten{$dst} = 1;\n+\t    }\n+\t    else {\n+\t\t$bad = \"Can not overwrite '$src' with '$dst'\";\n+\t    }\n \t}\n     }\n     \n@@ -118,8 +127,6 @@ while(scalar @srcArgs > 0) {\n     }\n \n     if ($bad eq \"\") {\n-\t$safesrc = quotemeta($src);\n-\t@srcfiles = grep /^$safesrc(\\/|$)/, @allfiles;\n         if (scalar @srcfiles == 0) {\n \t    $bad = \"'$src' not under version control\";\n \t}\n@@ -166,10 +173,12 @@ while(scalar @srcs > 0) {\n \n     push @deletedfiles, @srcfiles;\n     if (scalar @srcfiles == 1) {\n+\t# $dst can be a directory with 1 file inside\n \tif ($overwritten{$dst} ==1) {\n-\t    push @changedfiles, $dst;\n+\t    push @changedfiles, $dstfiles[0];\n+\n \t} else {\n-\t    push @addedfiles, $dst;\n+\t    push @addedfiles, $dstfiles[0];\n \t}\n     }\n     else {\n---\n0.99.9.GIT\n"}]}