From f397e1050cc404269fa0e5ec011ae228e2af9c90 Mon Sep 17 00:00:00 2001 From: kyazdani42 Date: Wed, 19 Feb 2020 23:01:52 +0100 Subject: [PATCH] fix git parsing and init - run `ls ROOT_PATH` on init to make sure we are in the right place - match git path with `.*` to make sure we check when in a subdir > it could cause issues though, fix this later with a better > git interface --- README.md | 2 -- lua/lib/git.lua | 3 ++- lua/lib/state.lua | 10 ++++------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 636a9565..379ad74c 100644 --- a/README.md +++ b/README.md @@ -24,5 +24,3 @@ - cd command to move faster accross the fs if needed - quickly find file in the directory structure - use libuv functions instead of `touch` and `mkdir` in `add_file()` -- fix colors fucks up on refresh sometimes (and git is wrong when cd into a subdirectory) - diff --git a/lua/lib/git.lua b/lua/lib/git.lua index c7c41a27..45fa8405 100644 --- a/lua/lib/git.lua +++ b/lua/lib/git.lua @@ -35,7 +35,8 @@ end local function create_git_checker(pattern) return function(relpath) for _, status in pairs(GIT_STATUS) do - local ret = string.match(status, '^.. ' .. relpath) + -- TODO: fix .* as it could be problematic + local ret = string.match(status, '^.. .*' .. relpath) if ret ~= nil and string.match(ret, pattern) ~= nil then return true end end return false diff --git a/lua/lib/state.lua b/lua/lib/state.lua index f625f501..7837f3ba 100644 --- a/lua/lib/state.lua +++ b/lua/lib/state.lua @@ -30,14 +30,12 @@ local function check_dir_access(path) end local function list_dirs(path) - local ls_cmd = 'ls -A --ignore=.git ' - if path == nil then - return syslist(ls_cmd) - elseif check_dir_access(path) == false then + if check_dir_access(path) == false then -- TODO: display an error here (permission denied) return {} else - return syslist(ls_cmd .. path) + local ls_cmd = 'ls -A --ignore=.git ' ..path + return syslist(ls_cmd) end end @@ -84,7 +82,7 @@ local function create_nodes(path, relpath, depth, dirs) end local function init_tree() - Tree = create_nodes(ROOT_PATH, '', 0, list_dirs()) + Tree = create_nodes(ROOT_PATH, '', 0, list_dirs(ROOT_PATH)) if ROOT_PATH ~= '/' then table.insert(Tree, 1, { path = ROOT_PATH,