Skip to content

Commit

Permalink
Merge branch 'jk/mv-submodules-fix'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
Junio C Hamano committed Mar 25, 2014
2 parents 2dfefe0 + fb8a4e8 commit 12de60a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions builtin/mv.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
modes = xrealloc(modes,
(argc + last - first)
* sizeof(enum update_mode));
submodule_gitfile = xrealloc(submodule_gitfile,
(argc + last - first)
* sizeof(char *));
}

dst = add_slash(dst);
Expand All @@ -193,6 +196,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
prefix_path(dst, dst_len,
path + length + 1);
modes[argc + j] = INDEX;
submodule_gitfile[argc + j] = NULL;
}
argc += last - first;
}
Expand Down Expand Up @@ -228,6 +232,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
Expand Down
13 changes: 12 additions & 1 deletion t/t7001-mv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand Down Expand Up @@ -463,4 +464,14 @@ test_expect_success 'checking out a commit before submodule moved needs manual u
! 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

0 comments on commit 12de60a

Please sign in to comment.