I made a script to run clang-format-diff.py
on a diff of all uncommitted changes and unpushed commits.
File called run-clang-format.sh
in base of git directory and contains:
git diff -U0 --no-color origin/master | clang-format-diff.py -p1
When I add the -i
option to clang-format-diff.py
it works fine but I want to avoid this because it introduces some wacky reordering that I want to bypass. So I currently run the above shell script like so in the base of the git directory (so I get a .diff that I can review and/or edit manually before applying):
./run-clang-format.sh > format.diff
format.diff looks like this (I've never seen this "before formatting / after formatting" format):
--- symengine/functions.cpp (before formatting)
+++ symengine/functions.cpp (after formatting)
@@ -11,7 +11,10 @@
extern RCP<const Basic> im3;
extern RCP<const Basic> im5;
-RCP<const Basic> sqrt(RCP<const Basic> &arg) { return pow(arg, div(one, i2)); }
+RCP<const Basic> sqrt(RCP<const Basic> &arg)
+{
+ return pow(arg, div(one, i2));
+}
RCP<const Basic> cbrt(RCP<const Basic> &arg)
{
I tried several ways to apply this patch (from the base of the git directory):
$ git apply format.diff
error: functions.cpp: No such file or directory
$ git am format.diff
Patch format detection failed.
$ patch -p1 < format.diff
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- symengine/functions.cpp (before formatting)
|+++ symengine/functions.cpp (after formatting)
--------------------------
File to patch:
EDIT The patch above could be applied if the file paths had a leading dot.
How can I either apply this patch as is or get clang-format-patch.py to create a diff in a format like this:
diff --git a/symengine/functions.cpp b/symengine/functions.cpp
index c2fbc01a..75ef7d63 100644
--- a/symengine/functions.cpp
+++ b/symengine/functions.cpp
@@ -11,10 +11,8 @@ extern RCP<const Basic> im2;
extern RCP<const Basic> im3;
extern RCP<const Basic> im5;
-RCP<const Basic> sqrt(RCP<const Basic> &arg)
-{
- return pow(arg, div(one, i2));
-}
+RCP<const Basic> sqrt(RCP<const Basic> &arg) { return pow(arg, div(one, i2)); }
+
RCP<const Basic> cbrt(RCP<const Basic> &arg)
{
return pow(arg, div(one, i3));
which is easily applied using git apply format.diff