Skip to content

Commit 151a973

Browse files
committed
Merge pull request #118 from aciidb0mb3r/patch-1
Pass SSH_AUTH_SOCK variable for ssh authentication while cloning repo…
2 parents 4b74110 + 6a7732d commit 151a973

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Sources/Get/Git.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import struct PackageDescription.Version
1212
import func POSIX.realpath
13+
import func POSIX.getenv
1314
import enum POSIX.Error
1415
import Utility
1516

@@ -22,10 +23,18 @@ extension Git {
2223
}
2324

2425
do {
26+
//List of environment variables which might be useful while running git
27+
let environmentList = ["SSH_AUTH_SOCK", "GIT_ASKPASS", "SSH_ASKPASS", "XDG_CONFIG_HOME"
28+
, "LANG", "LANGUAGE", "EDITOR", "PAGER", "TERM"]
29+
let environment = environmentList.reduce([String:String]()) { (accum, env) in
30+
var newAccum = accum
31+
newAccum[env] = getenv(env)
32+
return newAccum
33+
}
2534
try system(Git.tool, "clone",
2635
"--recursive", // get submodules too so that developers can use these if they so choose
2736
"--depth", "10",
28-
url, dstdir, message: "Cloning \(url)")
37+
url, dstdir, environment: environment, message: "Cloning \(url)")
2938
} catch POSIX.Error.ExitStatus {
3039
throw Error.GitCloneFailure(url, dstdir)
3140
}

Sources/Utility/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 Utility.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: true, 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)