File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -555,10 +555,25 @@ static int is_dir_empty(const wchar_t *wpath)
555
555
int mingw_rmdir (const char * pathname )
556
556
{
557
557
int tries = 0 ;
558
+ struct stat sb ;
559
+
558
560
wchar_t wpathname [MAX_LONG_PATH ];
559
561
if (xutftowcs_long_path (wpathname , pathname ) < 0 )
560
562
return -1 ;
561
563
564
+ /*
565
+ * Contrary to Linux rmdir(), Windows' _wrmdir() and _rmdir()
566
+ * will remove the directory at the path if it is a symbolic link
567
+ * which leads to issues when symlinks are used in the .git folder
568
+ * (in the context of git-repo for instance). So before calling _wrmdir()
569
+ * we first check if the path is a symbolic link. If it is, we exit
570
+ * and return the same error as Linux rmdir() in this case (ENOTDIR).
571
+ */
572
+ if (!mingw_lstat (pathname , & sb ) && S_ISLNK (sb .st_mode )) {
573
+ errno = ENOTDIR ;
574
+ return -1 ;
575
+ }
576
+
562
577
do {
563
578
if (!_wrmdir (wpathname )) {
564
579
invalidate_lstat_cache ();
Original file line number Diff line number Diff line change @@ -406,4 +406,14 @@ test_expect_success 'refuse to switch to branch checked out elsewhere' '
406
406
test_i18ngrep "already checked out" err
407
407
'
408
408
409
+ test_expect_success MINGW,SYMLINKS_WINDOWS ' rebase when .git/logs is a symlink' '
410
+ git checkout main &&
411
+ mv .git/logs actual_logs &&
412
+ cmd //c "mklink /D .git\logs ..\actual_logs" &&
413
+ git rebase -f HEAD^ &&
414
+ test -L .git/logs &&
415
+ rm .git/logs &&
416
+ mv actual_logs .git/logs
417
+ '
418
+
409
419
test_done
Original file line number Diff line number Diff line change @@ -1536,6 +1536,12 @@ test_lazy_prereq SYMLINKS '
1536
1536
ln -s x y && test -h y
1537
1537
'
1538
1538
1539
+ test_lazy_prereq SYMLINKS_WINDOWS '
1540
+ # test whether symbolic links are enabled on Windows
1541
+ test_have_prereq MINGW &&
1542
+ cmd //c "mklink y x" &> /dev/null && test -h y
1543
+ '
1544
+
1539
1545
test_lazy_prereq FILEMODE '
1540
1546
test "$(git config --bool core.filemode)" = true
1541
1547
'
You can’t perform that action at this time.
0 commit comments