git-difft 622 B

1234567891011121314
  1. #!/usr/bin/env bash
  2. # git diff.external wrapper: render diffs with difftastic when it's installed,
  3. # else fall back to a plain unified diff so `git diff` never hard-fails on a
  4. # machine without difft.
  5. #
  6. # git calls an external differ with 7 args:
  7. # path old-file old-hex old-mode new-file new-hex new-mode
  8. if command -v difft >/dev/null 2>&1; then
  9. exec difft "$@"
  10. fi
  11. # Fallback: plain unified diff. `diff` exits 1 when files differ, but git treats a
  12. # non-zero exit from an external differ as failure ("external diff died"), so we
  13. # swallow it and always exit 0.
  14. diff -u -L "a/$1" -L "b/$1" -- "$2" "$5" || true