Skip to content

gitignore: ignore comments on the same line as a pattern #625

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

Closed
wants to merge 1 commit into from
Closed

gitignore: ignore comments on the same line as a pattern #625

wants to merge 1 commit into from

Conversation

cbzehner
Copy link

@cbzehner cbzehner commented Aug 1, 2019

Why make this change?

Add the ability to use # to put comments after ignore patterns. This is
useful for documenting the reason for particular ignore patterns inclusion
and structure.

Right now a common convention in .gitignore files is to group patterns
by similarity using new lines beginning with one or more # characters
as headings.

When leaving comments about a particular pattern it can be difficult to
distinguish comments about a single patterns from comments used for file
organization.

Comments left after a pattern are unambiguously related to that line, and
that line only.

What should this change do?

Any part of a string after a non-escaped #, including the #, is removed
from the pattern.

Why make the change this way?

I don't normally write C, so I probably overlooked more idiomatic ways
to do this. This is done similarly to the way trim_trailing_spaces removes
extraneous spaces from patterns.

How can we test this change works?

That's one area I'd like help with, please.

Test cases:

/pattern/to/match
# Existing comment
/pattern/with/comment # This comment is ignored
/pattern/with/\#octothorpe # \#octothorpe is ignored

I wasn't sure where the correct place to add these would be, I didn't see (and
potentially overlooked) any tests in /t/* that cover this functionality. Would
someone be willing to provide a pointer to the correct place to add these tests?

Signed-off-by: Chris Zehner cbzehner@gmail.com

@dscho
Copy link
Member

dscho commented Aug 1, 2019

Thank you for your contribution!

Please make sure that your commit message focuses on answering the question "why?" more than on "how?", and that it wraps at <= 76 columns per line.

Finally send the patch to the mailing list for review. You can use GitGitGadget, submitGit or send it manually.

@cbzehner
Copy link
Author

cbzehner commented Aug 3, 2019

Thanks for the feedback @dscho! I'll submit this next week, but if you have any further feedback in the meantime I'd appreciate it!

@@ -658,6 +658,38 @@ void clear_exclude_list(struct exclude_list *el)
memset(el, 0, sizeof(*el));
}

static void trim_trailing_comments(char *buf)
Copy link

Choose a reason for hiding this comment

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

This function is very similar to trim_trailing_spaces(). l don't think logic should be put at all costs in one single function, but it's worth thinking if they can be merged somehow.

@dscho
Copy link
Member

dscho commented Sep 25, 2019

@cbzehner gentle ping?

@cbzehner
Copy link
Author

cbzehner commented Oct 1, 2019

Thanks for the reminder @dscho. I'll get this updated and out this week.

Signed-off-by: Chris Zehner <cbzehner@gmail.com>
@cbzehner
Copy link
Author

cbzehner commented Oct 1, 2019

Updated onto the latest master branch and opened a PR on GitGitGadget gitgitgadget#370

Should I leave this PR open in the meantime or close this and continue my submission via gitgitgadget#370?

@dscho
Copy link
Member

dscho commented Oct 1, 2019

Should I leave this PR open in the meantime or close this and continue my submission via gitgitgadget#370?

My personal preference would be to close it here, as I am trying to reduce the number of PRs in https://github.com/git/git/pulls (so I regularly look through many open PRs here).

@cbzehner
Copy link
Author

cbzehner commented Oct 1, 2019

Sounds good. Thank you for your guidance!

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.

5 participants