I'm writing a post-commit hook script with nodeJS on Windows. The following code calls the last commit message:
#!/bin/env node
require('child_process').exec('git log -1 --pretty=%B', function(err, commit) {
console.log(commit); // prints message in command prompt with 2 empty lines
var messages = commit.split(' '); // the delimiter is irrelevant
console.log(messages); // prints the array and shows '\n\n' at the end of last element
console.log(messages[messages.length - 1]); // yet this prints the last element WITHOUT '\n\n'
});
Why are there 2 new lines? I read on how Unix and non-Unix systems treat CR and LF. A bit on git config core.autocrlf
too, but I don't think that's the issue.