Skip to content

Commit bbef17d

Browse files
committed
pass relevant env vars while running git
1 parent 872d07f commit bbef17d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Sources/dep/Git.swift

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

9393
do {
94+
//List of environment variables which might be useful while running git
95+
let environmentList = ["SSH_AUTH_SOCK", "GIT_ASKPASS", "SSH_ASKPASS", "XDG_CONFIG_HOME"
96+
, "LANG", "LANGUAGE", "EDITOR", "PAGER", "TERM"]
97+
let environment = environmentList.reduce([String:String]()) { (accum, env) in
98+
var newAccum = accum
99+
newAccum[env] = getenv(env)
100+
return newAccum
101+
}
102+
94103
try system(Git.tool, "clone",
95104
"--recursive", // get submodules too so that developers can use these if they so choose
96105
"--depth", "10",
97-
url, dstdir, message: "Cloning \(url)")
106+
url, dstdir, environment: environment, message: "Cloning \(url)")
98107
} catch POSIX.Error.ExitStatus {
99108
throw Error.GitCloneFailure(url, dstdir)
100109
}

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: 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)