Skip to content

Commit 61765d0

Browse files
committed
Merge commit 'refs/pull/22/head' of github.com:whiteinge/diffconflicts
2 parents b097baa + b10cd62 commit 61765d0

File tree

4 files changed

+122
-8
lines changed

4 files changed

+122
-8
lines changed

README.md

Lines changed: 20 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,22 @@ 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+
[merge-tools]
101+
diffconflicts.executable=vim
102+
diffconflicts.args=-c 'let g:diffconflicts_vcs="hg"' -c DiffConflicts "$output" $base $local $other
103+
diffconflicts.premerge=keep
104+
diffconflicts.check=conflicts
105+
diffconflicts.priority=99
106+
107+
to your `.hgrc` file.
108+
Or, if you prefer to always open both the diff view and the history view use
109+
110+
diffconflicts.args=-c 'let g:diffconflicts_vcs="hg"' -c DiffConflictsWithHistory "$output" $base $local $other
111+
112+
as the args setting to call `DiffConflictsWithHistory`.

_utils/make-conflicts_hg.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 borogroves
26+
And the mome raths outgabe.
27+
28+
"Beware the Jabberwock, my son!
29+
The jaws that bite, the claws that catch!
30+
Beware the Jub jub bird, and shun
31+
The frumious bandersnatch!"
32+
EOF
33+
34+
hg bookmark branchA
35+
hg commit -m 'Buncha fixes'
36+
37+
38+
hg update -Cr master
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 borogoves,
43+
And the mome raths outgrabe.
44+
45+
"Beware the Jabberwock, my son!
46+
The jaws that bite, the claws that catch!
47+
Beware the Jubjub bird, and shun
48+
The frumious Bandersnatch!"
49+
EOF
50+
hg commit -m 'Fix syntax mistakes'
51+
52+
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: 39 additions & 5 deletions
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
@@ -56,17 +70,32 @@ function! s:showHistory()
5670
wincmd h
5771

5872
" Populate each window.
59-
buffer LOCAL
73+
if g:diffconflicts_vcs == "hg"
74+
buffer ~local.
75+
file LOCAL
76+
else
77+
buffer LOCAL
78+
endif
6079
setlocal nomodifiable readonly
6180
diffthis
6281

6382
wincmd l
64-
buffer BASE
83+
if g:diffconflicts_vcs == "hg"
84+
buffer ~base.
85+
file BASE
86+
else
87+
buffer BASE
88+
endif
6589
setlocal nomodifiable readonly
6690
diffthis
6791

6892
wincmd l
69-
buffer REMOTE
93+
if g:diffconflicts_vcs == "hg"
94+
buffer ~other.
95+
file OTHER
96+
else
97+
buffer REMOTE
98+
endif
7099
setlocal nomodifiable readonly
71100
diffthis
72101

@@ -75,6 +104,11 @@ function! s:showHistory()
75104
endfunction
76105

77106
function! s:checkThenShowHistory()
107+
if g:diffconflicts_vcs == "hg"
108+
let l:filecheck = 'v:val =~# "\\~base\\." || v:val =~# "\\~local\\." || v:val =~# "\\~other\\."'
109+
else
110+
let l:filecheck = 'v:val =~# "BASE" || v:val =~# "LOCAL" || v:val =~# "REMOTE"'
111+
endif
78112
let l:xs =
79113
\ filter(
80114
\ map(
@@ -84,7 +118,7 @@ function! s:checkThenShowHistory()
84118
\ ),
85119
\ 'bufname(v:val)'
86120
\ ),
87-
\ 'v:val =~# "BASE" || v:val =~# "LOCAL" || v:val =~# "REMOTE"'
121+
\ l:filecheck
88122
\ )
89123

90124
if (len(l:xs) < 3)

0 commit comments

Comments
 (0)