delta icon indicating copy to clipboard operation
delta copied to clipboard

Add .gitattributes rules for rust files

Open phillipwood opened this issue 2 years ago • 2 comments

Setting diff=rust will make git show the current function name in the hunk headers.

While delta currently removes git's whitespace error markup from diffs adding the whitespace rules will mean pre-commit hooks that run git diff --check will reject changes with whitespace errors. In order to get git to print the correct position of the error when there is an unwanted tab in the indent following a space we need to turn off space-before-tab otherwise the space will be considered to be an error instead of the tab.

The whitespace rule could perhaps be applied more widely but the Makefile and example gitcofig have leading tabs so I restricted them to rust files for now.

[edited to explain -space-before-tab]

phillipwood avatar Nov 27 '22 10:11 phillipwood

Thanks!

I haven't spent much time with this, but diff=rust isn't always an improvement is it? E.g. here (before on the left, after on the right): The current version helpfully indicates that the function ingest_line is a method in the StateMachine impl, whereas with diff=rust it erroneously suggests that the change is in a sibling function above. (This happened to be the first one I looked at; not sure of the frequency).

image

dandavison avatar Nov 27 '22 16:11 dandavison

Oh dear, I'd forgotten that it could do that (there was a discussion about fixing this on the git mailing list a while ago but nothing came of it). On the whole I think it is an improvement as it generally shows the function being changed rather than the enclosing struct or mod (see below, before on the left, after on the right) but if you're not keen then lets drop diff=rust and just keep the whitespace rules. The case you saw only happens if the real function name ends up in the context lines above the change. Untitled

phillipwood avatar Nov 28 '22 10:11 phillipwood

I've removed the diff attribute leaving just the whitespace attributes sorry it has taken me so long to get around to it.

phillipwood avatar Mar 17 '24 16:03 phillipwood

Thanks!

dandavison avatar Mar 17 '24 18:03 dandavison