Skip to content

Commit

Permalink
Notes
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey committed Aug 1, 2023
1 parent f9bc120 commit f73af2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions lua/neogit/lib/git/index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ end

function M.register(meta)
meta.update_index = function(state)
-- This exists to prevent double-refreshing the repo, when triggered by both the action callback and filewatcher
-- callback. We are assuming that if the `.git/index` file has not been modified, then there's no need to update the
-- status buffer/repo state.
state.index.timestamp = state.index_stat()
end
end
Expand Down
33 changes: 24 additions & 9 deletions lua/neogit/lib/git/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local git = {
stash = require("neogit.lib.git.stash"),
}
local Collection = require("neogit.lib.collection")
local a = require("plenary.async")

local function update_file(file, mode, name)
local mt, diff, has_diff
Expand All @@ -19,6 +20,12 @@ local function update_file(file, mode, name)
end

local function update_status(state)
-- git-status outputs files relative to the cwd.
--
-- Save the working directory to allow resolution to absolute paths since the
-- cwd may change after the status is refreshed and used, especially if using
-- rooter plugins with lsp integration
local cwd = vim.loop.cwd()
local result = git.cli.status.porcelain(2).branch.call():trim()

local untracked_files, unstaged_files, staged_files = {}, {}, {}
Expand Down Expand Up @@ -90,28 +97,36 @@ local function update_status(state)
end
end

state.cwd = vim.loop.cwd()
state.cwd = cwd

state.untracked.items = untracked_files
state.unstaged.items = unstaged_files
state.staged.items = staged_files
end

local function update_branch_information(state)
local tasks = {}

if state.head.oid ~= "(initial)" then
local result = git.cli.log.max_count(1).pretty("%B").call():trim()
state.head.commit_message = result.stdout[1]
table.insert(tasks, function()
state.head.commit_message = git.cli.log.max_count(1).pretty("%B").call():trim().stdout[1]
end)

if state.upstream.ref then
local result =
git.cli.log.max_count(1).pretty("%B").for_range("@{upstream}").show_popup(false).call():trim()
state.upstream.commit_message = result.stdout[1]
table.insert(tasks, function()
state.upstream.commit_message = git.cli.log.max_count(1).pretty("%B").for_range("@{upstream}").show_popup(false).call():trim().stdout[1]
end)
end

local pushRemote = require("neogit.lib.git").branch.pushRemote_ref()
if pushRemote then
local result =
git.cli.log.max_count(1).pretty("%B").for_range(pushRemote).show_popup(false).call():trim()
state.pushRemote.commit_message = result.stdout[1]
table.insert(tasks, function()
state.pushRemote.commit_message = git.cli.log.max_count(1).pretty("%B").for_range(pushRemote).show_popup(false).call():trim().stdout[1]
end)
end

if #tasks > 0 then
a.util.join(tasks)
end
end
end
Expand Down

0 comments on commit f73af2f

Please sign in to comment.