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 <chris.torek@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Chris Torek committed
Jul 20, 2020 at 06:17 UTC
9b906af657d4ec0bc8fc01c5cbbbddb582a8cac6
2 files changed
+22
-2
builtin/mv.c
+5
-2
@@ -132,6 +132,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
132
struct stat st;
133
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
134
struct lock_file lock_file = LOCK_INIT;
135
+ struct cache_entry *ce;
136
137
git_config(git_default_config, NULL);
138
@@ -220,9 +221,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
221
}
222
argc += last - first;
223
}
223
- } else if (cache_name_pos(src, length) < 0)
224
+ } else if (!(ce = cache_file_exists(src, length, ignore_case))) {
225
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 &&
229
(!ignore_case || strcasecmp(src, dst))) {
230
bad = _("destination exists");
231
if (force) {
t/t7001-mv.sh
+17
@@ -248,6 +248,23 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' '
248
249
rm -f dirty dirty2
250
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
+
268
test_expect_success 'git mv should overwrite symlink to a file' '
269
270
rm -fr .git &&