Skip to content

Conversation

@factory-ben
Copy link
Collaborator

Problem

The co-authorship hook example in the git-workflows documentation had critical bugs that would prevent it from working:

  1. Literal newlines in JSON output - The modified_msg variable contained actual newlines, which broke the JSON structure
  2. Broken sed command - The sed replacement tried to embed multiline strings with special characters directly, causing command failure
  3. Shell expansion issues - Variable expansion with newlines corrupted the final JSON output

Solution

Fixed by using jq -n with --arg to properly handle string escaping and JSON construction:

  • Use \n\n for newlines in bash variable instead of literal newlines
  • Extract and rebuild the git command without trying to embed complex multiline strings in sed
  • Let jq handle all JSON escaping automatically

This ensures the hook will work correctly when adding co-author trailers to git commits.

The previous implementation had critical bugs:
1. Literal newlines in JSON output broke JSON structure
2. sed command failed when embedding multiline strings
3. Shell variable expansion corrupted the JSON

Fixed by using jq with --arg to properly handle string escaping and JSON construction.
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

Successfully merging this pull request may close these issues.

2 participants