ediff 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # test args
  3. if [ ! ${#} -ge 2 ]; then
  4. echo 1>&2 "Usage: ${0} LOCAL REMOTE [MERGED BASE]"
  5. echo 1>&2 " (LOCAL, REMOTE, MERGED, BASE can be provided by \`git mergetool'.)"
  6. exit 1
  7. fi
  8. # tools
  9. _EMACSCLIENT=/usr/bin/emacsclient
  10. _BASENAME=/bin/basename
  11. _CP=/bin/cp
  12. _EGREP=/bin/egrep
  13. _MKTEMP=/bin/mktemp
  14. # args
  15. _LOCAL=${1}
  16. _REMOTE=${2}
  17. if [ ${3} ] ; then
  18. _MERGED=${3}
  19. else
  20. _MERGED=${_REMOTE}
  21. fi
  22. if [ ${4} -a -r ${4} ] ; then
  23. _BASE=${4}
  24. _EDIFF=ediff-merge-files-with-ancestor
  25. _EVAL="${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\" \"${_BASE}\" nil \"${_MERGED}\""
  26. elif [ ${_REMOTE} = ${_MERGED} ] ; then
  27. _EDIFF=ediff
  28. _EVAL="${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\""
  29. else
  30. _EDIFF=ediff-merge-files
  31. _EVAL="${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\" nil \"${_MERGED}\""
  32. fi
  33. # console vs. X
  34. #if [ "${TERM}" = "linux" ]; then
  35. # unset DISPLAY
  36. # _EMACSCLIENTOPTS="-t"
  37. #else
  38. # _EMACSCLIENTOPTS="-c"
  39. #fi
  40. _EMACSCLIENTOPTS="-t"
  41. # run emacsclient
  42. ${_EMACSCLIENT} ${_EMACSCLIENTOPTS} -a "" -e "(${_EVAL})" 2>&1
  43. # check modified file
  44. if [ ! $(egrep -c '^(<<<<<<<|=======|>>>>>>>|####### Ancestor)' ${_MERGED}) = 0 ]; then
  45. _MERGEDSAVE=$(${_MKTEMP} --tmpdir `${_BASENAME} ${_MERGED}`.XXXXXXXXXX)
  46. ${_CP} ${_MERGED} ${_MERGEDSAVE}
  47. echo 1>&2 "Oops! Conflict markers detected in $_MERGED."
  48. echo 1>&2 "Saved your changes to ${_MERGEDSAVE}"
  49. echo 1>&2 "Exiting with code 1."
  50. exit 1
  51. fi
  52. exit 0