9
#include "cache-tree.h"
10
#include "string-list.h"
11
#include "parse-options.h"
12
+#include "submodule.h"
13
14
static const char * const builtin_mv_usage[] = {
15
N_("git mv [options] <source>... <destination>"),
67
OPT_BOOLEAN('k', NULL, &ignore_errors, N_("skip move/rename errors")),
68
OPT_END(),
69
};
69
- const char **source, **destination, **dest_path;
70
+ const char **source, **destination, **dest_path, **submodule_gitfile;
71
enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
72
struct stat st;
73
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
86
source = internal_copy_pathspec(prefix, argv, argc, 0);
87
modes = xcalloc(argc, sizeof(enum update_mode));
88
dest_path = internal_copy_pathspec(prefix, argv + argc, 1, 0);
89
+ submodule_gitfile = xcalloc(argc, sizeof(char *));
90
91
if (dest_path[0][0] == '\0')
92
/* special case: "." was normalized to "" */
122
else if (src_is_dir) {
123
int first = cache_name_pos(src, length);
124
if (first >= 0) {
125
+ struct strbuf submodule_dotgit = STRBUF_INIT;
126
if (!S_ISGITLINK(active_cache[first]->ce_mode))
127
die (_("Huh? Directory %s is in index and no submodule?"), src);
128
+ strbuf_addf(&submodule_dotgit, "%s/.git", src);
129
+ submodule_gitfile[i] = read_gitfile(submodule_dotgit.buf);
130
+ if (submodule_gitfile[i])
131
+ submodule_gitfile[i] = xstrdup(submodule_gitfile[i]);
132
+ strbuf_release(&submodule_dotgit);
133
} else {
134
const char *src_w_slash = add_slash(src);
135
int last, len_w_slash = length + 1;
224
int pos;
225
if (show_only || verbose)
226
printf(_("Renaming %s to %s\n"), src, dst);
219
- if (!show_only && mode != INDEX &&
220
- rename(src, dst) < 0 && !ignore_errors)
221
- die_errno (_("renaming '%s' failed"), src);
227
+ if (!show_only && mode != INDEX) {
228
+ if (rename(src, dst) < 0 && !ignore_errors)
229
+ die_errno (_("renaming '%s' failed"), src);
230
+ if (submodule_gitfile[i])
231
+ connect_work_tree_and_git_dir(dst, submodule_gitfile[i]);
232
+ }
233
234
if (mode == WORKING_DIRECTORY)
235
continue;