Skip to content

Commit 496f256

Browse files
tboegigitster
authored andcommitted
cygwin: allow pushing to UNC paths
cygwin can use an UNC path like //server/share/repo $ cd //server/share/dir $ mkdir test $ cd test $ git init --bare However, when we try to push from a local Git repository to this repo, there is a problem: Git converts the leading "//" into a single "/". As cygwin handles an UNC path so well, Git can support them better: - Introduce cygwin_offset_1st_component() which keeps the leading "//", similar to what Git for Windows does. - Move CYGWIN out of the POSIX in the tests for path normalization in t0060 Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c8e978 commit 496f256

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

compat/cygwin.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "../git-compat-util.h"
2+
#include "../cache.h"
3+
4+
int cygwin_offset_1st_component(const char *path)
5+
{
6+
const char *pos = path;
7+
/* unc paths */
8+
if (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
9+
/* skip server name */
10+
pos = strchr(pos + 2, '/');
11+
if (!pos)
12+
return 0; /* Error: malformed unc path */
13+
14+
do {
15+
pos++;
16+
} while (*pos && pos[0] != '/');
17+
}
18+
return pos + is_dir_sep(*pos) - path;
19+
}

compat/cygwin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int cygwin_offset_1st_component(const char *path);
2+
#define offset_1st_component cygwin_offset_1st_component

config.mak.uname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ ifeq ($(uname_O),Cygwin)
181181
UNRELIABLE_FSTAT = UnfortunatelyYes
182182
SPARSE_FLAGS = -isystem /usr/include/w32api -Wno-one-bit-signed-bitfield
183183
OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
184+
COMPAT_OBJS += compat/cygwin.o
184185
endif
185186
ifeq ($(uname_S),FreeBSD)
186187
NEEDS_LIBICONV = YesPlease

git-compat-util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@
189189
#include <sys/sysctl.h>
190190
#endif
191191

192+
#if defined(__CYGWIN__)
193+
#include "compat/cygwin.h"
194+
#endif
192195
#if defined(__MINGW32__)
193196
/* pull in Windows compatibility stuff */
194197
#include "compat/mingw.h"

t/t0060-path-utils.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ ancestor() {
7070
case $(uname -s) in
7171
*MINGW*)
7272
;;
73+
*CYGWIN*)
74+
;;
7375
*)
7476
test_set_prereq POSIX
7577
;;

0 commit comments

Comments
 (0)