Skip to content

Commit c170072

Browse files
committed
Merge branch 'ct/mv-unmerged-path-error' into next
"git mv src dst", when src is an unmerged path, errored out correctly but with an incorrect error message to claim that src is not tracked, which has been clarified. * ct/mv-unmerged-path-error: git-mv: improve error message for conflicted file
2 parents fd7bb5c + 9b906af commit c170072

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

builtin/mv.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
132132
struct stat st;
133133
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
134134
struct lock_file lock_file = LOCK_INIT;
135+
struct cache_entry *ce;
135136

136137
git_config(git_default_config, NULL);
137138

@@ -220,9 +221,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
220221
}
221222
argc += last - first;
222223
}
223-
} else if (cache_name_pos(src, length) < 0)
224+
} else if (!(ce = cache_file_exists(src, length, ignore_case))) {
224225
bad = _("not under version control");
225-
else if (lstat(dst, &st) == 0 &&
226+
} else if (ce_stage(ce)) {
227+
bad = _("conflicted");
228+
} else if (lstat(dst, &st) == 0 &&
226229
(!ignore_case || strcasecmp(src, dst))) {
227230
bad = _("destination exists");
228231
if (force) {

t/t7001-mv.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' '
248248

249249
rm -f dirty dirty2
250250

251+
# NB: This test is about the error message
252+
# as well as the failure.
253+
test_expect_success 'git mv error on conflicted file' '
254+
rm -fr .git &&
255+
git init &&
256+
>conflict &&
257+
test_when_finished "rm -f conflict" &&
258+
cfhash=$(git hash-object -w conflict) &&
259+
q_to_tab <<-EOF | git update-index --index-info &&
260+
0 $cfhash 0Qconflict
261+
100644 $cfhash 1Qconflict
262+
EOF
263+
264+
test_must_fail git mv conflict newname 2>actual &&
265+
test_i18ngrep "conflicted" actual
266+
'
267+
251268
test_expect_success 'git mv should overwrite symlink to a file' '
252269
253270
rm -fr .git &&

0 commit comments

Comments
 (0)