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

Gitlog fails when the subject or body includes quotation marks #101

Open
am opened this issue Feb 13, 2015 · 6 comments
Open

Gitlog fails when the subject or body includes quotation marks #101

am opened this issue Feb 13, 2015 · 6 comments

Comments

@am
Copy link

am commented Feb 13, 2015

When running the task it fails with the following error:

Warning: Log failed to match exepected pattern:
{
  "hash": "60dc76bd83bfaf1a9380683369398863847d51e6",
  "author": {
    "name": "foo",
    "email": "[email protected]"
  },
  "date": "Tue, 10 Feb 2015 10:12:42 +0100",
  "subject": "Merge pull request #705 from io/joe/123",
  "body": "Fixes boo "word" bar"
}

Is there any way to escape the values before parsing the json?

@nburana
Copy link

nburana commented Feb 17, 2015

Having the same issue. In the meantime is there a way that client code can specify the format to remove subject and body?

@nburana
Copy link

nburana commented Feb 17, 2015

In case this helps anyone, you can set the format in the config file to exclude subject and body (assuming you dont need it) and it wont break the json parser.

module.exports = function (options) {
return {
head: {
options: {
prop: 'gitlog.head.result',
number: 1,
pretty: 'format:{%n' +
' "hash": "%H",%n' + // commit hash
' "author": {%n' +
' "name": "%an",%n' + // author
' "email": "%ae"%n' + // email
' },%n' +
' "date": "%aD"%n' + // date
'}%n' +
'--grunt-gitlog-separator--'
}
}
}
}

@am
Copy link
Author

am commented Feb 17, 2015

@nburana the problem persists if you need that field...

@nburana
Copy link

nburana commented Feb 17, 2015

Yeah totally. We just needed the hash and the date so this worked for us.

@am
Copy link
Author

am commented Feb 17, 2015

Looking into the source-code it will be difficult to fix this if we don't do a more granular parsing of the git log output.
When logging a range of commits the handleResult method will receive a string that almost have the complete format of a JSON. This is where the problem starts, since it's now too late to redefine the parsing.
Looking into a similar question in SO the solution implies that we parse each commit individually, even more, for each field we want to get there is a git log for that:

function escape_chars {
    sed -r 's/(\{\}")/\\\1/g'
}
function format {
    sha=$(git log -n1 --pretty=format:%h $1 | escape_chars)
    message=$(git log -n1 --pretty=format:%B $1 | escape_chars)
    author=$(git log -n1 --pretty=format:'%aN <%aE>' $1 | escape_chars)
    commit=$(git log -n1 --pretty=format:%cE $1 | escape_chars)
    date=$(git log -n1 --pretty=format:%cD $1 | escape_chars)
    echo "{\"sha\":\"$sha\",\"message\":\"$message\",\"author\":\"$author\",\"commit\":\"$commit\",\"date\":\"$date\"}"
}

for hash in $(git rev-list)
do
  format $hash
done

Not sure if this would be too much overhead for this task.
Any thoughts?

@dbrill
Copy link

dbrill commented Oct 21, 2019

Has anyone found a reasonable work around for this.

Would anyone benefit from me submitting a PR? If this comment gets a reasonable amount of notice I'll submit something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants