@@ -3369,6 +3369,15 @@ static int collect_renames(struct merge_options *opt,
collisions,
&clean);
+ if (new_path && !strcmp(new_path, p->one->path)) {
+ /* Ignore an implicit directory rename that suggests replacing a move
+ * from one->path to two->path with a move
+ * from one->path to one->path.
+ */
+ free(new_path);
+ new_path = NULL;
+ }
+
possibly_cache_new_pair(renames, p, side_index, new_path);
if (p->status != 'R' && !new_path) {
pool_diff_free_filepair(&opt->priv->pool, p);
new file mode 100755
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+test_description='Test cherry-picking a move commit.'
+
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=side2
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
+
+test_expect_success setup '
+ mkdir tools &&
+
+ echo hello >tools/hello &&
+
+ git add tools/hello &&
+ git commit -m"Add tools/hello." tools/hello &&
+
+ git branch side1 &&
+
+ # This commit is the base of the fatal cherry-pick merge.
+ echo world >world &&
+ git add world &&
+ git commit -m"Add world." &&
+
+ # Cherry picking this commit crashes git.
+ # This commit is side 2 of the fatal cherry-pick merge.
+ git mv -v world tools/world &&
+ git commit -m"mv world tools/world." &&
+
+ git checkout side1 &&
+ # This commit is side 1 of the fatal cherry-pick merge.
+ git mv -v tools/hello hello &&
+ git commit -m"mv tools/hello hello"
+'
+
+test_expect_success 'recursive cherry-pick of a move commit' '
+ test_must_fail git cherry-pick --strategy=recursive side2
+'
+
+test_expect_success 'ort cherry-pick of a move commit' '
+ rm -f world &&
+ git reset --hard &&
+ test_must_fail git cherry-pick --strategy=ort side2
+'
+
+test_done