25
WORKING_DIRECTORY = (1 << 1),
26
INDEX = (1 << 2),
27
SPARSE = (1 << 3),
28
+ SKIP_WORKTREE_DIR = (1 << 4),
29
};
30
31
#define DUP_BASENAME 1
124
return last - first;
125
}
126
127
+/*
128
+ * Check if an out-of-cone directory should be in the index. Imagine this case
129
+ * that all the files under a directory are marked with 'CE_SKIP_WORKTREE' bit
130
+ * and thus the directory is sparsified.
131
+ *
132
+ * Return 0 if such directory exist (i.e. with any of its contained files not
133
+ * marked with CE_SKIP_WORKTREE, the directory would be present in working tree).
134
+ * Return 1 otherwise.
135
+ */
136
+static int check_dir_in_index(const char *name)
137
+{
138
+ const char *with_slash = add_slash(name);
139
+ int length = strlen(with_slash);
140
+
141
+ int pos = cache_name_pos(with_slash, length);
142
+ const struct cache_entry *ce;
143
+
144
+ if (pos < 0) {
145
+ pos = -pos - 1;
146
+ if (pos >= the_index.cache_nr)
147
+ return 1;
148
+ ce = active_cache[pos];
149
+ if (strncmp(with_slash, ce->name, length))
150
+ return 1;
151
+ if (ce_skip_worktree(ce))
152
+ return 0;
153
+ }
154
+ return 1;
155
+}
156
+
157
int cmd_mv(int argc, const char **argv, const char *prefix)
158
{
159
int i, flags, gitmodules_modified = 0;
215
/* Checking */
216
for (i = 0; i < argc; i++) {
217
const char *src = source[i], *dst = destination[i];
187
- int length, src_is_dir;
218
+ int length;
219
const char *bad = NULL;
220
int skip_sparse = 0;
221
229
230
pos = cache_name_pos(src, length);
231
if (pos < 0) {
232
+ const char *src_w_slash = add_slash(src);
233
+ if (!path_in_sparse_checkout(src_w_slash, &the_index) &&
234
+ !check_dir_in_index(src)) {
235
+ modes[i] |= SKIP_WORKTREE_DIR;
236
+ goto dir_check;
237
+ }
238
/* only error if existence is expected. */
239
if (!(modes[i] & SPARSE))
240
bad = _("bad source");
241
goto act_on_entry;
242
}
206
-
243
ce = active_cache[pos];
244
if (!ce_skip_worktree(ce)) {
245
bad = _("bad source");
266
bad = _("can not move directory into itself");
267
goto act_on_entry;
268
}
233
- if ((src_is_dir = S_ISDIR(st.st_mode))
269
+ if (S_ISDIR(st.st_mode)
270
&& lstat(dst, &st) == 0) {
271
bad = _("cannot move directory over file");
272
goto act_on_entry;
273
}
238
- if (src_is_dir) {
274
+
275
+dir_check:
276
+ if (S_ISDIR(st.st_mode)) {
277
int j, dst_len, n;
278
int first = cache_name_pos(src, length), last;
279
407
printf(_("Renaming %s to %s\n"), src, dst);
408
if (show_only)
409
continue;
372
- if (!(mode & (INDEX | SPARSE)) &&
410
+ if (!(mode & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) &&
411
rename(src, dst) < 0) {
412
if (ignore_errors)
413
continue;
422
1);
423
}
424
387
- if (mode & (WORKING_DIRECTORY))
425
+ if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR))
426
continue;
427
428
pos = cache_name_pos(src, strlen(src));