crate-ci / git-conventional

Conventional Commit API
docs.rs/git-conventional
Apache License 2.0
28 stars 7 forks source link

Multiline commit messages are not being fully parsed #19

Closed orhun closed 2 years ago

orhun commented 2 years ago

Hey, I hope you're doing well!

This is related to git-cliff#33, I realized multiline commit messages are not parsed fully when using git-conventional:

#[test]
fn test_valid_simple_commit() {
    let commit =
        Commit::parse("feat: This is a long\ncommit that spans multiple lines").unwrap();

    assert_eq!(commit.type_(), "feat");
    assert_eq!(
        commit.description(),
        "This is a long\ncommit that spans multiple lines"
    );
}

Results in:

---- commit::test::test_valid_simple_commit stdout ----
thread 'commit::test::test_valid_simple_commit' panicked at 'assertion failed: `(left == right)`
  left: `"This is a long"`,
 right: `"This is a long\ncommit that spans multiple lines"`', src/commit.rs:370:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    commit::test::test_valid_simple_commit

As you can see, only the first line is captured as "description" instead.

Is this intentional? Can we do something about this?

epage commented 2 years ago

While the underspecified 1.0 spec doesn't explicitly say the description is a single line, it hints at it by only talking about multiple lines in other contexts.

If we look at the in-work 2.0 grammar, newlines are not allowed in the <summary> line.

In general, this is important because the summary is what is intended to be seen when git shows the first line of the commit message and shouldn't be cut off.

Though not required, it’s a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. The text up to the first blank line in a commit message is treated as the commit title, and that title is used throughout Git. For example, git-format-patch(1) turns a commit into email, and it uses the title on the Subject line and the rest of the commit in the body.

https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-commit.html#_discussion

See also https://chris.beams.io/posts/git-commit/

orhun commented 2 years ago

While the underspecified 1.0 spec doesn't explicitly say the description is a single line, it hints at it by only talking about multiple lines in other contexts.

If we look at the in-work 2.0 grammar, newlines are not allowed in the <summary> line.

In general, this is important because the summary is what is intended to be seen when git shows the first line of the commit message and shouldn't be cut off.

Though not required, it’s a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. The text up to the first blank line in a commit message is treated as the commit title, and that title is used throughout Git. For example, git-format-patch(1) turns a commit into email, and it uses the title on the Subject line and the rest of the commit in the body.

mirrors.edge.kernel.org/pub/software/scm/git/docs/git-commit.html#_discussion

See also chris.beams.io/posts/git-commit

Thank you for the explanation and references. It is apparent that conventionally newlines are not supposed to be in the commit message.