Skip to content

Commit 2d1e8e8

Browse files
authored
[5.4] Enable symlink support explicitly (#3417)
* Enable symlink support explicitly (#3406) motivation: enable git symlink support for Windows changes: pass core.symlinks=true to git clone operations * Limit the change to Windows only
1 parent 7cd58d6 commit 2d1e8e8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Sources/SourceControl/GitRepository.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,18 @@ public struct GitRepositoryProvider: RepositoryProvider {
8282
// shallow clone.
8383
precondition(!localFileSystem.exists(path))
8484
// FIXME: Ideally we should pass `--progress` here and report status regularly. We currently don't have callbacks for that.
85+
//
86+
// NOTE: Explicitly set `core.symlinks=true` on `git clone` to ensure that symbolic links are correctly resolved.
87+
// FIXME: Remove the judgement before a cross-platform release
88+
#if os(Windows)
89+
try self.callGit("clone", "-c", "core.symlinks=true", "--mirror", repository.url, path.pathString,
90+
repository: repository,
91+
failureMessage: "Failed to clone repository \(repository.url)")
92+
#else
8593
try self.callGit("clone", "--mirror", repository.url, path.pathString,
8694
repository: repository,
8795
failureMessage: "Failed to clone repository \(repository.url)")
96+
#endif
8897
}
8998

9099
public func copy(from sourcePath: AbsolutePath, to destinationPath: AbsolutePath) throws {
@@ -105,9 +114,18 @@ public struct GitRepositoryProvider: RepositoryProvider {
105114
// For editable clones, i.e. the user is expected to directly work on them, first we create
106115
// a clone from our cache of repositories and then we replace the remote to the one originally
107116
// present in the bare repository.
117+
//
118+
// NOTE: Explicitly set `core.symlinks=true` on `git clone` to ensure that symbolic links are correctly resolved.
119+
// FIXME: Remove the judgement before a cross-platform release
120+
#if os(Windows)
121+
try self.callGit("clone", "-c", "core.symlinks=true", "--no-checkout", sourcePath.pathString, destinationPath.pathString,
122+
repository: repository,
123+
failureMessage: "Failed to clone repository \(repository.url)")
124+
#else
108125
try self.callGit("clone", "--no-checkout", sourcePath.pathString, destinationPath.pathString,
109126
repository: repository,
110127
failureMessage: "Failed to clone repository \(repository.url)")
128+
#endif
111129
// The default name of the remote.
112130
let origin = "origin"
113131
// In destination repo remove the remote which will be pointing to the source repo.
@@ -125,9 +143,18 @@ public struct GitRepositoryProvider: RepositoryProvider {
125143
// re-resolve such that the objects in this repository changed, we would
126144
// only ever expect to get back a revision that remains present in the
127145
// object storage.
146+
//
147+
// NOTE: Explicitly set `core.symlinks=true` on `git clone` to ensure that symbolic links are correctly resolved.
148+
// FIXME: Remove the judgement before a cross-platform release
149+
#if os(Windows)
150+
try self.callGit("clone", "-c", "core.symlinks=true", "--shared", "--no-checkout", sourcePath.pathString, destinationPath.pathString,
151+
repository: repository,
152+
failureMessage: "Failed to clone repository \(repository.url)")
153+
#else
128154
try self.callGit("clone", "--shared", "--no-checkout", sourcePath.pathString, destinationPath.pathString,
129155
repository: repository,
130156
failureMessage: "Failed to clone repository \(repository.url)")
157+
#endif
131158
}
132159
}
133160

0 commit comments

Comments
 (0)