Skip to content

Commit

Permalink
Merge branch 'master' into file-watcher-wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey authored Jul 15, 2023
2 parents e1f4ae8 + cc77769 commit 9bd1067
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 82 deletions.
37 changes: 36 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,47 @@ jobs:
selene:
runs-on: ubuntu-latest
steps:
- name: Restore Cached Selene
id: cache-selene-restore
uses: actions/cache@v3
with:
key: ${{ runner.os }}-selene
path: ~/.cargo/bin/selene

- uses: actions/checkout@v1
- name: Compare the cached Selene version against crates.io
id: check-selene-cache
run: |
CRATES_IO_SELENE_VERSION=$(curl -s -L0 https://crates.io/api/v1/crates/selene | jq -r '.crate.max_stable_version')
CACHED_SELENE_VERSION="$((selene --version || printf "INVALID_VERSION") | awk '{print $2}')"
printf "Crates IO Selene Version: %s\n" "${CRATES_IO_SELENE_VERSION}"
printf "Cached Selene Version: %s\n" "${CACHED_SELENE_VERSION}"
CACHED_SELENE_VALID=false
if [[ "${CRATES_IO_SELENE_VERSION}" == "${CACHED_SELENE_VERSION}" ]]; then
CACHED_SELENE_VALID=true
printf "Cache is valid!\n"
fi
printf "cache-valid=%s\n" "${CACHED_SELENE_VALID}" >> "${GITHUB_OUTPUT}"
- uses: actions-rs/toolchain@v1
if: ${{ steps.check-selene-cache.outputs.cache-valid != 'true'}}
with:
toolchain: stable
- name: Install Selene
run: cargo install selene
if: ${{ steps.check-selene-cache.outputs.cache-valid != 'true'}}
run: cargo install selene --force

- name: Save New Selene Build to Cache
if: ${{ steps.check-selene-cache.outputs.cache-valid != 'true'}}
id: cache-selene-save
uses: actions/cache/save@v3
with:
key: ${{ runner.os }}-selene
path: ~/.cargo/bin/selene

- name: Run Selene
run: make lint
stylua:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ neogit.setup {
--
-- Requires you to have `sindrets/diffview.nvim` installed.
-- use {
-- 'TimUntersberger/neogit',
-- 'NeogitOrg/neogit',
-- requires = {
-- 'nvim-lua/plenary.nvim',
-- 'sindrets/diffview.nvim'
Expand Down
6 changes: 2 additions & 4 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ Neogit is a magit clone for Neovim that is currently work in progress.
Staging/unstaging maps ~

*neogit_s*
s Stage (also supports staging selection/hunk)
s Stage (also supports staging selection/hunk)

*neogit_S*
S Stage unstage changes
S Stage unstaged changes

*neogit_<C-s>*
<C-s> Stage Everything
Expand All @@ -79,8 +79,6 @@ Diff maps ~

*neogit-commit-maps*
Commit maps ~
*neogit_c*
c Open commit popup

<C-C><C-C> Commit (when writing a commit message)

Expand Down
1 change: 0 additions & 1 deletion doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ neogit_L neogit.txt /*neogit_L*
neogit_P neogit.txt /*neogit_P*
neogit_S neogit.txt /*neogit_S*
neogit_U neogit.txt /*neogit_U*
neogit_c neogit.txt /*neogit_c*
neogit_d neogit.txt /*neogit_d*
neogit_fold neogit.txt /*neogit_fold*
neogit_p neogit.txt /*neogit_p*
Expand Down
6 changes: 3 additions & 3 deletions ftplugin/NeogitCommitMessage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ end

vim.cmd.source("$VIMRUNTIME/ftplugin/gitcommit.vim")

local parser = vim.treesitter.language.get_lang("gitcommit")
if parser then
vim.treesitter.start(0, parser)
local ok, _ = pcall(vim.treesitter.language.inspect, "gitcommit")
if ok then
vim.treesitter.start(0, "gitcommit")
vim.cmd([[au BufUnload <buffer> lua vim.treesitter.stop(0)]])
end
6 changes: 3 additions & 3 deletions ftplugin/NeogitMergeMessage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ end

vim.cmd.source("$VIMRUNTIME/ftplugin/gitcommit.vim")

local parser = vim.treesitter.language.get_lang("gitcommit")
if parser then
vim.treesitter.start(0, parser)
local ok, _ = pcall(vim.treesitter.language.inspect, "gitcommit")
if ok then
vim.treesitter.start(0, "gitcommit")
vim.cmd([[au BufUnload <buffer> lua vim.treesitter.stop(0)]])
end
6 changes: 3 additions & 3 deletions ftplugin/NeogitRebaseTodo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ end

vim.cmd.source("$VIMRUNTIME/ftplugin/gitrebase.vim")

local parser = vim.treesitter.language.get_lang("git_rebase")
if parser then
vim.treesitter.start(0, parser)
local ok, _ = pcall(vim.treesitter.language.inspect, "git_rebase")
if ok then
vim.treesitter.start(0, "git_rebase")
vim.cmd([[au BufUnload <buffer> lua vim.treesitter.stop(0)]])
end
9 changes: 6 additions & 3 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ M.values = {
item = { ">", "v" },
section = { ">", "v" },
},
integrations = {
diffview = false,
},
integrations = setmetatable({}, {
__index = function(_, key)
local ok, value = pcall(require, key)
return ok and value or false
end,
}),
sections = {
untracked = {
folded = false,
Expand Down
10 changes: 9 additions & 1 deletion lua/neogit/lib/git/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,16 @@ local configurations = {
},
}

-- TODO: Consider returning a Path object, since consumers of this function tend to need that anyways.
local function git_root()
return process.new({ cmd = { "git", "rev-parse", "--show-toplevel" } }):spawn_blocking().stdout[1]
local process =
process.new({ cmd = { "git", "rev-parse", "--show-toplevel" }, ignore_code = true }):spawn_blocking()

if process ~= nil and process.code == 0 then
return process.stdout[1]
else
return ""
end
end

local git_root_sync = function()
Expand Down
16 changes: 14 additions & 2 deletions lua/neogit/lib/git/index.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local cli = require("neogit.lib.git.cli")
local M = {}

---Generates a patch that can be applied to index
Expand Down Expand Up @@ -65,14 +66,13 @@ function M.generate_patch(item, hunk, from, to, reverse)
return table.concat(diff_content, "\n")
end

---comment
---@param patch string diff generated with M.generate_patch
---@param opts table
---@return table
function M.apply(patch, opts)
opts = opts or { reverse = false, cached = false, index = false }

local cmd = require("neogit.lib.git.cli").apply
local cmd = cli.apply

if opts.reverse then
cmd = cmd.reverse
Expand All @@ -89,6 +89,18 @@ function M.apply(patch, opts)
return cmd.with_patch(patch).call()
end

function M.add(files)
return cli.add.files(unpack(files)).call()
end

function M.checkout(files)
return cli.checkout.files(unpack(files)).call()
end

function M.reset(files)
return cli.reset.files(unpack(files)).call()
end

-- Make sure the index is in sync as git-status skips it
-- Do this manually since the `cli` add --no-optional-locks
function M.update()
Expand Down
8 changes: 8 additions & 0 deletions lua/neogit/lib/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ function M:show()
},
}
end,
autocmds = {
["WinLeave"] = function()
if self.buffer.kind == "floating" then
-- We pcall this because it's possible the window was closed by a command invocation, e.g. "cc" for commits
pcall(self.close, self)
end
end,
},
}
end

Expand Down
5 changes: 4 additions & 1 deletion lua/neogit/popups/help/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ local M = {}
local util = require("neogit.lib.util")
local NONE = function() end

local status_mappings = vim.tbl_add_reverse_lookup(require("neogit.config").values.mappings.status)
-- Using deep extend this way creates a copy of the mapping values
local status_mappings = vim.tbl_add_reverse_lookup(
vim.tbl_deep_extend("force", require("neogit.config").values.mappings.status, {})
)

local function present(commands)
local presenter = util.map(commands, function(command)
Expand Down
16 changes: 8 additions & 8 deletions lua/neogit/popups/push/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function M.to_upstream(popup)
local remote, branch, set_upstream

if upstream then
remote, branch = unpack(vim.split(upstream, "/"))
remote, branch = upstream:match("^([^/]*)/(.*)$")
else
set_upstream = true
branch = git.repo.head.branch
Expand All @@ -60,14 +60,14 @@ function M.to_upstream(popup)
end

function M.to_elsewhere(popup)
local target = FuzzyFinderBuffer.new(git.branch.get_remote_branches())
:open_async { prompt_prefix = "push > " }
if not target then
return
end
local target = FuzzyFinderBuffer.new(git.branch.get_remote_branches()):open_async {
prompt_prefix = "push > ",
}

local remote, branch = unpack(vim.split(target, "/"))
push_to(popup:get_arguments(), remote, branch)
if target then
local remote, branch = target:match("^([^/]*)/(.*)$")
push_to(popup:get_arguments(), remote, branch)
end
end

function M.push_other(popup)
Expand Down
46 changes: 10 additions & 36 deletions lua/neogit/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,54 +101,27 @@ local function create_preview_buffer()
},
}

local chan = vim.api.nvim_open_term(buffer.handle, {})

preview_buffer = {
chan = chan,
buffer = buffer,
current_span = nil,
content = "",
}
end

--from https://github.com/stevearc/overseer.nvim/blob/82ed207195b58a73b9f7d013d6eb3c7d78674ac9/lua/overseer/util.lua#L119
---@param win number
local function scroll_to_end(win)
local bufnr = vim.api.nvim_win_get_buf(win)
local lnum = vim.api.nvim_buf_line_count(bufnr)
local last_line = vim.api.nvim_buf_get_lines(bufnr, -2, -1, true)[1]
-- Hack: terminal buffers add a bunch of empty lines at the end. We need to ignore them so that
-- we don't end up scrolling off the end of the useful output.
-- This has the unfortunate effect that we may not end up tailing the output as more arrives
if vim.bo[bufnr].buftype == "terminal" then
local half_height = math.floor(vim.api.nvim_win_get_height(win) / 2)
for i = lnum, 1, -1 do
local prev_line = vim.api.nvim_buf_get_lines(bufnr, i - 1, i, true)[1]
if prev_line ~= "" then
-- Only scroll back if we detect a lot of padding lines, and the total real output is
-- small. Otherwise the padding may be legit
if lnum - i >= half_height and i < half_height then
lnum = i
last_line = prev_line
end
break
end
end
end
vim.api.nvim_win_set_cursor(win, { lnum, vim.api.nvim_strwidth(last_line) })
end

function Process.show_console()
create_preview_buffer()

local win = preview_buffer.buffer:show()
scroll_to_end(win)
vim.api.nvim_chan_send(vim.api.nvim_open_term(preview_buffer.buffer.handle, {}), preview_buffer.content)
preview_buffer.buffer:show()
-- Scroll to the end of viewable text
vim.cmd.startinsert()
vim.defer_fn(vim.cmd.stopinsert, 50)

-- vim.api.nvim_win_call(win, function()
-- vim.cmd.normal("G")
-- end)
end

local nvim_chan_send = vim.api.nvim_chan_send

---@param process Process
---@param data string
local function append_log(process, data)
Expand All @@ -158,11 +131,12 @@ local function append_log(process, data)
end

if preview_buffer.current_span ~= process.job then
nvim_chan_send(preview_buffer.chan, string.format("> %s\r\n", table.concat(process.cmd, " ")))
preview_buffer.content = preview_buffer.content
.. string.format("> %s\r\n", table.concat(process.cmd, " "))
preview_buffer.current_span = process.job
end

nvim_chan_send(preview_buffer.chan, data .. "\r\n")
preview_buffer.content = preview_buffer.content .. data .. "\r\n"
end

vim.schedule(function()
Expand Down
Loading

0 comments on commit 9bd1067

Please sign in to comment.