Skip to content

Commit 12de60a

Browse files
committed
Merge branch 'jk/mv-submodules-fix'
"git mv" that moves a submodule forgot to adjust the array that uses to keep track of which submodules were to be moved to update its configuration. * jk/mv-submodules-fix: mv: prevent mismatched data when ignoring errors. builtin/mv: fix out of bounds write
2 parents 2dfefe0 + fb8a4e8 commit 12de60a

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

builtin/mv.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
180180
modes = xrealloc(modes,
181181
(argc + last - first)
182182
* sizeof(enum update_mode));
183+
submodule_gitfile = xrealloc(submodule_gitfile,
184+
(argc + last - first)
185+
* sizeof(char *));
183186
}
184187

185188
dst = add_slash(dst);
@@ -193,6 +196,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
193196
prefix_path(dst, dst_len,
194197
path + length + 1);
195198
modes[argc + j] = INDEX;
199+
submodule_gitfile[argc + j] = NULL;
196200
}
197201
argc += last - first;
198202
}
@@ -228,6 +232,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
228232
memmove(destination + i,
229233
destination + i + 1,
230234
(argc - i) * sizeof(char *));
235+
memmove(modes + i, modes + i + 1,
236+
(argc - i) * sizeof(enum update_mode));
237+
memmove(submodule_gitfile + i,
238+
submodule_gitfile + i + 1,
239+
(argc - i) * sizeof(char *));
231240
i--;
232241
}
233242
} 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' '
@@ -463,4 +464,14 @@ test_expect_success 'checking out a commit before submodule moved needs manual u
463464
! test -s actual
464465
'
465466

467+
test_expect_success 'mv -k does not accidentally destroy submodules' '
468+
git checkout submodule &&
469+
mkdir dummy dest &&
470+
git mv -k dummy sub dest &&
471+
git status --porcelain >actual &&
472+
grep "^R sub -> dest/sub" actual &&
473+
git reset --hard &&
474+
git checkout .
475+
'
476+
466477
test_done

0 commit comments

Comments
 (0)