From: Junio C Hamano Date: Tue, 25 Mar 2014 18:02:01 +0000 (-0700) Subject: Merge branch 'jk/mv-submodules-fix' X-Git-Tag: v2.0.0-rc0~71 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/12de60ac7a870cf0717ebbd9a150100219559f83?ds=inline;hp=-c Merge branch 'jk/mv-submodules-fix' "git mv" that moves a submodule forgot to adjust the array that uses to keep track of which submodules were to be moved to update its configuration. * jk/mv-submodules-fix: mv: prevent mismatched data when ignoring errors. builtin/mv: fix out of bounds write --- 12de60ac7a870cf0717ebbd9a150100219559f83 diff --combined builtin/mv.c index 7e26eb5229,45e57f307b..2a7243f52e --- a/builtin/mv.c +++ b/builtin/mv.c @@@ -162,8 -162,7 +162,8 @@@ int cmd_mv(int argc, const char **argv if (strncmp(path, src_w_slash, len_w_slash)) break; } - free((char *)src_w_slash); + if (src_w_slash != src) + free((char *)src_w_slash); if (last - first < 1) bad = _("source directory is empty"); @@@ -180,6 -179,9 +180,9 @@@ modes = xrealloc(modes, (argc + last - first) * sizeof(enum update_mode)); + submodule_gitfile = xrealloc(submodule_gitfile, + (argc + last - first) + * sizeof(char *)); } dst = add_slash(dst); @@@ -193,6 -195,7 +196,7 @@@ prefix_path(dst, dst_len, path + length + 1); modes[argc + j] = INDEX; + submodule_gitfile[argc + j] = NULL; } argc += last - first; } @@@ -228,6 -231,11 +232,11 @@@ 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 --combined t/t7001-mv.sh index e3c8c2c1b8,4023b6ec48..215d43d6a6 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@@ -294,7 -294,8 +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,25 -443,14 +443,35 @@@ test_expect_success 'mv --dry-run does git diff-files --quiet -- sub .gitmodules ' +test_expect_success 'checking out a commit before submodule moved needs manual updates' ' + git mv sub sub2 && + git commit -m "moved sub to sub2" && + git checkout -q HEAD^ 2>actual && + echo "warning: unable to rmdir sub2: Directory not empty" >expected && + test_i18ncmp expected actual && + git status -s sub2 >actual && + echo "?? sub2/" >expected && + test_cmp expected actual && + ! test -f sub/.git && + test -f sub2/.git && + git submodule update && + test -f sub/.git && + rm -rf sub2 && + git diff-index --exit-code HEAD && + git update-index --refresh && + git diff-files --quiet -- sub .gitmodules && + git status -s sub2 >actual && + ! test -s actual +' + + 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