Skip to content

Commit 4488089

Browse files
committed
Added the ability to control the --quiet options in the predefined git commands.
1 parent d3db50b commit 4488089

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

Sources/ShellOut.swift

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,45 +131,57 @@ public extension ShellOutCommand {
131131
}
132132

133133
/// Clone a git repository at a given URL
134-
static func gitClone(url: URL, to path: String? = nil, allowingPrompt: Bool = true) -> ShellOutCommand {
134+
static func gitClone(url: URL, to path: String? = nil, allowingPrompt: Bool = true, quiet: Bool = true) -> ShellOutCommand {
135135
var command = "\(git(allowingPrompt: allowingPrompt)) clone \(url.absoluteString)"
136136
path.map { command.append(argument: $0) }
137-
command.append(" --quiet")
137+
138+
if quiet {
139+
command.append(" --quiet")
140+
}
138141

139142
return ShellOutCommand(string: command)
140143
}
141144

142145
/// Create a git commit with a given message (also adds all untracked file to the index)
143-
static func gitCommit(message: String, allowingPrompt: Bool = true) -> ShellOutCommand {
146+
static func gitCommit(message: String, allowingPrompt: Bool = true, quiet: Bool = true) -> ShellOutCommand {
144147
var command = "\(git(allowingPrompt: allowingPrompt)) add . && git commit -a -m"
145148
command.append(argument: message)
146-
command.append(" --quiet")
149+
150+
if quiet {
151+
command.append(" --quiet")
152+
}
147153

148154
return ShellOutCommand(string: command)
149155
}
150156

151157
/// Perform a git push
152-
static func gitPush(remote: String? = nil, branch: String? = nil, allowingPrompt: Bool = true) -> ShellOutCommand {
158+
static func gitPush(remote: String? = nil, branch: String? = nil, allowingPrompt: Bool = true, quiet: Bool = true) -> ShellOutCommand {
153159
var command = "\(git(allowingPrompt: allowingPrompt)) push"
154160
remote.map { command.append(argument: $0) }
155161
branch.map { command.append(argument: $0) }
156-
command.append(" --quiet")
162+
163+
if quiet {
164+
command.append(" --quiet")
165+
}
157166

158167
return ShellOutCommand(string: command)
159168
}
160169

161170
/// Perform a git pull
162-
static func gitPull(remote: String? = nil, branch: String? = nil, allowingPrompt: Bool = true) -> ShellOutCommand {
171+
static func gitPull(remote: String? = nil, branch: String? = nil, allowingPrompt: Bool = true, quiet: Bool = true) -> ShellOutCommand {
163172
var command = "\(git(allowingPrompt: allowingPrompt)) pull"
164173
remote.map { command.append(argument: $0) }
165174
branch.map { command.append(argument: $0) }
166-
command.append(" --quiet")
175+
176+
if quiet {
177+
command.append(" --quiet")
178+
}
167179

168180
return ShellOutCommand(string: command)
169181
}
170182

171183
/// Run a git submodule update
172-
static func gitSubmoduleUpdate(initializeIfNeeded: Bool = true, recursive: Bool = true, allowingPrompt: Bool = true) -> ShellOutCommand {
184+
static func gitSubmoduleUpdate(initializeIfNeeded: Bool = true, recursive: Bool = true, allowingPrompt: Bool = true, quiet: Bool = true) -> ShellOutCommand {
173185
var command = "\(git(allowingPrompt: allowingPrompt)) submodule update"
174186

175187
if initializeIfNeeded {
@@ -180,14 +192,20 @@ public extension ShellOutCommand {
180192
command.append(" --recursive")
181193
}
182194

183-
command.append(" --quiet")
195+
if quiet {
196+
command.append(" --quiet")
197+
}
198+
184199
return ShellOutCommand(string: command)
185200
}
186201

187202
/// Checkout a given git branch
188-
static func gitCheckout(branch: String) -> ShellOutCommand {
189-
let command = "git checkout".appending(argument: branch)
190-
.appending(" --quiet")
203+
static func gitCheckout(branch: String, quiet: Bool = true) -> ShellOutCommand {
204+
var command = "git checkout".appending(argument: branch)
205+
206+
if quiet {
207+
command.append(" --quiet")
208+
}
191209

192210
return ShellOutCommand(string: command)
193211
}

0 commit comments

Comments
 (0)