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>
This commit is contained in:
parent
8e69b31e0d
commit
90924d55c5
@ -62,9 +62,17 @@ else {
|
|||||||
$dstDir = "";
|
$dstDir = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $subdir_prefix = `git rev-parse --show-prefix`;
|
||||||
|
chomp($subdir_prefix);
|
||||||
|
|
||||||
|
# run in git base directory, so that git-ls-files lists all revisioned files
|
||||||
|
chdir "$GIT_DIR/..";
|
||||||
|
|
||||||
# normalize paths, needed to compare against versioned files and update-index
|
# normalize paths, needed to compare against versioned files and update-index
|
||||||
# also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
|
# also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
|
||||||
for (@srcArgs, @dstArgs) {
|
for (@srcArgs, @dstArgs) {
|
||||||
|
# prepend git prefix as we run from base directory
|
||||||
|
$_ = $subdir_prefix.$_;
|
||||||
s|^\./||;
|
s|^\./||;
|
||||||
s|/\./|/| while (m|/\./|);
|
s|/\./|/| while (m|/\./|);
|
||||||
s|//+|/|g;
|
s|//+|/|g;
|
||||||
|
@ -11,17 +11,31 @@ test_expect_success \
|
|||||||
git-commit -m add -a'
|
git-commit -m add -a'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'moving the file' \
|
'moving the file out of subdirectory' \
|
||||||
'cd path0 && git-mv COPYING ../path1/COPYING'
|
'cd path0 && git-mv COPYING ../path1/COPYING'
|
||||||
|
|
||||||
# in path0 currently
|
# in path0 currently
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'commiting the change' \
|
'commiting the change' \
|
||||||
'cd .. && git-commit -m move -a'
|
'cd .. && git-commit -m move-out -a'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'checking the commit' \
|
'checking the commit' \
|
||||||
'git-diff-tree -r -M --name-status HEAD^ HEAD | \
|
'git-diff-tree -r -M --name-status HEAD^ HEAD | \
|
||||||
grep -E "^R100.+path0/COPYING.+path1/COPYING"'
|
grep -E "^R100.+path0/COPYING.+path1/COPYING"'
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'moving the file back into subdirectory' \
|
||||||
|
'cd path0 && git-mv ../path1/COPYING COPYING'
|
||||||
|
|
||||||
|
# in path0 currently
|
||||||
|
test_expect_success \
|
||||||
|
'commiting the change' \
|
||||||
|
'cd .. && git-commit -m move-in -a'
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'checking the commit' \
|
||||||
|
'git-diff-tree -r -M --name-status HEAD^ HEAD | \
|
||||||
|
grep -E "^R100.+path1/COPYING.+path0/COPYING"'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user