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

Commit 3097b68

Browse files
committed
Merge branch 'jk/mv-submodules-fix' into maint
* jk/mv-submodules-fix: mv: prevent mismatched data when ignoring errors. builtin/mv: fix out of bounds write Conflicts: t/t7001-mv.sh
2 parents a3236f4 + fb8a4e8 commit 3097b68

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

builtin/mv.c

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

184187
dst = add_slash(dst);
@@ -192,6 +195,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
192195
prefix_path(dst, dst_len,
193196
path + length + 1);
194197
modes[argc + j] = INDEX;
198+
submodule_gitfile[argc + j] = NULL;
195199
}
196200
argc += last - first;
197201
}
@@ -227,6 +231,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
227231
memmove(destination + i,
228232
destination + i + 1,
229233
(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 *));
230239
i--;
231240
}
232241
} 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)