lucaschain
lucaschain

Reputation: 33

Simple Regex test in shell for commit message

I'm new to Shell and I need to port a simple commit-msg hook that is written in ruby, my problem is exactly on the regex test, can anyone help?

This is the code in ruby:

#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)

$regex = /\[([A-Z]+)-\d+\](.)*/

if !$regex.match(message)
  puts "[ERROR] Please use the following pattern: '[ABC-123] lorem ipsum'"
  exit 1
end

Upvotes: 0

Views: 877

Answers (1)

lucaschain
lucaschain

Reputation: 33

In sh the script will be

#!/bin/sh
if echo $1 | egrep -qv '\[([A-Z]+)-\d+\](.)*'; then
  echo "[ERROR] Please use the following pattern: '[ABC-123] lorem ipsum'"
  exit 1;
fi

Upvotes: 1

Related Questions