mv: update sparsity after moving from out-of-cone to in-cone
Originally, "git mv" a sparse file from out-of-cone to in-cone does not update the moved file's sparsity (remove its SKIP_WORKTREE bit). And the corresponding cache entry is, unexpectedly, not checked out in the working tree. Update the behavior so that: 1. Moving from out-of-cone to in-cone removes the SKIP_WORKTREE bit from corresponding cache entry. 2. The moved cache entry is checked out in the working tree to reflect the updated sparsity. Helped-by: Victoria Dye <vdye@github.com> Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> Acked-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shaoxuan Yuan committed
Jun 30, 2022 at 10:37 UTC
707fa2f76ac77f441578943be56e5a4a3ee8c3c5
1 file changed
+17
builtin/mv.c
+17
@@ -13,6 +13,7 @@
13
#include "string-list.h"
14
#include "parse-options.h"
15
#include "submodule.h"
16
+#include "entry.h"
17
18
static const char * const builtin_mv_usage[] = {
19
N_("git mv [<options>] <source>... <destination>"),
@@ -304,6 +305,11 @@ remove_entry:
305
const char *src = source[i], *dst = destination[i];
306
enum update_mode mode = modes[i];
307
int pos;
308
+ struct checkout state = CHECKOUT_INIT;
309
+ state.istate = &the_index;
310
+
311
+ if (force)
312
+ state.force = 1;
313
if (show_only || verbose)
314
printf(_("Renaming %s to %s\n"), src, dst);
315
if (show_only)
@@ -328,6 +334,17 @@ remove_entry:
334
pos = cache_name_pos(src, strlen(src));
335
assert(pos >= 0);
336
rename_cache_entry_at(pos, dst);
337
+
338
+ if ((mode & SPARSE) &&
339
+ (path_in_sparse_checkout(dst, &the_index))) {
340
+ int dst_pos;
341
+
342
+ dst_pos = cache_name_pos(dst, strlen(dst));
343
+ active_cache[dst_pos]->ce_flags &= ~CE_SKIP_WORKTREE;
344
+
345
+ if (checkout_entry(active_cache[dst_pos], &state, NULL, NULL))
346
+ die(_("cannot checkout %s"), active_cache[dst_pos]->name);
347
+ }
348
}
349
350
if (gitmodules_modified)