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