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

@@ -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;
}