add git refresh

This commit is contained in:
kyazdani42 2020-02-19 14:32:33 +01:00
parent c77a560a63
commit 1c4fb795fb
5 changed files with 30 additions and 5 deletions

View File

@ -18,7 +18,6 @@
- [x] Mouse support
## TODO
- [ ] refresh tree (for git) on file save and update git status when needed
- [ ] find a good way to display git info
- [ ] better parsing of the git porcelain results

View File

@ -3,6 +3,7 @@ local system = function(v) api.nvim_call_function('system', { v }) end
local update_tree_view = require 'lib/winutils'.update_view
local scratch_wrapper = require 'lib/winutils'.scratch_wrapper
local update_tree_state = require 'lib/state'.refresh_tree
local refresh_git = require 'lib/git'.refresh_git
local EDIT_FILE = nil
@ -20,14 +21,15 @@ local function edit_rename(filename, path)
scratch_wrapper("rename", { "Rename " .. path, path .. filename })
end
-- TODO: for both 3 functions below, update git status before update_tree_state
local function add_file(path)
if string.match(path, '.*/$') then
system('mkdir -p ' .. path)
refresh_git()
update_tree_state()
update_tree_view(true)
else
system('touch ' .. path)
refresh_git()
update_tree_state()
update_tree_view(true)
end
@ -37,6 +39,7 @@ end
local function remove_file(confirmation)
if string.match(confirmation, '^y/n: y.*$') ~= nil then
system('rm -rf ' .. EDIT_FILE)
refresh_git()
update_tree_state()
update_tree_view(true)
end
@ -48,6 +51,7 @@ local function rename_file(path)
system('mv '..EDIT_FILE..' '..path)
EDIT_FILE = nil
api.nvim_command("q!")
refresh_git()
update_tree_state()
update_tree_view(true)
end

View File

@ -15,8 +15,14 @@ end
local GIT_STATUS = set_git_status()
local function refresh_git()
IS_GIT_REPO = is_git_repo()
if IS_GIT_REPO == false then return false end
GIT_STATUS = set_git_status()
return true
end
local function force_refresh_git()
IS_GIT_REPO = is_git_repo()
refresh_git()
end
local function is_folder_dirty(relpath)
@ -54,4 +60,5 @@ end
return {
get_git_attr = get_git_attr;
refresh_git = refresh_git;
force_refresh_git = force_refresh_git;
}

View File

@ -10,6 +10,7 @@ local get_tree = stateutils.get_tree
local init_tree = stateutils.init_tree
local open_dir = stateutils.open_dir
local check_dir_access = stateutils.check_dir_access
local refresh_tree = stateutils.refresh_tree
local winutils = require 'lib/winutils'
local update_view = winutils.update_view
@ -22,6 +23,10 @@ local conf = require 'lib/conf'
local set_root_path = conf.set_root_path
local get_cwd = conf.get_cwd
local git = require 'lib/git'
local refresh_git = git.refresh_git
local force_refresh_git = git.force_refresh_git
init_tree()
local function toggle()
@ -40,7 +45,6 @@ local function open_file(open_type)
local node = tree[tree_index]
if node.name == '..' then
-- TODO: git update
api.nvim_command('cd ..')
local new_path
@ -51,15 +55,16 @@ local function open_file(open_type)
end
set_root_path(new_path)
force_refresh_git()
init_tree(new_path)
update_view()
elseif open_type == 'chdir' then
-- TODO: git update
if node.dir == false or check_dir_access(node.path .. node.name) == false then return end
api.nvim_command('cd ' .. node.path .. node.name)
local new_path = get_cwd() .. '/'
set_root_path(new_path)
force_refresh_git()
init_tree(new_path)
update_view()
elseif node.dir == true then
@ -88,9 +93,17 @@ local function edit_file(edit_type)
end
end
local function refresh()
if refresh_git() == true then
refresh_tree()
update_view()
end
end
return {
toggle = toggle;
open_file = open_file;
edit_file = edit_file;
refresh = refresh;
}

View File

@ -41,6 +41,8 @@ execute 'hi def LuaTreeGitUntracked gui=NONE guifg='.g:terminal_color_6
execute 'hi def LuaTreeGitUnmerged gui=NONE guifg='.g:terminal_color_3
execute 'hi def LuaTreeGitDirty gui=NONE guifg='.g:terminal_color_13
au BufWritePost * lua require'tree'.refresh()
command! LuaTree lua require'tree'.toggle()
let &cpo = s:save_cpo