##// END OF EJS Templates
editmerge: dequote other use of $ED...
Ryan McElroy -
r26804:61250290 default
parent child Browse files
Show More
@@ -1,58 +1,58
1 1 #!/usr/bin/env bash
2 2 # A simple script for opening merge conflicts in the editor.
3 3 # Use the following Mercurial settings to enable it.
4 4 #
5 5 # [ui]
6 6 # merge = editmerge
7 7 #
8 8 # [merge-tools]
9 9 # editmerge.args=$output
10 10 # editmerge.check=changed
11 11 # editmerge.premerge=keep
12 12
13 13 FILE="$1"
14 14
15 15 getlines() {
16 16 grep -n "^<<<<<<" "$FILE" | cut -f1 -d:
17 17 }
18 18
19 19 # editor preference loosely based on https://mercurial-scm.org/wiki/editor
20 20 # hg showconfig is at the bottom though, since it's slow to run (0.15 seconds)
21 21 ED="$HGEDITOR"
22 22 if [ "$ED" = "" ] ; then
23 23 ED="$VISUAL"
24 24 fi
25 25 if [ "$ED" = "" ] ; then
26 26 ED="$EDITOR"
27 27 fi
28 28 if [ "$ED" = "" ] ; then
29 29 ED="$(hg showconfig ui.editor)"
30 30 fi
31 31 if [ "$ED" = "" ] ; then
32 32 echo "merge failed - unable to find editor"
33 33 exit 1
34 34 fi
35 35
36 36 if [ "$ED" = "emacs" ] || [ "$ED" = "nano" ] || [ "$ED" = "vim" ] ; then
37 37 FIRSTLINE="$(getlines | head -n 1)"
38 38 PREVIOUSLINE=""
39 39
40 40 # open the editor to the first conflict until there are no more
41 41 # or the user stops editing the file
42 42 while [ ! "$FIRSTLINE" = "" ] && [ ! "$FIRSTLINE" = "$PREVIOUSLINE" ] ; do
43 "$ED" "+$FIRSTLINE" "$FILE"
43 $ED "+$FIRSTLINE" "$FILE"
44 44 PREVIOUSLINE="$FIRSTLINE"
45 45 FIRSTLINE="$(getlines | head -n 1)"
46 46 done
47 47 else
48 48 $ED "$FILE"
49 49 fi
50 50
51 51 # get the line numbers of the remaining conflicts
52 52 CONFLICTS="$(getlines | sed ':a;N;$!ba;s/\n/, /g')"
53 53 if [ ! "$CONFLICTS" = "" ] ; then
54 54 echo "merge failed - resolve the conflicts (line $CONFLICTS) then use 'hg resolve --mark'"
55 55 exit 1
56 56 fi
57 57
58 58 exit 0
General Comments 0
You need to be logged in to leave comments. Login now