mv: move submodules together with their work trees
Currently the attempt to use "git mv" on a submodule errors out with: fatal: source directory is empty, source=<src>, destination=<dest> The reason is that mv searches for the submodule with a trailing slash in the index, which it doesn't find (because it is stored without a trailing slash). As it doesn't find any index entries inside the submodule it claims the directory would be empty even though it isn't. Fix that by searching for the name without a trailing slash and continue if it is a submodule. Then rename() will move the submodule work tree just like it moves a file. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
4838c81fab
commit
1150246828
89
builtin/mv.c
89
builtin/mv.c
@ -118,55 +118,60 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||
&& lstat(dst, &st) == 0)
|
||||
bad = _("cannot move directory over file");
|
||||
else if (src_is_dir) {
|
||||
const char *src_w_slash = add_slash(src);
|
||||
int len_w_slash = length + 1;
|
||||
int first, last;
|
||||
int first = cache_name_pos(src, length);
|
||||
if (first >= 0) {
|
||||
if (!S_ISGITLINK(active_cache[first]->ce_mode))
|
||||
die (_("Huh? Directory %s is in index and no submodule?"), src);
|
||||
} else {
|
||||
const char *src_w_slash = add_slash(src);
|
||||
int last, len_w_slash = length + 1;
|
||||
|
||||
modes[i] = WORKING_DIRECTORY;
|
||||
modes[i] = WORKING_DIRECTORY;
|
||||
|
||||
first = cache_name_pos(src_w_slash, len_w_slash);
|
||||
if (first >= 0)
|
||||
die (_("Huh? %.*s is in index?"),
|
||||
len_w_slash, src_w_slash);
|
||||
first = cache_name_pos(src_w_slash, len_w_slash);
|
||||
if (first >= 0)
|
||||
die (_("Huh? %.*s is in index?"),
|
||||
len_w_slash, src_w_slash);
|
||||
|
||||
first = -1 - first;
|
||||
for (last = first; last < active_nr; last++) {
|
||||
const char *path = active_cache[last]->name;
|
||||
if (strncmp(path, src_w_slash, len_w_slash))
|
||||
break;
|
||||
}
|
||||
free((char *)src_w_slash);
|
||||
|
||||
if (last - first < 1)
|
||||
bad = _("source directory is empty");
|
||||
else {
|
||||
int j, dst_len;
|
||||
|
||||
if (last - first > 0) {
|
||||
source = xrealloc(source,
|
||||
(argc + last - first)
|
||||
* sizeof(char *));
|
||||
destination = xrealloc(destination,
|
||||
(argc + last - first)
|
||||
* sizeof(char *));
|
||||
modes = xrealloc(modes,
|
||||
(argc + last - first)
|
||||
* sizeof(enum update_mode));
|
||||
first = -1 - first;
|
||||
for (last = first; last < active_nr; last++) {
|
||||
const char *path = active_cache[last]->name;
|
||||
if (strncmp(path, src_w_slash, len_w_slash))
|
||||
break;
|
||||
}
|
||||
free((char *)src_w_slash);
|
||||
|
||||
dst = add_slash(dst);
|
||||
dst_len = strlen(dst);
|
||||
if (last - first < 1)
|
||||
bad = _("source directory is empty");
|
||||
else {
|
||||
int j, dst_len;
|
||||
|
||||
for (j = 0; j < last - first; j++) {
|
||||
const char *path =
|
||||
active_cache[first + j]->name;
|
||||
source[argc + j] = path;
|
||||
destination[argc + j] =
|
||||
prefix_path(dst, dst_len,
|
||||
path + length + 1);
|
||||
modes[argc + j] = INDEX;
|
||||
if (last - first > 0) {
|
||||
source = xrealloc(source,
|
||||
(argc + last - first)
|
||||
* sizeof(char *));
|
||||
destination = xrealloc(destination,
|
||||
(argc + last - first)
|
||||
* sizeof(char *));
|
||||
modes = xrealloc(modes,
|
||||
(argc + last - first)
|
||||
* sizeof(enum update_mode));
|
||||
}
|
||||
|
||||
dst = add_slash(dst);
|
||||
dst_len = strlen(dst);
|
||||
|
||||
for (j = 0; j < last - first; j++) {
|
||||
const char *path =
|
||||
active_cache[first + j]->name;
|
||||
source[argc + j] = path;
|
||||
destination[argc + j] =
|
||||
prefix_path(dst, dst_len,
|
||||
path + length + 1);
|
||||
modes[argc + j] = INDEX;
|
||||
}
|
||||
argc += last - first;
|
||||
}
|
||||
argc += last - first;
|
||||
}
|
||||
} else if (cache_name_pos(src, length) < 0)
|
||||
bad = _("not under version control");
|
||||
|
Reference in New Issue
Block a user