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