8 # [merge-tools] |
8 # [merge-tools] |
9 # editmerge.args=$output |
9 # editmerge.args=$output |
10 # editmerge.check=changed |
10 # editmerge.check=changed |
11 # editmerge.premerge=keep |
11 # editmerge.premerge=keep |
12 |
12 |
13 FILE=$1 |
13 FILE="$1" |
14 |
14 |
15 getlines() { |
15 getlines() { |
16 grep -n "^<<<<<<" $FILE | cut -f1 -d: |
16 grep -n "^<<<<<<" "$FILE" | cut -f1 -d: |
17 } |
17 } |
18 |
18 |
19 # editor preference loosely based on https://mercurial-scm.org/wiki/editor |
19 # editor preference loosely based on https://mercurial-scm.org/wiki/editor |
20 # hg showconfig is at the bottom though, since it's slow to run (0.15 seconds) |
20 # hg showconfig is at the bottom though, since it's slow to run (0.15 seconds) |
21 ED=$HGEDITOR |
21 ED="$HGEDITOR" |
22 if [ "$ED" = "" ] ; then |
22 if [ "$ED" = "" ] ; then |
23 ED=$VISUAL |
23 ED="$VISUAL" |
24 fi |
24 fi |
25 if [ "$ED" = "" ] ; then |
25 if [ "$ED" = "" ] ; then |
26 ED=$EDITOR |
26 ED="$EDITOR" |
27 fi |
27 fi |
28 if [ "$ED" = "" ] ; then |
28 if [ "$ED" = "" ] ; then |
29 ED=$(hg showconfig ui.editor) |
29 ED="$(hg showconfig ui.editor)" |
30 fi |
30 fi |
31 if [ "$ED" = "" ] ; then |
31 if [ "$ED" = "" ] ; then |
32 echo "merge failed - unable to find editor" |
32 echo "merge failed - unable to find editor" |
33 exit 1 |
33 exit 1 |
34 fi |
34 fi |
35 |
35 |
36 if [ "$ED" = "emacs" ] || [ "$ED" = "nano" ] || [ "$ED" = "vim" ] ; then |
36 if [ "$ED" = "emacs" ] || [ "$ED" = "nano" ] || [ "$ED" = "vim" ] ; then |
37 FIRSTLINE=$(getlines | head -n 1) |
37 FIRSTLINE="$(getlines | head -n 1)" |
38 PREVIOUSLINE="" |
38 PREVIOUSLINE="" |
39 |
39 |
40 # open the editor to the first conflict until there are no more |
40 # open the editor to the first conflict until there are no more |
41 # or the user stops editing the file |
41 # or the user stops editing the file |
42 while [ ! "$FIRSTLINE" = "" ] && [ ! "$FIRSTLINE" = "$PREVIOUSLINE" ] ; do |
42 while [ ! "$FIRSTLINE" = "" ] && [ ! "$FIRSTLINE" = "$PREVIOUSLINE" ] ; do |
43 $ED +$FIRSTLINE $FILE |
43 "$ED" "+$FIRSTLINE" "$FILE" |
44 PREVIOUSLINE=$FIRSTLINE |
44 PREVIOUSLINE="$FIRSTLINE" |
45 FIRSTLINE=$(getlines | head -n 1) |
45 FIRSTLINE="$(getlines | head -n 1)" |
46 done |
46 done |
47 else |
47 else |
48 $ED $FILE |
48 $ED "$FILE" |
49 fi |
49 fi |
50 |
50 |
51 # get the line numbers of the remaining conflicts |
51 # get the line numbers of the remaining conflicts |
52 CONFLICTS=$(getlines | sed ':a;N;$!ba;s/\n/, /g') |
52 CONFLICTS="$(getlines | sed ':a;N;$!ba;s/\n/, /g')" |
53 if [ ! "$CONFLICTS" = "" ] ; then |
53 if [ ! "$CONFLICTS" = "" ] ; then |
54 echo "merge failed - resolve the conflicts (line $CONFLICTS) then use 'hg resolve --mark'" |
54 echo "merge failed - resolve the conflicts (line $CONFLICTS) then use 'hg resolve --mark'" |
55 exit 1 |
55 exit 1 |
56 fi |
56 fi |
57 |
57 |