Skip to content

Commit a87c40e

Browse files
author
Harald Klimach
committed
Added support for Mercurial to the plugin.
Basically this just removes the unconditional reliance on the git executable for the diff3 checking and introduces the variable `g:diffconflicts_vcs` to decide whether to call git or not. Aside from this small change there is just the documentation added on how to utilize this plugin in Mercurial.
1 parent b097baa commit a87c40e

File tree

4 files changed

+103
-4
lines changed

4 files changed

+103
-4
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# vim-diffconflicts
22

3-
A better Vimdiff Git mergetool
3+
A better Vimdiff Git (and Mercurial) mergetool
44

55
tl;dr:
66

@@ -91,3 +91,26 @@ splitting them apart.
9191
changes.
9292
9393
This tab is not opened by default so that Vim starts more quickly.
94+
95+
96+
## Mercurial
97+
98+
Configure Mercurial to use diffconflicts as a mergetool by adding:
99+
100+
```
101+
[merge-tools]
102+
diffconflicts.executable=vim
103+
diffconflicts.args=-c 'let g:diffconflicts_vcs="hg"' -c DiffConflicts "$output" "$base" "$local" "$other"
104+
diffconflicts.premerge=keep
105+
diffconflicts.check=conflicts
106+
diffconflicts.priority=99
107+
```
108+
109+
to your `.hgrc` file.
110+
Or, if you prefer to always open both the diff view and the history view use
111+
112+
```
113+
diffconflicts.args=-c 'let g:diffconflicts_vcs="hg"' -c DiffConflictsWithHistory "$output" "$base" "$local" "$other"
114+
```
115+
116+
as the args setting to call `DiffConflictsWithHistory`.

_utils/make-conflicts_hg.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
hg init testrepo_hg
4+
cd testrepo_hg
5+
6+
cat << EOF > poem.txt
7+
twas bri1lig, and the slithy toves
8+
did gyre and gimble in the wabe
9+
all mimsy were the borogroves
10+
and the m0me raths outgabe.
11+
12+
"Beware the Jabberwock, my son!
13+
The jaws that bite, the claws that catch!
14+
Beware the Jub jub bird, and shun
15+
The frumious bandersnatch!"
16+
EOF
17+
18+
hg add poem.txt
19+
hg bookmark master
20+
hg commit -m 'Commit One'
21+
22+
cat << EOF > poem.txt
23+
twas brillig, and the slithy toves
24+
Did gyre and gimble in the wabe:
25+
all mimsy were the borogoves,
26+
And the mome raths outgrabe.
27+
28+
"Beware the Jabberwock, my son!
29+
The jaws that bite, the claws that catch!
30+
Beware the Jubjub bird, and shun
31+
The frumious Bandersnatch!"
32+
EOF
33+
34+
hg bookmark branchA
35+
hg commit -m 'Fix syntax mistakes'
36+
37+
hg update -Cr master
38+
39+
cat << EOF > poem.txt
40+
'Twas brillig, and the slithy toves
41+
Did gyre and gimble in the wabe:
42+
All mimsy were the borogroves
43+
And the mome raths outgabe.
44+
45+
"Beware the Jabberwock, my son!
46+
The jaws that bite, the claws that catch!
47+
Beware the Jub jub bird, and shun
48+
The frumious bandersnatch!"
49+
EOF
50+
51+
hg commit -m 'Buncha fixes'
52+
53+
hg --config ui.merge=internal:merge merge branchA

doc/diffconflicts.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*diffconflicts.txt* A better Vimdiff Git mergetool
1+
*diffconflicts.txt* A better Vimdiff Git/Mercurial mergetool
22

33
This plugin converts a file containing Git conflict markers into a two-way diff
44
in Vimdiff. Additional mappings can be given to see the full three-way diff.
@@ -10,6 +10,14 @@ git config --global mergetool.diffconflicts.cmd 'vim -c DiffConflicts "$MERGED"
1010
git config --global mergetool.diffconflicts.trustExitCode true
1111
git config --global mergetool.keepBackup false
1212

13+
For Mercurial use the following settings in your .hgrc:
14+
15+
[merge-tools]
16+
diffconflicts.executable=vim
17+
diffconflicts.args=-c 'let g:diffconflicts_vcs="hg"' -c DiffConflicts "$output" "$base" "$local" "$other"
18+
diffconflicts.premerge=keep
19+
diffconflicts.check=conflicts
20+
1321
Commands:
1422
:DiffConflicts
1523
Convert a file containing Git conflict markers into a two-way diff.
@@ -23,4 +31,5 @@ Commands:
2331
the Git mergetool configuration to always open the history by default.
2432

2533
*DiffConflicts-settings*
26-
This plugin doesn't have any settings.
34+
Use g:diffconflicts_vcs to indicate which version control system produced
35+
the conflict file (Git or Mercurial).

plugin/diffconflicts.vim

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ let g:loaded_diffconflicts = 1
1010
let s:save_cpo = &cpo
1111
set cpo&vim
1212

13+
" CONFIGURATION
14+
if !exists("g:diffconflicts_vcs")
15+
" Default to git
16+
let g:diffconflicts_vcs = "git"
17+
endif
18+
19+
let g:loaded_diffconflicts = 1
1320
function! s:hasConflicts()
1421
try
1522
silent execute "%s/^<<<<<<< //gn"
@@ -22,7 +29,14 @@ endfunction
2229
function! s:diffconfl()
2330
let l:origBuf = bufnr("%")
2431
let l:origFt = &filetype
25-
let l:conflictStyle = system("git config --get merge.conflictStyle")[:-2]
32+
33+
if g:diffconflicts_vcs == "git"
34+
" Obtain the git setting for the conflict style.
35+
let l:conflictStyle = system("git config --get merge.conflictStyle")[:-2]
36+
else
37+
" Assume 2way conflict style otherwise.
38+
let l:conflictStyle = "diff"
39+
endif
2640

2741
" Set up the right-hand side.
2842
rightb vsplit

0 commit comments

Comments
 (0)