* move directories in work dir @ 2005-10-23 5:44 Rogelio M. Serrano Jr. 2005-10-23 6:24 ` Junio C Hamano 0 siblings, 1 reply; 5+ messages in thread From: Rogelio M. Serrano Jr. @ 2005-10-23 5:44 UTC (permalink / raw) To: git Hi, Sorry for asking but is there a way to tell git that i moved a directory into another? For example i have. analyse analyse/import_a analyse/import_a/Rules.mk analyse/import_a/import_a.c^[ analyse/import_b analyse/import_b/Rules.mk analyse/import_b/import_b.c i make a new dir analyse/import_tools then move import_a and import_b in there and end up with: analyse analyse/import_tools/import_a analyse/import_tools/import_a/Rules.mk analyse/import_tools/import_a/import_a.c^[ analyse/import_tools/import_b analyse/import_tools/import_b/Rules.mk analyse/import_tools/import_b/import_b.c right now i have to do git-update-index --add for everything all over again. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: move directories in work dir 2005-10-23 5:44 move directories in work dir Rogelio M. Serrano Jr. @ 2005-10-23 6:24 ` Junio C Hamano 2005-10-23 6:53 ` Rogelio M. Serrano Jr. 2005-10-31 7:25 ` [PATCH] Add support for renaming multiple items at once, and for the destination to be a directory Ryan Anderson 0 siblings, 2 replies; 5+ messages in thread From: Junio C Hamano @ 2005-10-23 6:24 UTC (permalink / raw) To: Rogelio M. Serrano Jr.; +Cc: git, ryan "Rogelio M. Serrano Jr." <rogelio@smsglobal.net> writes: > ... is there a way to tell git that i moved a directory into > another? For example i have. Before you moved them, you could have done [*1*]: $ mkdir analyze/import_tools $ git rename analyze/import_a analyze/import_tools/import_a $ git rename analyze/import_b analyze/import_tools/import_b But that may be too late now. Instead you already did: $ mkdir analyze/import_tools $ mv analyze/import_a analyze/import_b analyze/import_tools/. At this point, you can: $ git-add analyze/import_tools $ git-ls-files analyze/import_a analyze/import_b | git-update-index --remove --stdin > right now i have to do git-update-index --add for everything all over > again. "git rename" is just a short-hand of your manual "git-update-index --add --remove" (and at the same time moving files in the working tree). There isn't any extra information you are giving git by using it (IOW "git" does not record renames). BTW, do you really have a file whose name ends with an ESC character? > analyse/import_a/import_a.c^[ [Footnote] *1* It strikes me that git rename *could* be friendlier by emulating how "mv" treats the paths parameters (current implementation insists two parameters $src and $dst). What do you think, Ryan? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: move directories in work dir 2005-10-23 6:24 ` Junio C Hamano @ 2005-10-23 6:53 ` Rogelio M. Serrano Jr. 2005-10-31 7:25 ` [PATCH] Add support for renaming multiple items at once, and for the destination to be a directory Ryan Anderson 1 sibling, 0 replies; 5+ messages in thread From: Rogelio M. Serrano Jr. @ 2005-10-23 6:53 UTC (permalink / raw) To: git On 2005-10-23 14:24:34 +0800 Junio C Hamano <junkio@cox.net> wrote: > "Rogelio M. Serrano Jr." <rogelio@smsglobal.net> writes: > >> ... is there a way to tell git that i moved a directory into >> another? For example i have. > > Before you moved them, you could have done [*1*]: > > $ mkdir analyze/import_tools > $ git rename analyze/import_a analyze/import_tools/import_a > $ git rename analyze/import_b analyze/import_tools/import_b > thanks i can live with that. i have another subtree with about 20 files in it. [snipped..] > > BTW, do you really have a file whose name ends with an ESC > character? > Oh no thats the my mua's editor. its a bug. [snipped...] Thanks ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] Add support for renaming multiple items at once, and for the destination to be a directory. 2005-10-23 6:24 ` Junio C Hamano 2005-10-23 6:53 ` Rogelio M. Serrano Jr. @ 2005-10-31 7:25 ` Ryan Anderson 2005-10-31 7:53 ` Peter Eriksen 1 sibling, 1 reply; 5+ messages in thread From: Ryan Anderson @ 2005-10-31 7:25 UTC (permalink / raw) To: Junio C Hamano, git; +Cc: Ryan Anderson Signed-off-by: Ryan Anderson <ryan@michonline.com> --- > *1* It strikes me that git rename *could* be friendlier by emulating > how "mv" treats the paths parameters (current implementation insists > two parameters $src and $dst). What do you think, Ryan? How does this look? Documentation/git-rename.txt | 1 + git-rename.perl | 69 +++++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 24 deletions(-) applies-to: 0146495a383d5af298e9c9ef33e1c5d506c63afc 172761431e16af8650f973fc16fae6e74935b422 diff --git a/Documentation/git-rename.txt b/Documentation/git-rename.txt index 583cb03..17ca558 100644 --- a/Documentation/git-rename.txt +++ b/Documentation/git-rename.txt @@ -9,6 +9,7 @@ git-rename - Script used to rename a fil SYNOPSIS -------- 'git-rename' <source> <destination> +'git-rename' <source> [source ... ] <destination directory> DESCRIPTION ----------- diff --git a/git-rename.perl b/git-rename.perl index 3b1127b..51dec91 100755 --- a/git-rename.perl +++ b/git-rename.perl @@ -8,6 +8,9 @@ use warnings; use strict; +require 5.008; + +use File::Basename qw(basename); sub usage($); @@ -19,40 +22,58 @@ unless ( -d $GIT_DIR && -d $GIT_DIR . "/ usage("Git repository not found."); } -usage("") if scalar @ARGV != 2; +usage("") if scalar @ARGV < 2; -my ($src,$dst) = @ARGV; +my $dst = pop @ARGV; +my @src = @ARGV; -unless (-f $src || -l $src || -d $src) { - usage("git rename: bad source '$src'"); +foreach my $src (@src) { + unless (-f $src || -l $src || -d $src) { + usage("git rename: bad source '$src'"); + } } -if (-e $dst) { - usage("git rename: destinations '$dst' already exists"); +if (-e $dst && !-d $dst) { + usage("git rename: destination '$dst' already exists"); } -my (@allfiles,@srcfiles,@dstfiles); - -$/ = "\0"; -open(F,"-|","git-ls-files","-z") - or die "Failed to open pipe from git-ls-files: " . $!; +# Append a "/" if one doesn't exist on the end of $dst, and $dst is +# a directory. +$dst .= "/" if -d $dst && $dst !~ m#/$#; + +foreach my $src (@src) { + my (@allfiles,@srcfiles,@dstfiles); + my $actualdst = $dst; + + $/ = "\0"; + open(F,"-|","git-ls-files","-z") + or die "Failed to open pipe from git-ls-files: " . $!; + + @allfiles = map { chomp; $_; } <F>; + close(F); + + if (-d $src) { + # Remove a trailing / if any + $src =~ s#/$##; + my $tsrc = basename $src; + $actualdst = $dst . $tsrc; + } + + my $safesrc = quotemeta($src); + @srcfiles = grep /^$safesrc/, @allfiles; + @dstfiles = @srcfiles; + s#^$safesrc(/|$)#$actualdst$1# for @dstfiles; -@allfiles = map { chomp; $_; } <F>; -close(F); -my $safesrc = quotemeta($src); -@srcfiles = grep /^$safesrc/, @allfiles; -@dstfiles = @srcfiles; -s#^$safesrc(/|$)#$dst$1# for @dstfiles; + rename($src,$actualdst) + or die "rename($src,$actualdst) failed: $!"; -rename($src,$dst) - or die "rename failed: $!"; + my $rc = system("git-update-index","--add","--",@dstfiles); + die "git-update-index failed to add new name (related to $src and $dst) with code $?\n" if $rc; -my $rc = system("git-update-index","--add","--",@dstfiles); -die "git-update-index failed to add new name with code $?\n" if $rc; - -$rc = system("git-update-index","--remove","--",@srcfiles); -die "git-update-index failed to remove old name with code $?\n" if $rc; + $rc = system("git-update-index","--remove","--",@srcfiles); + die "git-update-index failed to remove old name (related to $src) with code $?\n" if $rc; +} sub usage($) { --- 0.99.9.GIT ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Add support for renaming multiple items at once, and for the destination to be a directory. 2005-10-31 7:25 ` [PATCH] Add support for renaming multiple items at once, and for the destination to be a directory Ryan Anderson @ 2005-10-31 7:53 ` Peter Eriksen 0 siblings, 0 replies; 5+ messages in thread From: Peter Eriksen @ 2005-10-31 7:53 UTC (permalink / raw) To: git On Mon, Oct 31, 2005 at 02:25:31AM -0500, Ryan Anderson wrote: > Signed-off-by: Ryan Anderson <ryan@michonline.com> > > --- > > > *1* It strikes me that git rename *could* be friendlier by emulating > > how "mv" treats the paths parameters (current implementation insists > > two parameters $src and $dst). What do you think, Ryan? > > How does this look? See commit 1114b26e8f2d06912d855c631e51a4ee8a06c4e2 which adds git-mv. "It supersedes git-rename by adding functionality to move multiple files, directories or symlinks into another directory. It also provides according documentation." Perhaps you didn't see this commit? Regards, Peter ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-10-31 8:02 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2005-10-23 5:44 move directories in work dir Rogelio M. Serrano Jr. 2005-10-23 6:24 ` Junio C Hamano 2005-10-23 6:53 ` Rogelio M. Serrano Jr. 2005-10-31 7:25 ` [PATCH] Add support for renaming multiple items at once, and for the destination to be a directory Ryan Anderson 2005-10-31 7:53 ` Peter Eriksen
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.