git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 00/18] Support symbolic links on Windows

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 9, 2026, 20:04 UTC
Message-ID
<pull.2018.v2.git.1767989115.gitgitgadget@gmail.com>
In-Reply-To
<pull.2018.git.1765980535.gitgitgadget@gmail.com>

This finally upstreams Git for Windows' support for Windows' branch of symbolic links, which has been maturing since 2015. It is based off of js/prep-symlink-windows.

Changes since v1:
 * Changed Karsten's email address to the current one.
 * The changes to do_lstat() are now reflected by the comment preceding that
   function.
 * The commit message mentioning some ELOOP logic when symlink support is
   disabled, which had no corresponding part in the commit's diff, was
   adjusted to no longer mention that long gone change.
 * Fixed the typo "woutl".
 * Dropped a misleading, stale comment about ENOSYS in the readlink()
   implementation (talking about a long-dropped part of the original patch).
Bill Zissimopoulos (1):
  mingw: compute the correct size for symlinks in `mingw_lstat()`
Johannes Schindelin (3):
  mingw: try to create symlinks without elevated permissions
  mingw: emulate `stat()` a little more faithfully
  mingw: special-case index entries for symlinks with buggy size
Karsten Blees (14):
  mingw: don't call `GetFileAttributes()` twice in `mingw_lstat()`
  mingw: implement `stat()` with symlink support
  mingw: drop the separate `do_lstat()` function
  mingw: let `mingw_lstat()` error early upon problems with reparse
    points
  mingw: teach dirent about symlinks
  mingw: factor out the retry logic
  mingw: change default of `core.symlinks` to false
  mingw: add symlink-specific error codes
  mingw: handle symlinks to directories in `mingw_unlink()`
  mingw: support renaming symlinks
  mingw: allow `mingw_chdir()` to change to symlink-resolved directories
  mingw: implement `readlink()`
  mingw: implement basic `symlink()` functionality (file symlinks only)
  mingw: add support for symlinks to directories
 compat/mingw-posix.h  |   6 +-
 compat/mingw.c        | 635 ++++++++++++++++++++++++++++++++----------
 compat/win32.h        |   6 +-
 compat/win32/dirent.c |   5 +-
 read-cache.c          |  11 +
 5 files changed, 507 insertions(+), 156 deletions(-)
