Skip to content

Commit 707fa2f

Browse files
ffyuandagitster
authored andcommitted
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 <[email protected]> Signed-off-by: Shaoxuan Yuan <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1143cc0 commit 707fa2f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

builtin/mv.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "string-list.h"
1414
#include "parse-options.h"
1515
#include "submodule.h"
16+
#include "entry.h"
1617

1718
static const char * const builtin_mv_usage[] = {
1819
N_("git mv [<options>] <source>... <destination>"),
@@ -304,6 +305,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
304305
const char *src = source[i], *dst = destination[i];
305306
enum update_mode mode = modes[i];
306307
int pos;
308+
struct checkout state = CHECKOUT_INIT;
309+
state.istate = &the_index;
310+
311+
if (force)
312+
state.force = 1;
307313
if (show_only || verbose)
308314
printf(_("Renaming %s to %s\n"), src, dst);
309315
if (show_only)
@@ -328,6 +334,17 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
328334
pos = cache_name_pos(src, strlen(src));
329335
assert(pos >= 0);
330336
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+
}
331348
}
332349

333350
if (gitmodules_modified)

0 commit comments

Comments
 (0)