Skip to content

Commit 8e12aaa

Browse files
committed
Merge branch 'st/mv-lstat-fix'
Correct use of lstat() that assumed a failing call would not clobber the statbuf. * st/mv-lstat-fix: mv: handle lstat() failure correctly
2 parents cecd6a5 + 72695d8 commit 8e12aaa

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

builtin/mv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
184184
int src_dir_nr = 0, src_dir_alloc = 0;
185185
struct strbuf a_src_dir = STRBUF_INIT;
186186
enum update_mode *modes, dst_mode = 0;
187-
struct stat st;
187+
struct stat st, dest_st;
188188
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
189189
struct lock_file lock_file = LOCK_INIT;
190190
struct cache_entry *ce;
@@ -304,7 +304,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
304304
goto act_on_entry;
305305
}
306306
if (S_ISDIR(st.st_mode)
307-
&& lstat(dst, &st) == 0) {
307+
&& lstat(dst, &dest_st) == 0) {
308308
bad = _("cannot move directory over file");
309309
goto act_on_entry;
310310
}

t/t7001-mv.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ test_expect_success 'do not move directory over existing directory' '
174174
test_must_fail git mv path2 path0
175175
'
176176

177+
test_expect_success 'rename directory to non-existing directory' '
178+
mkdir dir-a &&
179+
>dir-a/f &&
180+
git add dir-a &&
181+
git mv dir-a non-existing-dir
182+
'
183+
177184
test_expect_success 'move into "."' '
178185
git mv path1/path2/ .
179186
'

0 commit comments

Comments
 (0)