{"thread":{"id":"2198","subject":"move directories in work dir","startedAt":"2005-10-23T05:44:54Z","lastAt":"2005-10-31T07:53:39Z","messageCount":5,"participants":["Rogelio M. Serrano Jr.","Junio C Hamano","Ryan Anderson","Peter Eriksen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"10478","messageId":"6f22540448f7234336a00bce5b6547b6@Splinter","threadId":"2198","inReplyTo":null,"subject":"move directories in work dir","fromName":"Rogelio M. Serrano Jr.","fromEmail":"rogelio@smsglobal.net","sentAt":"2005-10-23T05:44:54Z","receivedAt":"2005-10-23T05:44:54Z","isPatch":false,"sender":{"key":"rogelio@smsglobal.net","avatar":null},"body":"Hi,\n\nSorry for asking but is there a way to tell git that i moved a \ndirectory into another? For example i have.\n\nanalyse\nanalyse/import_a\nanalyse/import_a/Rules.mk\nanalyse/import_a/import_a.c\u001b\nanalyse/import_b\nanalyse/import_b/Rules.mk\nanalyse/import_b/import_b.c\n\ni make a new dir\nanalyse/import_tools\n\nthen move import_a and import_b in there and end up with:\n\nanalyse\nanalyse/import_tools/import_a\nanalyse/import_tools/import_a/Rules.mk\nanalyse/import_tools/import_a/import_a.c\u001b\nanalyse/import_tools/import_b\nanalyse/import_tools/import_b/Rules.mk\nanalyse/import_tools/import_b/import_b.c\n\nright now i have to do git-update-index --add for everything all over \nagain.\n"},{"id":"10479","messageId":"7vzmp04uot.fsf@assigned-by-dhcp.cox.net","threadId":"2198","inReplyTo":"6f22540448f7234336a00bce5b6547b6@Splinter","subject":"Re: move directories in work dir","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-10-23T06:24:34Z","receivedAt":"2005-10-23T06:24:34Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Rogelio M. Serrano Jr.\" <rogelio@smsglobal.net> writes:\n\n> ... is there a way to tell git that i moved a directory into\n> another? For example i have.\n\nBefore you moved them, you could have done [*1*]:\n\n\t$ mkdir analyze/import_tools\n\t$ git rename analyze/import_a analyze/import_tools/import_a\n\t$ git rename analyze/import_b analyze/import_tools/import_b\n\nBut that may be too late now.  Instead you already did:\n\n\t$ mkdir analyze/import_tools\n        $ mv analyze/import_a analyze/import_b analyze/import_tools/.\n\nAt this point, you can:\n\n\t$ git-add analyze/import_tools\n\t$ git-ls-files analyze/import_a analyze/import_b |\n          git-update-index --remove --stdin\n\n> right now i have to do git-update-index --add for everything all over \n> again.\n\n\"git rename\" is just a short-hand of your manual\n\"git-update-index --add --remove\" (and at the same time moving\nfiles in the working tree).  There isn't any extra information\nyou are giving git by using it (IOW \"git\" does not record\nrenames).\n\nBTW, do you really have a file whose name ends with an ESC\ncharacter?\n\n> analyse/import_a/import_a.c\u001b\n\n[Footnote]\n\n*1* It strikes me that git rename *could* be friendlier by\nemulating how \"mv\" treats the paths parameters (current\nimplementation insists two parameters $src and $dst).  What do\nyou think, Ryan?\n"},{"id":"10480","messageId":"5da2f0a458f277e9f6f3155bcef48237@Splinter","threadId":"2198","inReplyTo":"7vzmp04uot.fsf@assigned-by-dhcp.cox.net","subject":"Re: move directories in work dir","fromName":"Rogelio M. Serrano Jr.","fromEmail":"rogelio@smsglobal.net","sentAt":"2005-10-23T06:53:54Z","receivedAt":"2005-10-23T06:53:54Z","isPatch":false,"sender":{"key":"rogelio@smsglobal.net","avatar":null},"body":"On 2005-10-23 14:24:34 +0800 Junio C Hamano <junkio@cox.net> wrote:\n\n> \"Rogelio M. Serrano Jr.\" <rogelio@smsglobal.net> writes:\n> \n>> ... is there a way to tell git that i moved a directory into\n>> another? For example i have.\n> \n> Before you moved them, you could have done [*1*]:\n> \n> \t$ mkdir analyze/import_tools\n> \t$ git rename analyze/import_a analyze/import_tools/import_a\n> \t$ git rename analyze/import_b analyze/import_tools/import_b\n> \n\nthanks i can live with that. i have another subtree with about 20 \nfiles in it.\n\n[snipped..]\n> \n> BTW, do you really have a file whose name ends with an ESC\n> character?\n> \n\nOh no thats the my mua's editor. its a bug.\n\n[snipped...]\n\nThanks\n"},{"id":"10846","messageId":"11307435312942-git-send-email-ryan@michonline.com","threadId":"2198","inReplyTo":"7vzmp04uot.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Add support for renaming multiple items at once, and for the destination to be a directory.","fromName":"Ryan Anderson","fromEmail":"ryan@michonline.com","sentAt":"2005-10-31T07:25:31Z","receivedAt":"2005-10-31T07:25:31Z","isPatch":true,"sender":{"key":"ryan@michonline.com","avatar":null},"body":"Signed-off-by: Ryan Anderson <ryan@michonline.com>\n\n---\n\n> *1* It strikes me that git rename *could* be friendlier by emulating\n> how \"mv\" treats the paths parameters (current implementation insists\n> two parameters $src and $dst).  What do you think, Ryan?\n\nHow does this look?\n\n Documentation/git-rename.txt |    1 +\n git-rename.perl              |   69 +++++++++++++++++++++++++++---------------\n 2 files changed, 46 insertions(+), 24 deletions(-)\n\napplies-to: 0146495a383d5af298e9c9ef33e1c5d506c63afc\n172761431e16af8650f973fc16fae6e74935b422\ndiff --git a/Documentation/git-rename.txt b/Documentation/git-rename.txt\nindex 583cb03..17ca558 100644\n--- a/Documentation/git-rename.txt\n+++ b/Documentation/git-rename.txt\n@@ -9,6 +9,7 @@ git-rename - Script used to rename a fil\n SYNOPSIS\n --------\n 'git-rename' <source> <destination>\n+'git-rename' <source> [source ... ] <destination directory>\n \n DESCRIPTION\n -----------\ndiff --git a/git-rename.perl b/git-rename.perl\nindex 3b1127b..51dec91 100755\n--- a/git-rename.perl\n+++ b/git-rename.perl\n@@ -8,6 +8,9 @@\n \n use warnings;\n use strict;\n+require 5.008;\n+\n+use File::Basename qw(basename);\n \n sub usage($);\n \n@@ -19,40 +22,58 @@ unless ( -d $GIT_DIR && -d $GIT_DIR . \"/\n \tusage(\"Git repository not found.\");\n }\n \n-usage(\"\") if scalar @ARGV != 2;\n+usage(\"\") if scalar @ARGV < 2;\n \n-my ($src,$dst) = @ARGV;\n+my $dst = pop @ARGV;\n+my @src = @ARGV;\n \n-unless (-f $src || -l $src || -d $src) {\n-\tusage(\"git rename: bad source '$src'\");\n+foreach my $src (@src) {\n+\tunless (-f $src || -l $src || -d $src) {\n+\t\tusage(\"git rename: bad source '$src'\");\n+\t}\n }\n \n-if (-e $dst) {\n-\tusage(\"git rename: destinations '$dst' already exists\");\n+if (-e $dst && !-d $dst) {\n+\tusage(\"git rename: destination '$dst' already exists\");\n }\n \n-my (@allfiles,@srcfiles,@dstfiles);\n-\n-$/ = \"\\0\";\n-open(F,\"-|\",\"git-ls-files\",\"-z\")\n-\tor die \"Failed to open pipe from git-ls-files: \" . $!;\n+# Append a \"/\" if one doesn't exist on the end of $dst, and $dst is\n+# a directory.\n+$dst .= \"/\" if -d $dst && $dst !~ m#/$#;\n+\n+foreach my $src (@src) {\n+\tmy (@allfiles,@srcfiles,@dstfiles);\n+\tmy $actualdst = $dst;\n+\n+\t$/ = \"\\0\";\n+\topen(F,\"-|\",\"git-ls-files\",\"-z\")\n+\t\tor die \"Failed to open pipe from git-ls-files: \" . $!;\n+\n+\t@allfiles = map { chomp; $_; } <F>;\n+\tclose(F);\n+\n+\tif (-d $src) {\n+\t\t# Remove a trailing / if any\n+\t\t$src =~ s#/$##;\n+\t\tmy $tsrc = basename $src;\n+\t\t$actualdst = $dst . $tsrc;\n+\t}\n+\n+\tmy $safesrc = quotemeta($src);\n+\t@srcfiles = grep /^$safesrc/, @allfiles;\n+\t@dstfiles = @srcfiles;\n+\ts#^$safesrc(/|$)#$actualdst$1# for @dstfiles;\n \n-@allfiles = map { chomp; $_; } <F>;\n-close(F);\n \n-my $safesrc = quotemeta($src);\n-@srcfiles = grep /^$safesrc/, @allfiles;\n-@dstfiles = @srcfiles;\n-s#^$safesrc(/|$)#$dst$1# for @dstfiles;\n+\trename($src,$actualdst)\n+\t\tor die \"rename($src,$actualdst) failed: $!\";\n \n-rename($src,$dst)\n-\tor die \"rename failed: $!\";\n+\tmy $rc = system(\"git-update-index\",\"--add\",\"--\",@dstfiles);\n+\tdie \"git-update-index failed to add new name (related to $src and $dst) with code $?\\n\" if $rc;\n \n-my $rc = system(\"git-update-index\",\"--add\",\"--\",@dstfiles);\n-die \"git-update-index failed to add new name with code $?\\n\" if $rc;\n-\n-$rc = system(\"git-update-index\",\"--remove\",\"--\",@srcfiles);\n-die \"git-update-index failed to remove old name with code $?\\n\" if $rc;\n+\t$rc = system(\"git-update-index\",\"--remove\",\"--\",@srcfiles);\n+\tdie \"git-update-index failed to remove old name (related to $src) with code $?\\n\" if $rc;\n+}\n \n \n sub usage($) {\n---\n0.99.9.GIT\n"},{"id":"10847","messageId":"20051031075338.GA9006@ebar091.ebar.dtu.dk","threadId":"2198","inReplyTo":"11307435312942-git-send-email-ryan@michonline.com","subject":"Re: [PATCH] Add support for renaming multiple items at once, and for the destination to be a directory.","fromName":"Peter Eriksen","fromEmail":"s022018@student.dtu.dk","sentAt":"2005-10-31T07:53:39Z","receivedAt":"2005-10-31T07:53:39Z","isPatch":true,"sender":{"key":"s022018@student.dtu.dk","avatar":null},"body":"On Mon, Oct 31, 2005 at 02:25:31AM -0500, Ryan Anderson wrote:\n> Signed-off-by: Ryan Anderson <ryan@michonline.com>\n> \n> ---\n> \n> > *1* It strikes me that git rename *could* be friendlier by emulating\n> > how \"mv\" treats the paths parameters (current implementation insists\n> > two parameters $src and $dst).  What do you think, Ryan?\n> \n> How does this look?\n\nSee commit 1114b26e8f2d06912d855c631e51a4ee8a06c4e2 which adds git-mv.\n\n\"It supersedes git-rename by adding functionality to move multiple\nfiles, directories or symlinks into another directory.  It also\nprovides according documentation.\"\n\nPerhaps you didn't see this commit?\n\nRegards,\n\nPeter \n"}]}