1

I'm trying to use git diff to ensure that my JavaScript has been beautified before committing.

js-beautify src.js | git -c core.fileMode=false diff --no-index -- src.js -

I've followed the instructions here for ignoring file mode but I still get this output.

diff --git a/src.js b/-
old mode 100755
new mode 100644
index 13158aa..0000000

I also tried git config core.fileMode false to no avail. If I change permissions of the file and diff against HEAD, the command works as expected (diff is empty).

chmod 644 src.js
git -c core.fileMode=false diff -- src.js

Is it possible to ignore the permissions of files that aren't indexed? I'm using git version 1.9.1.

Community
  • 1
  • 1
Neil
  • 2,137
  • 16
  • 24

1 Answers1

2

One method around that would be something along these lines:

js-beautify src.js | diff - <(git show HEAD:./src.js)

or alternatively:

diff <(js-beautify src.js) <(git show HEAD:./src.js)

That won't produce the git diff format, but I don't know if that's critical for your particular use case.

twalberg
  • 59,951
  • 11
  • 89
  • 84