square / spacecommander

Commit fully-formatted Objective-C as a team without even trying.
Other
1.13k stars 177 forks source link

Allow formatting of just the committed lines #86

Open flybrotherlixiang opened 4 years ago

flybrotherlixiang commented 4 years ago

Is it possible for the pre-commit hook to work just upon the committed code instead of the entire file?

segiddins commented 4 years ago

Currently, this is not possible, and I don't foresee it being possible because clang-format uses the entire file as context, each line isn't formatted on its own

HIIgor commented 3 years ago

--lines option of ClangFormat can do this, you need to get the diff lines using git diff in advance .

$DIR/bin/clang-format-3.8-custom -style=file -lines=$line

HIIgor commented 3 years ago

https://clang.llvm.org/docs/ClangFormat.html