Skip to content

setup: hook scripts serialized as single escaped line, losing multiline formatting #21

Description

@tupe12334

Problem

Running worktree setup (or any config operation that calls config.save()) collapses multiline hook scripts into a single escaped line.

For example, a manually written config like:

[hooks]
"post:open" = """
#!/usr/bin/env bash
echo "Worktree ready: {{owner}}/{{repo}}#{{issue}} ({{branch}})"
"""

becomes after setup saves:

[hooks]
"post:open" = "#!/usr/bin/env bash\necho \"Worktree ready: {{owner}}/{{repo}}#{{issue}} ({{branch}})\"\n"

Root Cause

src/config/ser.rstoml_quoted() escapes \n as \\n, always producing a single-line TOML basic string regardless of whether the value contains newlines. The to_toml_with_comments() method uses this for all hook values.

Expected Behavior

When a hook script value contains newlines, it should be written as a TOML multiline literal or multiline basic string so the file remains human-readable and editable, e.g.:

"post:open" = """
#!/usr/bin/env bash
echo "Worktree ready: {{owner}}/{{repo}}#{{issue}} ({{branch}})"
"""

Suggested Fix

In toml_quoted (or in the call site), detect when the value contains \n and emit a TOML multiline basic string ("""...""") instead of a single-line basic string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions