Git Symlinks in Windows

前端 未结 13 1453
执念已碎
执念已碎 2020-11-22 09:23

Our developers use a mix of Windows and Unix based OS\'s. Therefore, symlinks created on Unix machines become a problem for Windows developers. In windows (msysgit), the sym

13条回答
  •  时光取名叫无心
    2020-11-22 09:35

    Here is a batch script for converting symlinks in repository, for files only, based on Josh Lee's answer. Script with some additional check for administrator rights is at https://gist.github.com/Quazistax/8daf09080bf54b4c7641.

    @echo off
    pushd "%~dp0"
    setlocal EnableDelayedExpansion
    
    for /f "tokens=3,*" %%e in ('git ls-files -s ^| findstr /R /C:"^120000"') do (
         call :processFirstLine %%f
    )
    REM pause
    goto :eof
    
    :processFirstLine
    @echo.
    @echo FILE:    %1
    
    dir "%~f1" | find "" >NUL && (
      @echo FILE already is a symlink
      goto :eof
    )
    
    for /f "usebackq tokens=*" %%l in ("%~f1") do (
      @echo LINK TO: %%l
    
      del "%~f1"
      if not !ERRORLEVEL! == 0 (
        @echo FAILED: del
        goto :eof
      )
    
      setlocal
      call :expandRelative linkto "%1" "%%l"
      mklink "%~f1" "!linkto!"
      endlocal
      if not !ERRORLEVEL! == 0 (
        @echo FAILED: mklink
        @echo reverting deletion...
        git checkout -- "%~f1"
        goto :eof
      )
    
      git update-index --assume-unchanged "%1"
      if not !ERRORLEVEL! == 0 (
        @echo FAILED: git update-index --assume-unchanged
        goto :eof
      )
      @echo SUCCESS
      goto :eof
    )
    goto :eof
    
    :: param1 = result variable
    :: param2 = reference path from which relative will be resolved
    :: param3 = relative path
    :expandRelative
      pushd .
      cd "%~dp2"
      set %1=%~f3
      popd
    goto :eof
    

提交回复
热议问题