From 7f5ce2cb55bf18020a68f88c2861ea862feb8178 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Sun, 15 Feb 2015 11:45:48 +0000
Subject: [PATCH 40/N] fixup! Add functionality for converting UNIX paths in
 arguments and environment variables to Windows form for native Win32
 applications.

This teaches MSYS2's path conversion to leave arguments starting with a
tilde or quote alone: It is not a good idea to expand, say, ~/.gitconfig
partially: replacing it by ~C:\msys64\.gitconfig is most likely the
wrong thing to do!

This addresses the expectations of the following test cases in the test
suite of https://github.com/git/git/tree/v2.43.0:

-t0001.19 init with init.templatedir using ~ expansion
-t0003.12 core.attributesfile
-t0003.13 attribute test: read paths from stdin
-t0003.15 attribute test: --all option
-t0003.16 attribute test: --cached option
-t0003.17 root subdir attribute test
-t0003.18 negative patterns
-t0003.19 patterns starting with exclamation
-t0003.20 "**" test
-t0003.21 "**" with no slashes test
-t0003.23 using --source
-t0003.32 bare repository: check that --cached honors index
-t0003.34 binary macro expanded by -a
-t0003.35 query binary macro directly
-t0003.40 large attributes line ignored in tree
-t0003.41 large attributes line ignores trailing content in tree
-t0003.43 large attributes line ignored in index
-t0003.44 large attributes line ignores trailing content in index
-t0068.1 run based on configured value

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 winsup/cygwin/msys2_path_conv.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc
index 875be6f..35b7757 100644
--- a/winsup/cygwin/msys2_path_conv.cc
+++ b/winsup/cygwin/msys2_path_conv.cc
@@ -349,6 +349,13 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
     if (no_pathconv)
       return NONE;
 
+    /* Let's not convert ~/.file to ~C:\msys64\.file */
+    if (*it == '~') {
+skip_p2w:
+        *src = end;
+        return NONE;
+    }
+
     while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
         recurse = true;
         it = ++*src;
