summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2014-03-15 18:56:52 +0000
committerJunio C Hamano <gitster@pobox.com>2014-03-17 11:38:41 -0700
commitfb8a4e8079ab8fc37e9cde32957c35637280ab8f (patch)
tree12553ebd139bfeeffcd746676afbc594c8837b25
parent89ccc1b09cf4004e6129c66def42b47206ed6b5f (diff)
downloadgit-jk/mv-submodules-fix.tar.gz
mv: prevent mismatched data when ignoring errors.jk/mv-submodules-fix
We shrink the source and destination arrays, but not the modes or submodule_gitfile arrays, resulting in potentially mismatched data. Shrink all the arrays at the same time to prevent this. Add tests to ensure the problem does not recur. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/mv.c5
-rwxr-xr-xt/t7001-mv.sh13
2 files changed, 17 insertions, 1 deletions
diff --git a/builtin/mv.c b/builtin/mv.c
index 5258077224..45e57f307b 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -231,6 +231,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
memmove(destination + i,
destination + i + 1,
(argc - i) * sizeof(char *));
+ memmove(modes + i, modes + i + 1,
+ (argc - i) * sizeof(enum update_mode));
+ memmove(submodule_gitfile + i,
+ submodule_gitfile + i + 1,
+ (argc - i) * sizeof(char *));
i--;
}
} else
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 3bfdfed1f7..4023b6ec48 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -294,7 +294,8 @@ test_expect_success 'setup submodule' '
git submodule add ./. sub &&
echo content >file &&
git add file &&
- git commit -m "added sub and file"
+ git commit -m "added sub and file" &&
+ git branch submodule
'
test_expect_success 'git mv cannot move a submodule in a file' '
@@ -442,4 +443,14 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
git diff-files --quiet -- sub .gitmodules
'
+test_expect_success 'mv -k does not accidentally destroy submodules' '
+ git checkout submodule &&
+ mkdir dummy dest &&
+ git mv -k dummy sub dest &&
+ git status --porcelain >actual &&
+ grep "^R sub -> dest/sub" actual &&
+ git reset --hard &&
+ git checkout .
+'
+
test_done