Mercurial > hg
comparison contrib/editmergeps.ps1 @ 32329:799615bbf5bf
contrib: add editmerge version for powershell
This just adds a translation of existing contrib/editmerge to powershell.
It allows users on Windows to iteratively resolve conflicts in their
editor of choice.
# no-check-commit
author | Kostia Balytskyi <ikostia@fb.com> |
---|---|
date | Thu, 18 May 2017 14:36:46 -0700 |
parents | |
children | 864fc285d10a |
comparison
equal
deleted
inserted
replaced
32328:531e6a57abd2 | 32329:799615bbf5bf |
---|---|
1 # A simple script for opening merge conflicts in editor | |
2 # A loose translation of contrib/editmerge to powershell | |
3 # Please make sure that both editmergeps.bat and editmerge.ps1 are available | |
4 # via %PATH% and use the following Mercurial settings to enable it | |
5 # | |
6 # [ui] | |
7 # editmergeps | |
8 # editmergeps.args=$output | |
9 # editmergeps.check=changed | |
10 # editmergeps.premerge=keep | |
11 | |
12 $file=$args[0] | |
13 | |
14 function Get-Lines | |
15 { | |
16 Select-String "^<<<<<<" $file | % {"$($_.LineNumber)"} | |
17 } | |
18 | |
19 $ed = $Env:HGEDITOR; | |
20 if ($ed -eq $nil) | |
21 { | |
22 $ed = $Env:VISUAL; | |
23 } | |
24 if ($ed -eq $nil) | |
25 { | |
26 $ed = $Env:EDITOR; | |
27 } | |
28 if ($ed -eq $nil) | |
29 { | |
30 $ed = $(hg showconfig ui.editor); | |
31 } | |
32 if ($ed -eq $nil) | |
33 { | |
34 Write-Error "merge failed - unable to find editor" | |
35 exit 1 | |
36 } | |
37 | |
38 if (($ed -eq "vim") -or ($ed -eq "emacs") -or ($ed -eq "nano")) | |
39 { | |
40 $lines = Get-Lines | |
41 $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil } | |
42 $previousline = $nil; | |
43 | |
44 | |
45 # open the editor to the first conflict until there are no more | |
46 # or the user stops editing the file | |
47 while (($firstline -ne $nil) -and ($firstline -ne $previousline)) | |
48 { | |
49 & "$ed" "+$firstline" "$file" | |
50 $previousline = $firstline | |
51 $lines = Get-Lines | |
52 $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil } | |
53 Write-Output "firstline is: $firstline, previousline is: $previousline" | |
54 } | |
55 } | |
56 else | |
57 { | |
58 $ "$ed" $file | |
59 } | |
60 | |
61 $conflicts=Get-Lines | |
62 if ($conflicts.Length -ne 0) | |
63 { | |
64 Write-Output "merge failed - resolve the conflicts (line $conflicts) then use 'hg resolve --mark'" | |
65 exit 1 | |
66 } | |
67 | |
68 exit 0 | |
69 |