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