Skip to content

Commit 90924d5

Browse files
weidendoJunio C Hamano
authored andcommitted
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>
1 parent 8e69b31 commit 90924d5

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

git-mv.perl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,17 @@ ()
6262
$dstDir = "";
6363
}
6464

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+
6571
# normalize paths, needed to compare against versioned files and update-index
6672
# also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
6773
for (@srcArgs, @dstArgs) {
74+
# prepend git prefix as we run from base directory
75+
$_ = $subdir_prefix.$_;
6876
s|^\./||;
6977
s|/\./|/| while (m|/\./|);
7078
s|//+|/|g;

t/t7001-mv.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,31 @@ test_expect_success \
1111
git-commit -m add -a'
1212

1313
test_expect_success \
14-
'moving the file' \
14+
'moving the file out of subdirectory' \
1515
'cd path0 && git-mv COPYING ../path1/COPYING'
1616

1717
# in path0 currently
1818
test_expect_success \
1919
'commiting the change' \
20-
'cd .. && git-commit -m move -a'
20+
'cd .. && git-commit -m move-out -a'
2121

2222
test_expect_success \
2323
'checking the commit' \
2424
'git-diff-tree -r -M --name-status HEAD^ HEAD | \
2525
grep -E "^R100.+path0/COPYING.+path1/COPYING"'
2626

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+
2741
test_done

0 commit comments

Comments
 (0)