diff options
author | Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> | 2022-06-30 04:37:35 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-01 23:50:16 +0200 |
commit | 8a26a3915fbe1aab9786b28c535c8541f8df2a19 (patch) | |
tree | fc82c77a720b5cef9bbd6bcb28ffea472e1da9d0 /builtin/mv.c | |
parent | mv: check if out-of-cone file exists in index with SKIP_WORKTREE bit (diff) | |
download | git-8a26a3915fbe1aab9786b28c535c8541f8df2a19.tar.xz git-8a26a3915fbe1aab9786b28c535c8541f8df2a19.zip |
mv: check if <destination> exists in index to handle overwriting
Originally, moving a sparse file into cone can result in unwarned
overwrite of existing entry. The expected behavior is that if the
<destination> exists in the entry, user should be prompted to supply
a [-f|--force] to carry out the operation, or the operation should
fail.
Add a check mechanism to do that.
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>
Diffstat (limited to 'builtin/mv.c')
-rw-r--r-- | builtin/mv.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/builtin/mv.c b/builtin/mv.c index 520be85774..7d9627938a 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -202,11 +202,20 @@ int cmd_mv(int argc, const char **argv, const char *prefix) bad = _("bad source"); goto act_on_entry; } - - if (!ignore_sparse) + if (!ignore_sparse) { string_list_append(&only_match_skip_worktree, src); - else + goto act_on_entry; + } + /* Check if dst exists in index */ + if (cache_name_pos(dst, strlen(dst)) < 0) { modes[i] = SPARSE; + goto act_on_entry; + } + if (!force) { + bad = _("destination exists"); + goto act_on_entry; + } + modes[i] = SPARSE; goto act_on_entry; } if (!strncmp(src, dst, length) && |