Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit fb8a4e8

Browse files
bk2204gitster
authored andcommitted
mv: prevent mismatched data when ignoring errors.
We shrink the source and destination arrays, but not the modes or submodule_gitfile arrays, resulting in potentially mismatched data. Shrink all the arrays at the same time to prevent this. Add tests to ensure the problem does not recur. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 89ccc1b commit fb8a4e8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

builtin/mv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
231231
memmove(destination + i,
232232
destination + i + 1,
233233
(argc - i) * sizeof(char *));
234+
memmove(modes + i, modes + i + 1,
235+
(argc - i) * sizeof(enum update_mode));
236+
memmove(submodule_gitfile + i,
237+
submodule_gitfile + i + 1,
238+
(argc - i) * sizeof(char *));
234239
i--;
235240
}
236241
} else

t/t7001-mv.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ test_expect_success 'setup submodule' '
294294
git submodule add ./. sub &&
295295
echo content >file &&
296296
git add file &&
297-
git commit -m "added sub and file"
297+
git commit -m "added sub and file" &&
298+
git branch submodule
298299
'
299300

300301
test_expect_success 'git mv cannot move a submodule in a file' '
@@ -442,4 +443,14 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
442443
git diff-files --quiet -- sub .gitmodules
443444
'
444445

446+
test_expect_success 'mv -k does not accidentally destroy submodules' '
447+
git checkout submodule &&
448+
mkdir dummy dest &&
449+
git mv -k dummy sub dest &&
450+
git status --porcelain >actual &&
451+
grep "^R sub -> dest/sub" actual &&
452+
git reset --hard &&
453+
git checkout .
454+
'
455+
445456
test_done

0 commit comments

Comments
 (0)