forked from rgieseke/ta-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvc.lua
41 lines (40 loc) · 1.36 KB
/
vc.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- Displays a filtered list of files in a project along with their current
-- hg state or a standard snapopen dialog if hg is not used.
module('_m.common.vc', package.seeall)
-- Figure out the projects root and display states of the files in a
-- snapopen dialog.
function hg_status()
local path = buffer.filename:match('(.+)/')
local command = 'cd '..path..'; hg root 2>&1'
local f = io.popen(command)
local ans = f:read("*a")
f:close()
if ans:match(".hg not found") then
_m.textadept.snapopen.open({path})
else
local hg_root = ans:sub(1,-2)
command = 'cd '..path..'; hg st -amdcu 2>&1'
f = io.popen(command)
local status = f:read("*a")
f:close()
local items = {}
local fstatus, fname
for fstatus, fname in string.gmatch(status, "([AMDC\?])%s([%w\.]+)[\n]") do
items[#items+1] = fname
items[#items+1] = fstatus
end
local out =
gui.dialog('filteredlist',
'--title', 'hg ('..hg_root..')',
'--button1', 'gtk-ok',
'--button2', 'gtk-cancel',
'--no-newline',
'--string-output',
'--columns', 'File', 'Status',
'--items', unpack(items))
local response, file = out:match('([^\n]+)\n([^\n]+)$')
if response and response ~= 'gtk-cancel' then
io.open_file(hg_root..'/'..file)
end
end
end