Skip to content

Commit 9b906af

Browse files
chris3torekgitster
authored andcommitted
git-mv: improve error message for conflicted file
'git mv' has always complained about renaming a conflicted file, as it cannot handle multiple index entries for one file. However, the error message it uses has been the same as the one for an untracked file: fatal: not under version control, src=... which is patently wrong. Distinguish the two cases and add a test to make sure we produce the correct message. Signed-off-by: Chris Torek <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af6b65d commit 9b906af

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)