]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'sb/mv-submodule-fix' into HEAD
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 May 2016 21:40:05 +0000 (14:40 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 May 2016 21:40:05 +0000 (14:40 -0700)
"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

1  2 
builtin/mv.c
t/t7001-mv.sh

diff --combined builtin/mv.c
index aeae855e2b95399db4ae6032d118848449488267,c789501706ba96303e15492b7b95facd2e59c21e..a2014266b6b33d7940627777af9ae860c7850c2d
@@@ -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 4008faead8ec4ea0d08e82d2916dbc3e17327c8a,fcfc953f3de795dc6e6d3e48a38808940aeb52b7..4a2570ed959410ca34503c6260141f10debd752b
@@@ -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