-
Couldn't load subscription status.
- Fork 5
make format-xml to reformat, make hook to set up pre-commit hook #28
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/bash | ||
|
|
||
| make format-xml | ||
| git add en de | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that problematic though? IIUC this would level-out any differences incurred from the auto-formatter by updating the index already. So now I cannot discern my (presumably manual) changes from the hooked changes anymore. If you would just omit the In fact, that difference is exactly what the line below should check on – instead of distrusting any changes to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I do not see this as problematic, not being able to differentiate the staged and pre-commit changes. The convenience of just doing "git commit" again outweighs the loss of exact control IMHO. However you're right, that this would prevent comitting ANY dita files which is of course not what I intended :) I'll adapt to the |
||
| git status --porcelain|grep -qP '^M.*dita$' | ||
| if (( $? == 0 ));then | ||
| echo "XML needed reformatting, please run 'git commit' again" | ||
| exit 1 | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgive my being inquisitive, but what's
-false -ofor? IIUC,-prunealways evaluates to true, then-falsealways to false, then-ois a disjunction, then comes-name. So IINM that together means the same as-prune -name '*.dita'.For
\( -size 0 \)there's also-emptyBTW.The shell's while loop could be rewritten as
| xargs 'xmlstarlet fo {} | sponge {}'or| parallel -j 'xmlstarlet fo {} | sponge {}'BTW.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inquisitiveness is appreciated here.
-prune -false -ois one of those snippets I have in muscle memory. It doesn't do the right thing without-false -o. I agree it should but it doesn't.find(1)is weird sometimes.\( -size 0 \)==-emptythanks, I'll change it.As for
sponge/parallel: Thanks for the tip,spongesolves the redirection issue and your approach is probably more efficient, but thewhileloop is easier to debug. And as for "debugging" I just noticed I committed the version withecho. My bad, will fix.