Skip to content

Commit c0dfe07

Browse files
committed
Pass SSH_AUTH_SOCK variable for ssh authentication while cloning repos - SR-561
1 parent dcdc74e commit c0dfe07

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Sources/dep/Git.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ class Git {
9191
}
9292

9393
do {
94+
var environment = [String:String]()
95+
if let sshAuthSockPath = getenv("SSH_AUTH_SOCK") { //for auto ssh authentication if possible
96+
environment["SSH_AUTH_SOCK"] = sshAuthSockPath
97+
}
9498
try system(Git.tool, "clone",
9599
"--recursive", // get submodules too so that developers can use these if they so choose
96100
"--depth", "10",
97-
url, dstdir, message: "Cloning \(url)")
101+
url, dstdir, environment: environment, message: "Cloning \(url)")
98102
} catch POSIX.Error.ExitStatus {
99103
throw Error.GitCloneFailure(url, dstdir)
100104
}

Sources/sys/Verbosity.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ import func libc.fflush
8787
import var libc.stdout
8888
import enum POSIX.Error
8989

90-
public func system(arguments: String..., message: String?) throws {
90+
public func system(arguments: String..., environment: [String:String] = [:], message: String?) throws {
9191
var out = ""
9292
do {
9393
if sys.verbosity == .Concise {
9494
if let message = message {
9595
print(message)
9696
fflush(stdout) // ensure we display `message` before git asks for credentials
9797
}
98-
try POSIX.popen(arguments, redirectStandardError: true) { line in
98+
try POSIX.popen(arguments, redirectStandardError: false, environment: environment) { line in
9999
out += line
100100
}
101101
} else {
102-
try system(arguments)
102+
try system(arguments, environment: environment)
103103
}
104104
} catch POSIX.Error.ExitStatus(let foo) {
105105
if verbosity == .Concise {

0 commit comments

Comments
 (0)