Skip to content

Commit

Permalink
Merge pull request #25 from cszatma/feature/no-verify
Browse files Browse the repository at this point in the history
Show no-verify message on command fail
  • Loading branch information
orta authored Aug 18, 2019
2 parents 6152f88 + 1c0a184 commit e0c5bca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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

0 comments on commit e0c5bca

Please sign in to comment.