base-commit: 1887b3dd06823575e37ad19b5827d467e126c6ed
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2018%2Fdscho%2Fsymlinks-next-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2018/dscho/symlinks-next-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2018
Range-diff vs v1:
  1:  dae450dd0e !  1:  6ec4ff7457 mingw: don't call `GetFileAttributes()` twice in `mingw_lstat()`
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: don't call `GetFileAttributes()` twice in `mingw_lstat()`
     @@ Commit message
          free, and also have a (wide char) buffer that can be modified. This
          makes it easy to avoid that extraneous Win32 API call.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
     +@@ compat/mingw.c: static int has_valid_directory_prefix(wchar_t *wfilename)
     + }
     + 
     + /* We keep the do_lstat code in a separate function to avoid recursion.
     +- * When a path ends with a slash, the stat will fail with ENOENT. In
     +- * this case, we strip the trailing slashes and stat again.
     ++ * When a path ends with a slash, the call to `GetFileAttributedExW()`
     ++ * would fail. To prevent this, we strip any trailing slashes before that
     ++ * call.
     +  *
     +  * If follow is true then act like stat() and report on the link
     +  * target. Otherwise report on the link itself.
      @@ compat/mingw.c: static int do_lstat(int follow, const char *file_name, struct stat *buf)
       {
       	WIN32_FILE_ATTRIBUTE_DATA fdata;
  2:  c36848eda7 !  2:  5d83a8ab76 mingw: implement `stat()` with symlink support
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: implement `stat()` with symlink support
     @@ Commit message
          permissions, and then calling `GetFileInformationByHandle()` on it. This
          way, all links are resolved by the Windows file system layer.
      
     -    If symlinks are disabled, use `mingw_lstat()` as before, but fail with
     -    `ELOOP` if a symlink would have to be resolved.
     -
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
  3:  aa0ca80bbb !  3:  d3953f1826 mingw: drop the separate `do_lstat()` function
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: drop the separate `do_lstat()` function
     @@ Commit message
          the extra function and the old `mingw_stat()`-specific (`follow == 1`)
          logic.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
     @@ compat/mingw.c: static int has_valid_directory_prefix(wchar_t *wfilename)
       }
       
      -/* We keep the do_lstat code in a separate function to avoid recursion.
     -- * When a path ends with a slash, the stat will fail with ENOENT. In
     -- * this case, we strip the trailing slashes and stat again.
     +- * When a path ends with a slash, the call to `GetFileAttributedExW()`
     +- * would fail. To prevent this, we strip any trailing slashes before that
     +- * call.
      - *
      - * If follow is true then act like stat() and report on the link
      - * target. Otherwise report on the link itself.
  4:  886044373b !  4:  a6355789c3 mingw: let `mingw_lstat()` error early upon problems with reparse points
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: let `mingw_lstat()` error early upon problems with reparse points
     @@ Commit message
          `--color-moved -w`. That code was _not_ moved because a subsequent
          commit will move it to an altogether different function, anyway.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
  5:  db1d156aa0 !  5:  8b7f5a8fc7 mingw: teach dirent about symlinks
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: teach dirent about symlinks
     @@ Commit message
      
          Implement `DT_LNK` detection in dirent.c's `readdir()` function.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
  6:  4c49a3d9bf =  6:  1159e86dc4 mingw: compute the correct size for symlinks in `mingw_lstat()`
  7:  ad74d540f2 !  7:  4aeccd6656 mingw: factor out the retry logic
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: factor out the retry logic
     @@ Commit message
      
          In `mingw_rmdir()`, we include special error handling in the retry loop.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
  8:  25313cea76 !  8:  86c0742748 mingw: change default of `core.symlinks` to false
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: change default of `core.symlinks` to false
     @@ Commit message
          is true for the time being (an experiment to switch to BusyBox-w32
          failed due to the experimental nature of BusyBox-w32).
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
  9:  b698f4a002 !  9:  9a0093d34b mingw: add symlink-specific error codes
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: add symlink-specific error codes
     @@ Commit message
          Let's handle a couple of symlink-related error codes that will become
          relevant with the upcoming support for symlinks on Windows.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
 10:  282aba42e8 ! 10:  5dc90f9785 mingw: handle symlinks to directories in `mingw_unlink()`
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: handle symlinks to directories in `mingw_unlink()`
      
          The `_wunlink()` and `DeleteFileW()` functions refuse to delete symlinks
     -    to directories on Windows; The error code woutl be `ERROR_ACCESS_DENIED`
     +    to directories on Windows; The error code would be `ERROR_ACCESS_DENIED`
          in that case. Take that error code as an indicator that we need to try
          `_wrmdir()` as well. In the best case, it will remove a symlink. In the
          worst case, it will fail with the same error code again.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
 11:  5cb3b10500 ! 11:  3670a0a181 mingw: support renaming symlinks
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: support renaming symlinks
     @@ Commit message
          Avoid the `_wrename()` call, and go with directly calling
          `MoveFileEx()`, with proper error handling of course.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
 12:  49920839bb ! 12:  f79cf31dab mingw: allow `mingw_chdir()` to change to symlink-resolved directories
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: allow `mingw_chdir()` to change to symlink-resolved directories
     @@ Commit message
          Windows is limited to only MAX_PATH (260) characters. Therefore using
          symlinks and long paths in combination may be problematic.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
 13:  8fef8220f4 ! 13:  1ae9c63a89 mingw: implement `readlink()`
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: implement `readlink()`
     @@ Commit message
          Implement `readlink()` by reading NTFS reparse points via the
          `read_reparse_point()` function that was introduced earlier to determine
          the length of symlink targets. Works for symlinks and directory
     -    junctions. If symlinks are disabled, fail with `ENOSYS`.
     +    junctions.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw-posix.h ##
 14:  1dd5f9d6cd ! 14:  4e0ac43ef6 mingw: implement basic `symlink()` functionality (file symlinks only)
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: implement basic `symlink()` functionality (file symlinks only)
     @@ Commit message
          This implementation fails with `ENOSYS` if symlinks are disabled or
          unsupported.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw-posix.h ##
 15:  7b6dbc73f7 ! 15:  3d479fd47e mingw: add support for symlinks to directories
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          mingw: add support for symlinks to directories
     @@ Commit message
          to directory or vice versa, or if the target directory is created in
          another process. It's the best Git can do, though.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## compat/mingw.c ##
 16:  d3b89c29b0 = 16:  fb6aa461da mingw: try to create symlinks without elevated permissions
 17:  2e73ab4221 = 17:  40c3f7f36e mingw: emulate `stat()` a little more faithfully
 18:  817f488523 = 18:  afcf2bbfcb mingw: special-case index entries for symlinks with buggy size
-- 
gitgitgadget
Previous: Karsten BleesNext: Karsten Blees via GitGitGadget
Message 33 of 51 in “Support symbolic links on Windows”
  1. 00/18 Support symbolic links on WindowsJohannes Schindelin via GitGitGadget, Dec 17, 2025
  2. 01/18 mingw: don't call `GetFileAttributes()` twice in `mingw_lstat()`Karsten Blees via GitGitGadget, Dec 17, 2025
  3. Johannes SixtDec 18, 2025
  4. 02/18 mingw: implement `stat()` with symlink supportKarsten Blees via GitGitGadget, Dec 17, 2025
  5. Johannes SixtDec 18, 2025
  6. Johannes SchindelinJan 9, 2026
  7. 03/18 mingw: drop the separate `do_lstat()` functionKarsten Blees via GitGitGadget, Dec 17, 2025
  8. Johannes SixtDec 18, 2025
  9. 04/18 mingw: let `mingw_lstat()` error early upon problems with reparse pointsKarsten Blees via GitGitGadget, Dec 17, 2025
  10. 05/18 mingw: teach dirent about symlinksKarsten Blees via GitGitGadget, Dec 17, 2025
  11. 06/18 mingw: compute the correct size for symlinks in `mingw_lstat()`Bill Zissimopoulos via GitGitGadget, Dec 17, 2025
  12. 07/18 mingw: factor out the retry logicKarsten Blees via GitGitGadget, Dec 17, 2025
  13. 08/18 mingw: change default of `core.symlinks` to falseKarsten Blees via GitGitGadget, Dec 17, 2025
  14. 09/18 mingw: add symlink-specific error codesKarsten Blees via GitGitGadget, Dec 17, 2025
  15. 10/18 mingw: handle symlinks to directories in `mingw_unlink()`Karsten Blees via GitGitGadget, Dec 17, 2025
  16. Ben KnobleDec 18, 2025
  17. Johannes SchindelinJan 9, 2026
  18. 11/18 mingw: support renaming symlinksKarsten Blees via GitGitGadget, Dec 17, 2025
  19. Johannes SixtDec 18, 2025
  20. Johannes SchindelinJan 9, 2026
  21. 12/18 mingw: allow `mingw_chdir()` to change to symlink-resolved directoriesKarsten Blees via GitGitGadget, Dec 17, 2025
  22. 13/18 mingw: implement `readlink()`Karsten Blees via GitGitGadget, Dec 17, 2025
  23. Johannes SixtDec 18, 2025
  24. Johannes SchindelinJan 9, 2026
  25. 14/18 mingw: implement basic `symlink()` functionality (file symlinks only)Karsten Blees via GitGitGadget, Dec 17, 2025
  26. 15/18 mingw: add support for symlinks to directoriesKarsten Blees via GitGitGadget, Dec 17, 2025
  27. 16/18 mingw: try to create symlinks without elevated permissionsJohannes Schindelin via GitGitGadget, Dec 17, 2025
  28. 17/18 mingw: emulate `stat()` a little more faithfullyJohannes Schindelin via GitGitGadget, Dec 17, 2025
  29. 18/18 mingw: special-case index entries for symlinks with buggy sizeJohannes Schindelin via GitGitGadget, Dec 17, 2025
  30. Junio C HamanoDec 18, 2025
  31. Johannes SixtDec 18, 2025
  32. Karsten BleesDec 18, 2025
  33. 00/18 Support symbolic links on WindowsJohannes Schindelin via GitGitGadget, Jan 9, 2026
  34. 01/18 mingw: don't call `GetFileAttributes()` twice in `mingw_lstat()`Karsten Blees via GitGitGadget, Jan 9, 2026
  35. 02/18 mingw: implement `stat()` with symlink supportKarsten Blees via GitGitGadget, Jan 9, 2026
  36. 03/18 mingw: drop the separate `do_lstat()` functionKarsten Blees via GitGitGadget, Jan 9, 2026
  37. 04/18 mingw: let `mingw_lstat()` error early upon problems with reparse pointsKarsten Blees via GitGitGadget, Jan 9, 2026
  38. 05/18 mingw: teach dirent about symlinksKarsten Blees via GitGitGadget, Jan 9, 2026
  39. 06/18 mingw: compute the correct size for symlinks in `mingw_lstat()`Bill Zissimopoulos via GitGitGadget, Jan 9, 2026
  40. 07/18 mingw: factor out the retry logicKarsten Blees via GitGitGadget, Jan 9, 2026
  41. 08/18 mingw: change default of `core.symlinks` to falseKarsten Blees via GitGitGadget, Jan 9, 2026
  42. 09/18 mingw: add symlink-specific error codesKarsten Blees via GitGitGadget, Jan 9, 2026
  43. 11/18 mingw: support renaming symlinksKarsten Blees via GitGitGadget, Jan 9, 2026
  44. 10/18 mingw: handle symlinks to directories in `mingw_unlink()`Karsten Blees via GitGitGadget, Jan 9, 2026
  45. 12/18 mingw: allow `mingw_chdir()` to change to symlink-resolved directoriesKarsten Blees via GitGitGadget, Jan 9, 2026
  46. 13/18 mingw: implement `readlink()`Karsten Blees via GitGitGadget, Jan 9, 2026
  47. 14/18 mingw: implement basic `symlink()` functionality (file symlinks only)Karsten Blees via GitGitGadget, Jan 9, 2026
  48. 15/18 mingw: add support for symlinks to directoriesKarsten Blees via GitGitGadget, Jan 9, 2026
  49. 16/18 mingw: try to create symlinks without elevated permissionsJohannes Schindelin via GitGitGadget, Jan 9, 2026
  50. 17/18 mingw: emulate `stat()` a little more faithfullyJohannes Schindelin via GitGitGadget, Jan 9, 2026
  51. 18/18 mingw: special-case index entries for symlinks with buggy sizeJohannes Schindelin via GitGitGadget, Jan 9, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.