Skip to content

Commit

Permalink
Merge pull request #2791 from chrisant996/fix_2789
Browse files Browse the repository at this point in the history
Fix #2789
  • Loading branch information
DRSDavidSoft committed Dec 5, 2022
2 parents 42df6cd + 0fdcda9 commit 24ba9c3
Showing 1 changed file with 50 additions and 40 deletions.
90 changes: 50 additions & 40 deletions vendor/clink.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,58 +408,72 @@ local function get_svn_status()
return true
end

---
-- Use a prompt coroutine to get git status in the background.
-- Cache the info so we can reuse it next time to reduce flicker.
---
local function get_git_info_table()
local info = clink_promptcoroutine(function ()
return get_git_status()
end)
if not info then
info = cached_info.git_info or {}
else
cached_info.git_info = info
end
return info
end

---
-- Get the status of working dir
-- @return {bool}
---
local last_git_status_time = nil
local last_git_status_setting = true
local function get_git_status_setting()
local time = os.clock()
local last_time = last_git_status_time
last_git_status_time = time
if last_time and time >= 0 and time - last_time < 10 then
return last_git_status_setting
end

-- When async prompt filtering is available, check the
-- prompt_overrideGitStatusOptIn config setting for whether to ignore the
-- cmder.status and cmder.cmdstatus git config opt-in settings.
if clink.promptcoroutine and io.popenyield and settings.get("prompt.async") then
if prompt_overrideGitStatusOptIn then
last_git_status_setting = true
return true
end
end

local gitStatusConfig = io.popen("git --no-pager config cmder.status 2>nul")

local gitStatusConfig = io_popenyield("git --no-pager config cmder.status 2>nul")
for line in gitStatusConfig:lines() do
if string.match(line, 'false') then
gitStatusConfig:close()
last_git_status_setting = false
return false
end
end
gitStatusConfig:close()

local gitCmdStatusConfig = io.popen("git --no-pager config cmder.cmdstatus 2>nul")
local gitCmdStatusConfig = io_popenyield("git --no-pager config cmder.cmdstatus 2>nul")
for line in gitCmdStatusConfig:lines() do
if string.match(line, 'false') then
gitCmdStatusConfig:close()
last_git_status_setting = false
return false
end
end
gitStatusConfig:close()
gitCmdStatusConfig:close()

last_git_status_setting = true
return true
end

---
-- Use a prompt coroutine to get git status in the background.
-- Cache the info so we can reuse it next time to reduce flicker.
---
local function get_git_info_table()
local info = clink_promptcoroutine(function ()
-- Use git status if allowed.
local cmderGitStatusOptIn = get_git_status_setting()
return cmderGitStatusOptIn and get_git_status() or {}
end)
if not info then
info = cached_info.git_info or {}
else
cached_info.git_info = info
end
return info
end

local function git_prompt_filter()

-- Don't do any git processing if the prompt doesn't want to show git info.
Expand All @@ -477,7 +491,6 @@ local function git_prompt_filter()

local git_dir = get_git_dir()
local color
cmderGitStatusOptIn = get_git_status_setting()
if git_dir then
local branch = get_git_branch(git_dir)
if branch then
Expand All @@ -487,28 +500,25 @@ local function git_prompt_filter()
cached_info.git_dir = git_dir
cached_info.git_branch = branch
end
-- Use git status if allowed.
if cmderGitStatusOptIn then
-- if we're inside of git repo then try to detect current branch
-- Has branch => therefore it is a git folder, now figure out status
local gitInfo = get_git_info_table()
local gitStatus = gitInfo.status
local gitConflict = gitInfo.conflict

if gitStatus == nil then
color = colors.nostatus
elseif gitStatus then
color = colors.clean
else
color = colors.dirty
end

if gitConflict then
color = colors.conflict
end
else
-- If we're inside of git repo then try to detect current branch
-- Has branch => therefore it is a git folder, now figure out status
local gitInfo = get_git_info_table()
local gitStatus = gitInfo.status
local gitConflict = gitInfo.conflict

if gitStatus == nil then
color = colors.nostatus
elseif gitStatus then
color = colors.clean
else
color = colors.dirty
end

if gitConflict then
color = colors.conflict
end

clink.prompt.value = string.gsub(clink.prompt.value, "{git}", " "..color.."("..verbatim(branch)..")")
return false
end
Expand Down

0 comments on commit 24ba9c3

Please sign in to comment.