Skip to content

Commit 4668212

Browse files
authored
Merge pull request JohnSundell#48 from finestructure/master
Suppress git password prompts by default
2 parents e1577ac + 72157e8 commit 4668212

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Sources/ShellOut.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,26 @@ public extension ShellOutCommand {
131131
}
132132

133133
/// Clone a git repository at a given URL
134-
static func gitClone(url: URL, to path: String? = nil) -> ShellOutCommand {
135-
var command = "git clone \(url.absoluteString)"
134+
static func gitClone(url: URL, to path: String? = nil, allowingPrompt: Bool = false) -> ShellOutCommand {
135+
var command = "\(git(allowingPrompt: allowingPrompt)) clone \(url.absoluteString)"
136136
path.map { command.append(argument: $0) }
137137
command.append(" --quiet")
138138

139139
return ShellOutCommand(string: command)
140140
}
141141

142142
/// Create a git commit with a given message (also adds all untracked file to the index)
143-
static func gitCommit(message: String) -> ShellOutCommand {
144-
var command = "git add . && git commit -a -m"
143+
static func gitCommit(message: String, allowingPrompt: Bool = false) -> ShellOutCommand {
144+
var command = "\(git(allowingPrompt: allowingPrompt)) add . && git commit -a -m"
145145
command.append(argument: message)
146146
command.append(" --quiet")
147147

148148
return ShellOutCommand(string: command)
149149
}
150150

151151
/// Perform a git push
152-
static func gitPush(remote: String? = nil, branch: String? = nil) -> ShellOutCommand {
153-
var command = "git push"
152+
static func gitPush(remote: String? = nil, branch: String? = nil, allowingPrompt: Bool = false) -> ShellOutCommand {
153+
var command = "\(git(allowingPrompt: allowingPrompt)) push"
154154
remote.map { command.append(argument: $0) }
155155
branch.map { command.append(argument: $0) }
156156
command.append(" --quiet")
@@ -159,8 +159,8 @@ public extension ShellOutCommand {
159159
}
160160

161161
/// Perform a git pull
162-
static func gitPull(remote: String? = nil, branch: String? = nil) -> ShellOutCommand {
163-
var command = "git pull"
162+
static func gitPull(remote: String? = nil, branch: String? = nil, allowingPrompt: Bool = false) -> ShellOutCommand {
163+
var command = "\(git(allowingPrompt: allowingPrompt)) pull"
164164
remote.map { command.append(argument: $0) }
165165
branch.map { command.append(argument: $0) }
166166
command.append(" --quiet")
@@ -169,8 +169,8 @@ public extension ShellOutCommand {
169169
}
170170

171171
/// Run a git submodule update
172-
static func gitSubmoduleUpdate(initializeIfNeeded: Bool = true, recursive: Bool = true) -> ShellOutCommand {
173-
var command = "git submodule update"
172+
static func gitSubmoduleUpdate(initializeIfNeeded: Bool = true, recursive: Bool = true, allowingPrompt: Bool = false) -> ShellOutCommand {
173+
var command = "\(git(allowingPrompt: allowingPrompt)) submodule update"
174174

175175
if initializeIfNeeded {
176176
command.append(" --init")
@@ -191,6 +191,10 @@ public extension ShellOutCommand {
191191

192192
return ShellOutCommand(string: command)
193193
}
194+
195+
private static func git(allowingPrompt: Bool) -> String {
196+
return allowingPrompt ? "git" : "env GIT_TERMINAL_PROMPT=0 git"
197+
}
194198
}
195199

196200
/// File system commands

0 commit comments

Comments
 (0)