From: Junio C Hamano Date: Fri, 29 Apr 2016 19:59:07 +0000 (-0700) Subject: Merge branch 'sb/mv-submodule-fix' X-Git-Tag: v2.9.0-rc0~91 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9cb50a3ca60a5c5969deb83d11782da26c3bcdb7?hp=-c Merge branch 'sb/mv-submodule-fix' "git mv old new" did not adjust the path for a submodule that lives as a subdirectory inside old/ directory correctly. * sb/mv-submodule-fix: mv: allow moving nested submodules --- 9cb50a3ca60a5c5969deb83d11782da26c3bcdb7 diff --combined builtin/mv.c index aeae855e2b,c789501706..a2014266b6 --- a/builtin/mv.c +++ b/builtin/mv.c @@@ -24,8 -24,7 +24,8 @@@ static const char **internal_copy_paths int count, unsigned flags) { int i; - const char **result = xmalloc((count + 1) * sizeof(const char *)); + const char **result; + ALLOC_ARRAY(result, count + 1); memcpy(result, pathspec, count * sizeof(const char *)); result[count] = NULL; for (i = 0; i < count; i++) { @@@ -48,9 -47,9 +48,9 @@@ static const char *add_slash(const char *path) { - int len = strlen(path); + size_t len = strlen(path); if (path[len - 1] != '/') { - char *with_slash = xmalloc(len + 2); + char *with_slash = xmalloc(st_add(len, 2)); memcpy(with_slash, path, len); with_slash[len++] = '/'; with_slash[len] = 0; @@@ -252,15 -251,18 +252,18 @@@ int cmd_mv(int argc, const char **argv int pos; if (show_only || verbose) printf(_("Renaming %s to %s\n"), src, dst); - if (!show_only && mode != INDEX) { - if (rename(src, dst) < 0 && !ignore_errors) - die_errno(_("renaming '%s' failed"), src); - if (submodule_gitfile[i]) { - if (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR) - connect_work_tree_and_git_dir(dst, submodule_gitfile[i]); - if (!update_path_in_gitmodules(src, dst)) - gitmodules_modified = 1; - } + if (show_only) + continue; + if (mode != INDEX && rename(src, dst) < 0) { + if (ignore_errors) + continue; + die_errno(_("renaming '%s' failed"), src); + } + if (submodule_gitfile[i]) { + if (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR) + connect_work_tree_and_git_dir(dst, submodule_gitfile[i]); + if (!update_path_in_gitmodules(src, dst)) + gitmodules_modified = 1; } if (mode == WORKING_DIRECTORY) diff --combined t/t7001-mv.sh index 4008faead8,fcfc953f3d..4a2570ed95 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@@ -102,7 -102,7 +102,7 @@@ test_expect_success test_expect_success \ 'adding another file' \ - 'cp "$TEST_DIRECTORY"/../README path0/README && + 'cp "$TEST_DIRECTORY"/../README.md path0/README && git add path0/README && git commit -m add2 -a' @@@ -156,11 -156,11 +156,11 @@@ test_expect_success "Michael Cassar's t echo b > partA/outline.txt && echo c > papers/unsorted/_another && git add papers partA && - T1=`git write-tree` && + T1=$(git write-tree) && git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf && - T=`git write-tree` && + T=$(git write-tree) && git ls-tree -r $T | verbose grep partA/outline.txt ' @@@ -292,6 -292,9 +292,9 @@@ test_expect_success 'setup submodule' echo content >file && git add file && git commit -m "added sub and file" && + mkdir -p deep/directory/hierachy && + git submodule add ./. deep/directory/hierachy/sub && + git commit -m "added another submodule" && git branch submodule ' @@@ -475,4 -478,17 +478,17 @@@ test_expect_success 'mv -k does not acc git checkout . ' + test_expect_success 'moving a submodule in nested directories' ' + ( + cd deep && + git mv directory ../ && + # git status would fail if the update of linking git dir to + # work dir of the submodule failed. + git status && + git config -f ../.gitmodules submodule.deep/directory/hierachy/sub.path >../actual && + echo "directory/hierachy/sub" >../expect + ) && + test_cmp actual expect + ' + test_done