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

fix: respect existing trailers in commit messages #632

Merged
merged 1 commit into from
Jul 31, 2022

Conversation

tniessen
Copy link
Member

@tniessen tniessen commented May 14, 2022

Use git interpret-trailers (probably requires a fairly recent git version) to see if the original commit message already contains trailers and do not add an empty line before adding metadata if it does (as suggested in #602 (comment)). This should fix how git node land treats Co-authored-by lines.

No reordering happens. The generated metadata is appended to the existing trailer. My understanding is that the order of trailers is irrelevant, but if that's not true, we might want to revisit that part.

This particular part of the code base does not seem to be covered by any tests, so please review carefully.

Fixes: #602

@codecov

This comment was marked as off-topic.

const metadata = this.metadata.trim().split('\n');
const amended = original.split('\n');
if (amended[amended.length - 1] !== '') {
Copy link
Member Author

@tniessen tniessen May 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: This condition appears to have always been false because the code above calls trim() on the commit message before splitting it at \n.

} else {
cli.error('Git found no trailers in the original commit message, ' +
`but '${line}' is present and should be a trailer.`);
process.exit(1); // make it work with git rebase -x
Copy link
Member Author

@tniessen tniessen May 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: It seems reasonable to abort in this case, but if anyone thinks it could be problematic, I'd be happy to revert this particular check.

@tniessen tniessen changed the title ci: respect existing trailers in commit messages fix: respect existing trailers in commit messages May 14, 2022
@targos
Copy link
Member

targos commented May 15, 2022

I'm going to try it with some backports and V8 update

@tniessen
Copy link
Member Author

tniessen commented May 19, 2022

@targos Have you had a chance to test this yet? Looks like it'll be difficult to write tests for this part.

Actually, I am not sure what happens with Refs etc. git node land treats those specially somehow, and right now, those aren't trailers when landing a pull request. On the other hand, GitHub doesn't seem to expect them to be trailers, so maybe we should preserve that?

@targos
Copy link
Member

targos commented May 19, 2022

Have you had a chance to test this yet?

It's still on my todo list.

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried that with nodejs/node#44048 and I confirm this PR fixes the issue.

@targos targos merged commit f442797 into nodejs:main Jul 31, 2022
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.

"git node land" hides co-authored-by trailers
3 participants