Domanda

voglio usare un gancio git per forzare messaggi di commit a rispettare un formato specifico (che dovrebbe terminare con #NUMBER). Ho provato ad installare questo gancio , anche fatto riferimento here , ma continuo a ricevere il messaggio:

$ git commit -am "Test"
.git/hooks/commit-msg: line 1: sage_file: command not found
.git/hooks/commit-msg: line 2: syntax error near unexpected token `('
.git/hooks/commit-msg: line 2: `message = File.read(message_file)'

Sto usando gli script esattamente come appaiono negli esempi, ed entrambi dare lo stesso errore. Ho provato per esempio:

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

#starts with # then number, space, and at least 5 words no more than 200
$regex = /(^#[0-9]+ \W*(\w+(\W+|$)){5,200})/

if !$regex.match(message)
puts "Your message is not formatted correctly (example: #XXX at least 5 words)"
exit 1
end

Cosa potrebbe esserci di sbagliato?

È stato utile?

Soluzione

E 'possibile che (a) si sta facendo questo su Windows, e (b) hai accidentalmente introdotto fine riga di Windows CRLF nello script. Gli script di shell non lo fanno come quelli, e possono causare il tipo di problema si osserva.

Per impostare Vim di scrivere in stile Unix fine riga LF, uso

:set ff=unix
:w
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top