Skip to content
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

Show no-verify message on command fail #25

Merged
merged 1 commit into from
Aug 18, 2019
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
7 changes: 7 additions & 0 deletions Sources/Komondor/Commands/install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ let hookList = [
"sendemail-validate"
]

let skippableHooks = [
"commit-msg",
"pre-commit",
"pre-rebase",
"pre-push"
]

public func install(logger _: Logger) throws {
// Add a skip env var
let env = ProcessInfo.processInfo.environment
Expand Down
9 changes: 6 additions & 3 deletions Sources/Komondor/Commands/runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import PackageConfig
import ShellOut

// To emulate running the command as the script woudl do:
// To emulate running the command as the script would do:
//
// swift run komondor run [hook-name]
//
Expand All @@ -25,7 +25,7 @@ public func runner(logger _: Logger, args: [String]) throws {
exit(1)
}

var commands = [] as [String]
var commands: [String] = []
if let stringOption = hookOptions as? String {
commands = [stringOption]
} else if let arrayOptions = hookOptions as? [String] {
Expand All @@ -36,7 +36,7 @@ public func runner(logger _: Logger, args: [String]) throws {

do {
try commands.forEach { command in
print("> \(command)")
print("[Komondor] > \(hook) \(command)")
let gitParams = Array(args.dropFirst())
// Exporting git hook input params as shell env var GIT_PARAMS
let cmd = "export GIT_PARAMS=\(gitParams.joined(separator: " ")) ; \(command)"
Expand All @@ -49,6 +49,9 @@ public func runner(logger _: Logger, args: [String]) throws {
} catch let error as ShellOutError {
print(error.message)
print(error.output)

let noVerifyMessage = skippableHooks.contains(hook) ? "add --no-verify to skip" : "cannot be skipped due to Git specs"
print("[Komondor] > \(hook) hook failed (\(noVerifyMessage))")
exit(error.terminationStatus)
} catch {
print(error)
Expand Down