Skip to content

Pass SSH_AUTH_SOCK variable for ssh authentication while cloning repo… #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Sources/Get/Git.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import struct PackageDescription.Version
import func POSIX.realpath
import func POSIX.getenv
import enum POSIX.Error
import Utility

Expand All @@ -22,10 +23,18 @@ extension Git {
}

do {
//List of environment variables which might be useful while running git
let environmentList = ["SSH_AUTH_SOCK", "GIT_ASKPASS", "SSH_ASKPASS", "XDG_CONFIG_HOME"
, "LANG", "LANGUAGE", "EDITOR", "PAGER", "TERM"]
let environment = environmentList.reduce([String:String]()) { (accum, env) in
var newAccum = accum
newAccum[env] = getenv(env)
return newAccum
}
try system(Git.tool, "clone",
"--recursive", // get submodules too so that developers can use these if they so choose
"--depth", "10",
url, dstdir, message: "Cloning \(url)")
url, dstdir, environment: environment, message: "Cloning \(url)")
} catch POSIX.Error.ExitStatus {
throw Error.GitCloneFailure(url, dstdir)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Utility/Verbosity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ import func libc.fflush
import var libc.stdout
import enum POSIX.Error

public func system(arguments: String..., message: String?) throws {
public func system(arguments: String..., environment: [String:String] = [:], message: String?) throws {
var out = ""
do {
if Utility.verbosity == .Concise {
if let message = message {
print(message)
fflush(stdout) // ensure we display `message` before git asks for credentials
}
try POSIX.popen(arguments, redirectStandardError: true) { line in
try POSIX.popen(arguments, redirectStandardError: true, environment: environment) { line in
out += line
}
} else {
try system(arguments)
try system(arguments, environment: environment)
}
} catch POSIX.Error.ExitStatus(let foo) {
if verbosity == .Concise {
Expand Down