Open kalaskow opened 2 years ago
I am sorry I haven't posted any example to reproduce.
Please take this file to_reproduce.txt, rename it to to_reproduce.py
and do the following:
python -m libcst.tool codemod add_trailing_commas.AddTrailingCommas to_reproduce.py -u > mod.patch
patch to_reproduce.py mod.patch
With LibCST version 0.4.7
I encounter the following error:
patching file to_reproduce.py
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file to_reproduce.py.rej
Funnily enough, when I remove trailing blank line from to_reproduce.py
I get:
patching file to_reproduce.py
Hunk #1 succeeded at 1 with fuzz 1.
Hello,
I've written a codemod which rewrites parameters in given function call. Details are not important. Also, I work in a project where we use Perforce as a source control. As a result I can't use default libcst.tool mode where files are just modified in place as I need to know upfront which files need modification. I've decided to use
-u
option which generates unified diff. I can preprocess such diff to extract files which require modification, open them and the apply the diff. Problem is the generated diff can't be applied when file is "short".The problem
Generate diff:
Apply diff:
I've compared what is the difference between diff generated by libcst.tool (
x.diff
) an real diff (y.diff
):It seems that
libcst.tool codemod -u
adds one unneccessary line which preventspatch
to apply such diff.If I use
-u=1
to limit context diff is generated correctly and can be applied without any problems. When diff happens to span over entire file (-u=3
) then it cannot be applied.Conclusion
Am I using wrong options or diff generation in some cases is wrong?