Raw
1 /*
2 * "git mv" builtin command
3 *
4 * Copyright (C) 2006 Johannes Schindelin
5 */
6
7 #define USE_THE_REPOSITORY_VARIABLE
8 #define DISABLE_SIGN_COMPARE_WARNINGS
9
10 #include "builtin.h"
11 #include "abspath.h"
12 #include "advice.h"
13 #include "config.h"
14 #include "environment.h"
15 #include "gettext.h"
16 #include "name-hash.h"
17 #include "object-file.h"
18 #include "path.h"
19 #include "pathspec.h"
20 #include "lockfile.h"
21 #include "dir.h"
22 #include "string-list.h"
23 #include "parse-options.h"
24 #include "read-cache-ll.h"
25 #include "symlinks.h"
26
27 #include "setup.h"
28 #include "strvec.h"
29 #include "submodule.h"
30 #include "entry.h"
31
32 static const char * const builtin_mv_usage[] = {
33 N_("git mv [-v] [-f] [-n] [-k] <source> <destination>"),
34 N_("git mv [-v] [-f] [-n] [-k] <source>... <destination-directory>"),
35 NULL
36 };
37
38 enum update_mode {
39 WORKING_DIRECTORY = (1 << 1),
40 INDEX = (1 << 2),
41 SPARSE = (1 << 3),
42 SKIP_WORKTREE_DIR = (1 << 4),
43 /*
44 * A file gets moved implicitly via a move of one of its parent
45 * directories. This flag causes us to skip the check that we don't try
46 * to move a file and any of its parent directories at the same point
47 * in time.
48 */
49 MOVE_VIA_PARENT_DIR = (1 << 5),
50 };
51
52 static int needs_worktree_rename(enum update_mode mode, enum update_mode dst_mode)
53 {
54 return !(mode & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) &&
55 !(dst_mode & (SKIP_WORKTREE_DIR | SPARSE));
56 }
57
58 #define DUP_BASENAME 1
59 #define KEEP_TRAILING_SLASH 2
60
61 static void internal_prefix_pathspec(struct strvec *out,
62 const char *prefix,
63 const char **pathspec,
64 int count, unsigned flags)
65 {
66 int prefixlen = prefix ? strlen(prefix) : 0;
67
68 /* Create an intermediate copy of the pathspec based on the flags */
69 for (int i = 0; i < count; i++) {
70 size_t length = strlen(pathspec[i]);
71 size_t to_copy = length;
72 const char *maybe_basename;
73 char *trimmed, *prefixed_path;
74
75 while (!(flags & KEEP_TRAILING_SLASH) &&
76 to_copy > 0 && is_dir_sep(pathspec[i][to_copy - 1]))
77 to_copy--;
78
79 trimmed = xmemdupz(pathspec[i], to_copy);
80 maybe_basename = (flags & DUP_BASENAME) ? basename(trimmed) : trimmed;
81 prefixed_path = prefix_path(the_repository, prefix, prefixlen, maybe_basename);
82 strvec_push(out, prefixed_path);
83
84 free(prefixed_path);
85 free(trimmed);
86 }
87 }
88
89 static char *add_slash(const char *path)
90 {
91 size_t len = strlen(path);
92 if (len && path[len - 1] != '/') {
93 char *with_slash = xmalloc(st_add(len, 2));
94 memcpy(with_slash, path, len);
95 with_slash[len++] = '/';
96 with_slash[len] = 0;
97 return with_slash;
98 }
99 return xstrdup(path);
100 }
101
102 #define SUBMODULE_WITH_GITDIR ((const char *)1)
103
104 static const char *submodule_gitfile_path(const char *src, int first)
105 {
106 struct strbuf submodule_dotgit = STRBUF_INIT;
107 const char *path;
108
109 if (!S_ISGITLINK(the_repository->index->cache[first]->ce_mode))
110 die(_("Directory %s is in index and no submodule?"), src);
111 if (!is_staging_gitmodules_ok(the_repository->index))
112 die(_("Please stage your changes to .gitmodules or stash them to proceed"));
113
114 strbuf_addf(&submodule_dotgit, "%s/.git", src);
115
116 path = read_gitfile(submodule_dotgit.buf);
117 strbuf_release(&submodule_dotgit);
118 if (path)
119 return path;
120 return SUBMODULE_WITH_GITDIR;
121 }
122
123 static int index_range_of_same_dir(const char *src, int length,
124 int *first_p, int *last_p)
125 {
126 char *src_w_slash = add_slash(src);
127 int first, last, len_w_slash = length + 1;
128
129 first = index_name_pos(the_repository->index, src_w_slash, len_w_slash);
130 if (first >= 0)
131 die(_("%.*s is in index"), len_w_slash, src_w_slash);
132
133 first = -1 - first;
134 for (last = first; last < the_repository->index->cache_nr; last++) {
135 const char *path = the_repository->index->cache[last]->name;
136 if (strncmp(path, src_w_slash, len_w_slash))
137 break;
138 }
139
140 free(src_w_slash);
141 *first_p = first;
142 *last_p = last;
143 return last - first;
144 }
145
146 /*
147 * Given the path of a directory that does not exist on-disk, check whether the
148 * directory contains any entries in the index with the SKIP_WORKTREE flag
149 * enabled.
150 * Return 1 if such index entries exist.
151 * Return 0 otherwise.
152 */
153 static int empty_dir_has_sparse_contents(const char *name)
154 {
155 int ret = 0;
156 char *with_slash = add_slash(name);
157 int length = strlen(with_slash);
158
159 int pos = index_name_pos(the_repository->index, with_slash, length);
160 const struct cache_entry *ce;
161
162 if (pos < 0) {
163 pos = -pos - 1;
164 if (pos >= the_repository->index->cache_nr)
165 goto free_return;
166 ce = the_repository->index->cache[pos];
167 if (strncmp(with_slash, ce->name, length))
168 goto free_return;
169 if (ce_skip_worktree(ce))
170 ret = 1;
171 }
172
173 free_return:
174 free(with_slash);
175 return ret;
176 }
177
178 static void remove_empty_src_dirs(const char **src_dir, size_t src_dir_nr)
179 {
180 size_t i;
181 struct strbuf a_src_dir = STRBUF_INIT;
182
183 for (i = 0; i < src_dir_nr; i++) {
184 int dummy;
185 strbuf_addstr(&a_src_dir, src_dir[i]);
186 /*
187 * if entries under a_src_dir are all moved away,
188 * recursively remove a_src_dir to cleanup
189 */
190 if (index_range_of_same_dir(a_src_dir.buf, a_src_dir.len,
191 &dummy, &dummy) < 1) {
192 remove_dir_recursively(&a_src_dir, 0);
193 }
194 strbuf_reset(&a_src_dir);
195 }
196
197 strbuf_release(&a_src_dir);
198 }
199
200 struct pathmap_entry {
201 struct hashmap_entry ent;
202 const char *path;
203 };
204
205 static int pathmap_cmp(const void *cmp_data UNUSED,
206 const struct hashmap_entry *a,
207 const struct hashmap_entry *b,
208 const void *key UNUSED)
209 {
210 const struct pathmap_entry *e1 = container_of(a, struct pathmap_entry, ent);
211 const struct pathmap_entry *e2 = container_of(b, struct pathmap_entry, ent);
212 return fspathcmp(e1->path, e2->path);
213 }
214
215 int cmd_mv(int argc,
216 const char **argv,
217 const char *prefix,
218 struct repository *repo UNUSED)
219 {
220 int i, flags, gitmodules_modified = 0;
221 int verbose = 0, show_only = 0, force = 0, ignore_errors = 0, ignore_sparse = 0;
222 struct option builtin_mv_options[] = {
223 OPT__VERBOSE(&verbose, N_("be verbose")),
224 OPT__DRY_RUN(&show_only, N_("dry run")),
225 OPT__FORCE(&force, N_("force move/rename even if target exists"),
226 PARSE_OPT_NOCOMPLETE),
227 OPT_BOOL('k', NULL, &ignore_errors, N_("skip move/rename errors")),
228 OPT_BOOL(0, "sparse", &ignore_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
229 OPT_END(),
230 };
231 struct strvec sources = STRVEC_INIT;
232 struct strvec dest_paths = STRVEC_INIT;
233 struct strvec destinations = STRVEC_INIT;
234 struct strvec submodule_gitfiles_to_free = STRVEC_INIT;
235 const char **submodule_gitfiles;
236 char *dst_w_slash = NULL;
237 struct strvec src_dir = STRVEC_INIT;
238 enum update_mode *modes, dst_mode = 0;
239 struct stat st, dest_st;
240 struct string_list src_for_dst = STRING_LIST_INIT_DUP;
241 struct lock_file lock_file = LOCK_INIT;
242 struct cache_entry *ce;
243 struct string_list only_match_skip_worktree = STRING_LIST_INIT_DUP;
244 struct string_list dirty_paths = STRING_LIST_INIT_DUP;
245 struct hashmap moved_dirs = HASHMAP_INIT(pathmap_cmp, NULL);
246 struct strbuf pathbuf = STRBUF_INIT;
247 int ret;
248 struct repo_config_values *cfg = repo_config_values(the_repository);
249
250 repo_config(the_repository, git_default_config, NULL);
251
252 argc = parse_options(argc, argv, prefix, builtin_mv_options,
253 builtin_mv_usage, 0);
254 if (--argc < 1)
255 usage_with_options(builtin_mv_usage, builtin_mv_options);
256
257 repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
258 if (repo_read_index(the_repository) < 0)
259 die(_("index file corrupt"));
260
261 internal_prefix_pathspec(&sources, prefix, argv, argc, 0);
262 CALLOC_ARRAY(modes, argc);
263
264 /*
265 * Keep trailing slash, needed to let
266 * "git mv file no-such-dir/" error out, except in the case
267 * "git mv directory no-such-dir/".
268 */
269 flags = KEEP_TRAILING_SLASH;
270 if (argc == 1 && is_directory(argv[0]) && !is_directory(argv[1]))
271 flags = 0;
272 internal_prefix_pathspec(&dest_paths, prefix, argv + argc, 1, flags);
273 dst_w_slash = add_slash(dest_paths.v[0]);
274 submodule_gitfiles = xcalloc(argc, sizeof(char *));
275
276 if (dest_paths.v[0][0] == '\0')
277 /* special case: "." was normalized to "" */
278 internal_prefix_pathspec(&destinations, dest_paths.v[0], argv, argc, DUP_BASENAME);
279 else if (!lstat(dest_paths.v[0], &st) && S_ISDIR(st.st_mode)) {
280 internal_prefix_pathspec(&destinations, dst_w_slash, argv, argc, DUP_BASENAME);
281 } else if (!path_in_sparse_checkout(dst_w_slash, the_repository->index) &&
282 empty_dir_has_sparse_contents(dst_w_slash)) {
283 internal_prefix_pathspec(&destinations, dst_w_slash, argv, argc, DUP_BASENAME);
284 dst_mode = SKIP_WORKTREE_DIR;
285 } else if (argc != 1) {
286 die(_("destination '%s' is not a directory"), dest_paths.v[0]);
287 } else {
288 strvec_pushv(&destinations, dest_paths.v);
289
290 /*
291 * <destination> is a file outside of sparse-checkout
292 * cone. Insist on cone mode here for backward
293 * compatibility. We don't want dst_mode to be assigned
294 * for a file when the repo is using no-cone mode (which
295 * is deprecated at this point) sparse-checkout. As
296 * SPARSE here is only considering cone-mode situation.
297 */
298 if (!path_in_cone_mode_sparse_checkout(destinations.v[0], the_repository->index))
299 dst_mode = SPARSE;
300 }
301
302 /* Checking */
303 for (i = 0; i < argc; i++) {
304 const char *src = sources.v[i], *dst = destinations.v[i];
305 int length;
306 const char *bad = NULL;
307 int skip_sparse = 0;
308
309 if (show_only)
310 printf(_("Checking rename of '%s' to '%s'\n"), src, dst);
311
312 length = strlen(src);
313 if (lstat(src, &st) < 0) {
314 int pos;
315 const struct cache_entry *ce;
316
317 pos = index_name_pos(the_repository->index, src, length);
318 if (pos < 0) {
319 char *src_w_slash = add_slash(src);
320 if (!path_in_sparse_checkout(src_w_slash, the_repository->index) &&
321 empty_dir_has_sparse_contents(src)) {
322 free(src_w_slash);
323 modes[i] |= SKIP_WORKTREE_DIR;
324 goto dir_check;
325 }
326 free(src_w_slash);
327 /* only error if existence is expected. */
328 if (!(modes[i] & SPARSE))
329 bad = _("bad source");
330 goto act_on_entry;
331 }
332 ce = the_repository->index->cache[pos];
333 if (!ce_skip_worktree(ce)) {
334 bad = _("bad source");
335 goto act_on_entry;
336 }
337 if (!ignore_sparse) {
338 string_list_append(&only_match_skip_worktree, src);
339 goto act_on_entry;
340 }
341 /* Check if dst exists in index */
342 if (index_name_pos(the_repository->index, dst, strlen(dst)) < 0) {
343 modes[i] |= SPARSE;
344 goto act_on_entry;
345 }
346 if (!force) {
347 bad = _("destination exists");
348 goto act_on_entry;
349 }
350 modes[i] |= SPARSE;
351 goto act_on_entry;
352 }
353 if (!strncmp(src, dst, length) &&
354 (dst[length] == 0 || dst[length] == '/')) {
355 bad = _("can not move directory into itself");
356 goto act_on_entry;
357 }
358 if (S_ISDIR(st.st_mode)
359 && lstat(dst, &dest_st) == 0) {
360 bad = _("destination already exists");
361 goto act_on_entry;
362 }
363
364 dir_check:
365 if (S_ISDIR(st.st_mode)) {
366 struct pathmap_entry *entry;
367 char *dst_with_slash;
368 size_t dst_with_slash_len;
369 int j, n;
370 int first = index_name_pos(the_repository->index, src, length), last;
371
372 if (first >= 0) {
373 const char *path = submodule_gitfile_path(src, first);
374 if (path != SUBMODULE_WITH_GITDIR)
375 path = strvec_push(&submodule_gitfiles_to_free, path);
376 submodule_gitfiles[i] = path;
377 goto act_on_entry;
378 } else if (index_range_of_same_dir(src, length,
379 &first, &last) < 1) {
380 bad = _("source directory is empty");
381 goto act_on_entry;
382 }
383
384 entry = xmalloc(sizeof(*entry));
385 entry->path = src;
386 hashmap_entry_init(&entry->ent, fspathhash(src));
387 hashmap_add(&moved_dirs, &entry->ent);
388
389 /* last - first >= 1 */
390 modes[i] |= WORKING_DIRECTORY;
391
392 strvec_push(&src_dir, src);
393
394 n = argc + last - first;
395 REALLOC_ARRAY(modes, n);
396 REALLOC_ARRAY(submodule_gitfiles, n);
397
398 dst_with_slash = add_slash(dst);
399 dst_with_slash_len = strlen(dst_with_slash);
400
401 for (j = 0; j < last - first; j++) {
402 const struct cache_entry *ce = the_repository->index->cache[first + j];
403 const char *path = ce->name;
404 char *prefixed_path = prefix_path(the_repository, dst_with_slash,
405 dst_with_slash_len, path + length + 1);
406
407 strvec_push(&sources, path);
408 strvec_push(&destinations, prefixed_path);
409
410 modes[argc + j] = MOVE_VIA_PARENT_DIR | (ce_skip_worktree(ce) ? SPARSE : INDEX);
411 submodule_gitfiles[argc + j] = NULL;
412
413 free(prefixed_path);
414 }
415
416 free(dst_with_slash);
417 argc += last - first;
418 goto act_on_entry;
419 }
420 if (!(ce = index_file_exists(the_repository->index, src, length, 0))) {
421 bad = _("not under version control");
422 goto act_on_entry;
423 }
424 if (ce_stage(ce)) {
425 bad = _("conflicted");
426 goto act_on_entry;
427 }
428 if (lstat(dst, &st) == 0 &&
429 (!repo_ignore_case(the_repository) || strcasecmp(src, dst))) {
430 bad = _("destination exists");
431 if (force) {
432 /*
433 * only files can overwrite each other:
434 * check both source and destination
435 */
436 if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
437 if (verbose)
438 warning(_("overwriting '%s'"), dst);
439 bad = NULL;
440 } else
441 bad = _("Cannot overwrite");
442 }
443 goto act_on_entry;
444 }
445 if (string_list_has_string(&src_for_dst, dst)) {
446 bad = _("multiple sources for the same target");
447 goto act_on_entry;
448 }
449 if (is_dir_sep(dst[strlen(dst) - 1])) {
450 bad = _("destination directory does not exist");
451 goto act_on_entry;
452 }
453 if (has_symlink_leading_path(dst, strlen(dst))) {
454 bad = _("destination is beyond a symbolic link");
455 goto act_on_entry;
456 }
457
458 /*
459 * If we are going to move SRC to DST on disk, DST's leading
460 * directories must already exist.
461 */
462 if (needs_worktree_rename(modes[i], dst_mode)) {
463 const char *slash_ = strrchr(dst, '/');
464
465 if (slash_) {
466 struct stat dir_st;
467 char *dst_dir = xstrdup(dst);
468 char *slash = &dst_dir[slash_ - dst];
469
470 *slash = '\0';
471 if (lstat(dst_dir, &dir_st) < 0) {
472 /*
473 * other errors fall through to rename(),
474 * which reports them
475 */
476 if (errno == ENOENT || errno == ENOTDIR)
477 bad = _("destination directory does not exist");
478 } else if (!S_ISDIR(dir_st.st_mode)) {
479 bad = _("destination is not a directory");
480 }
481
482 free(dst_dir);
483 }
484
485 if (bad)
486 goto act_on_entry;
487 }
488
489 if (ignore_sparse &&
490 (dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&
491 index_entry_exists(the_repository->index, dst, strlen(dst))) {
492 bad = _("destination exists in the index");
493 if (force) {
494 if (verbose)
495 warning(_("overwriting '%s'"), dst);
496 bad = NULL;
497 } else {
498 goto act_on_entry;
499 }
500 }
501 /*
502 * We check if the paths are in the sparse-checkout
503 * definition as a very final check, since that
504 * allows us to point the user to the --sparse
505 * option as a way to have a successful run.
506 */
507 if (!ignore_sparse &&
508 !path_in_sparse_checkout(src, the_repository->index)) {
509 string_list_append(&only_match_skip_worktree, src);
510 skip_sparse = 1;
511 }
512 if (!ignore_sparse &&
513 !path_in_sparse_checkout(dst, the_repository->index)) {
514 string_list_append(&only_match_skip_worktree, dst);
515 skip_sparse = 1;
516 }
517
518 if (skip_sparse)
519 goto remove_entry;
520
521 string_list_insert(&src_for_dst, dst);
522
523 act_on_entry:
524 if (!bad)
525 continue;
526 if (!ignore_errors)
527 die(_("%s, source=%s, destination=%s"),
528 bad, src, dst);
529 remove_entry:
530 if (--argc > 0) {
531 int n = argc - i;
532 strvec_remove(&sources, i);
533 strvec_remove(&destinations, i);
534 MOVE_ARRAY(modes + i, modes + i + 1, n);
535 MOVE_ARRAY(submodule_gitfiles + i,
536 submodule_gitfiles + i + 1, n);
537 i--;
538 }
539 }
540
541 for (i = 0; i < argc; i++) {
542 const char *slash_pos;
543
544 if (modes[i] & MOVE_VIA_PARENT_DIR)
545 continue;
546
547 strbuf_reset(&pathbuf);
548 strbuf_addstr(&pathbuf, sources.v[i]);
549
550 slash_pos = strrchr(pathbuf.buf, '/');
551 while (slash_pos > pathbuf.buf) {
552 struct pathmap_entry needle;
553
554 strbuf_setlen(&pathbuf, slash_pos - pathbuf.buf);
555
556 needle.path = pathbuf.buf;
557 hashmap_entry_init(&needle.ent, fspathhash(pathbuf.buf));
558
559 if (hashmap_get_entry(&moved_dirs, &needle, ent, NULL))
560 die(_("cannot move both '%s' and its parent directory '%s'"),
561 sources.v[i], pathbuf.buf);
562
563 slash_pos = strrchr(pathbuf.buf, '/');
564 }
565 }
566
567 if (only_match_skip_worktree.nr) {
568 advise_on_updating_sparse_paths(&only_match_skip_worktree);
569 if (!ignore_errors) {
570 ret = 1;
571 goto out;
572 }
573 }
574
575 for (i = 0; i < argc; i++) {
576 const char *src = sources.v[i], *dst = destinations.v[i];
577 enum update_mode mode = modes[i];
578 int pos;
579 int sparse_and_dirty = 0;
580 struct checkout state = CHECKOUT_INIT;
581 state.istate = the_repository->index;
582
583 if (force)
584 state.force = 1;
585 if (show_only || verbose)
586 printf(_("Renaming %s to %s\n"), src, dst);
587 if (show_only)
588 continue;
589 if (needs_worktree_rename(mode, dst_mode) &&
590 rename(src, dst) < 0) {
591 if (ignore_errors)
592 continue;
593 die_errno(_("renaming '%s' to '%s' failed"), src, dst);
594 }
595 if (submodule_gitfiles[i]) {
596 if (!update_path_in_gitmodules(src, dst))
597 gitmodules_modified = 1;
598 if (submodule_gitfiles[i] != SUBMODULE_WITH_GITDIR)
599 connect_work_tree_and_git_dir(dst,
600 submodule_gitfiles[i],
601 1);
602 }
603
604 if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR))
605 continue;
606
607 pos = index_name_pos(the_repository->index, src, strlen(src));
608 if (pos < 0)
609 BUG("could not find source in index: '%s'", src);
610 if (!(mode & SPARSE) && !lstat(src, &st))
611 sparse_and_dirty = ie_modified(the_repository->index,
612 the_repository->index->cache[pos],
613 &st,
614 0);
615 rename_index_entry_at(the_repository->index, pos, dst);
616
617 if (ignore_sparse &&
618 cfg->apply_sparse_checkout &&
619 cfg->core_sparse_checkout_cone) {
620 /*
621 * NEEDSWORK: we are *not* paying attention to
622 * "out-to-out" move (<source> is out-of-cone and
623 * <destination> is out-of-cone) at this point. It
624 * should be added in a future patch.
625 */
626 if ((mode & SPARSE) &&
627 path_in_sparse_checkout(dst, the_repository->index)) {
628 /* from out-of-cone to in-cone */
629 int dst_pos = index_name_pos(the_repository->index, dst,
630 strlen(dst));
631 struct cache_entry *dst_ce = the_repository->index->cache[dst_pos];
632
633 dst_ce->ce_flags &= ~CE_SKIP_WORKTREE;
634
635 if (checkout_entry(dst_ce, &state, NULL, NULL))
636 die(_("cannot checkout %s"), dst_ce->name);
637 } else if ((dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&
638 !(mode & SPARSE) &&
639 !path_in_sparse_checkout(dst, the_repository->index)) {
640 /* from in-cone to out-of-cone */
641 int dst_pos = index_name_pos(the_repository->index, dst,
642 strlen(dst));
643 struct cache_entry *dst_ce = the_repository->index->cache[dst_pos];
644
645 /*
646 * if src is clean, it will suffice to remove it
647 */
648 if (!sparse_and_dirty) {
649 dst_ce->ce_flags |= CE_SKIP_WORKTREE;
650 unlink_or_warn(src);
651 } else {
652 /*
653 * if src is dirty, move it to the
654 * destination and create leading
655 * dirs if necessary
656 */
657 char *dst_dup = xstrdup(dst);
658 string_list_append(&dirty_paths, dst);
659 safe_create_leading_directories(the_repository, dst_dup);
660 FREE_AND_NULL(dst_dup);
661 rename(src, dst);
662 }
663 }
664 }
665 }
666
667 remove_empty_src_dirs(src_dir.v, src_dir.nr);
668
669 if (dirty_paths.nr)
670 advise_on_moving_dirty_path(&dirty_paths);
671
672 if (gitmodules_modified)
673 stage_updated_gitmodules(the_repository->index);
674
675 if (write_locked_index(the_repository->index, &lock_file,
676 COMMIT_LOCK | SKIP_IF_UNCHANGED))
677 die(_("Unable to write new index file"));
678
679 ret = 0;
680
681 out:
682 strvec_clear(&src_dir);
683 free(dst_w_slash);
684 string_list_clear(&src_for_dst, 0);
685 string_list_clear(&dirty_paths, 0);
686 string_list_clear(&only_match_skip_worktree, 0);
687 strvec_clear(&sources);
688 strvec_clear(&dest_paths);
689 strvec_clear(&destinations);
690 strvec_clear(&submodule_gitfiles_to_free);
691 hashmap_clear_and_free(&moved_dirs, struct pathmap_entry, ent);
692 strbuf_release(&pathbuf);
693 free(submodule_gitfiles);
694 free(modes);
695 return ret;
696 }