@matheusbsbs / matheus-bagliano / commits / 90924d55c5
Fork 0

git-mv: fix moves into a subdir from outside

git-mv needs to be run from the base directory so that the check if a file is under revision also covers files outside of a subdirectory. Previously, e.g. in the git repo, cd Documentation; git-mv ../README . produced the error Error: '../README' not under version control The test is extended for this case; it previously only tested one direction. Signed-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Josef Weidendorfer committed Mar 3, 2006 at 17:23 UTC 90924d55c5fc4205b2d41821a3288d478aa661a0
2 files changed +24 -2
git-mv.perl
+8
@@ -62,9 +62,17 @@ else {
62 $dstDir = "";
63 }
64
65 +my $subdir_prefix = `git rev-parse --show-prefix`;
66 +chomp($subdir_prefix);
67 +
68 +# run in git base directory, so that git-ls-files lists all revisioned files
69 +chdir "$GIT_DIR/..";
70 +
71 # normalize paths, needed to compare against versioned files and update-index
72 # also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
73 for (@srcArgs, @dstArgs) {
74 + # prepend git prefix as we run from base directory
75 + $_ = $subdir_prefix.$_;
76 s|^\./||;
77 s|/\./|/| while (m|/\./|);
78 s|//+|/|g;
t/t7001-mv.sh
+16 -2
@@ -11,17 +11,31 @@ test_expect_success \
11 git-commit -m add -a'
12
13 test_expect_success \
14 - 'moving the file' \
14 + 'moving the file out of subdirectory' \
15 'cd path0 && git-mv COPYING ../path1/COPYING'
16
17 # in path0 currently
18 test_expect_success \
19 'commiting the change' \
20 - 'cd .. && git-commit -m move -a'
20 + 'cd .. && git-commit -m move-out -a'
21
22 test_expect_success \
23 'checking the commit' \
24 'git-diff-tree -r -M --name-status HEAD^ HEAD | \
25 grep -E "^R100.+path0/COPYING.+path1/COPYING"'
26
27 +test_expect_success \
28 + 'moving the file back into subdirectory' \
29 + 'cd path0 && git-mv ../path1/COPYING COPYING'
30 +
31 +# in path0 currently
32 +test_expect_success \
33 + 'commiting the change' \
34 + 'cd .. && git-commit -m move-in -a'
35 +
36 +test_expect_success \
37 + 'checking the commit' \
38 + 'git-diff-tree -r -M --name-status HEAD^ HEAD | \
39 + grep -E "^R100.+path1/COPYING.+path0/COPYING"'
40 +
41 test_done