Skip to content

Commit

Permalink
refactor: add back in telescope
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ryall committed Jan 4, 2024
1 parent 3a1eacf commit 6494af8
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 357 deletions.
59 changes: 58 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
inputs.nixpkgs.follows = "nixpkgs";
};

neovim = {
url = "github:neovim/neovim?dir=contrib";
inputs.nixpkgs.follows = "nixpkgs";
};
neodev-nvim = {
url = "github:folke/neodev.nvim";
flake = false;
Expand Down Expand Up @@ -55,6 +59,9 @@
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(final: _: {
neovim-nightly = inputs.neovim.packages.${final.system}.neovim;
})
];
};
devShells = {
Expand All @@ -81,12 +88,6 @@
name = "telescope.nvim";
src = inputs.telescope-nvim;
};
packages.neorocks-test-stable = pkgs.callPackage ./nix/neorocks-test.nix {
name = "git-worktree-stable";
inherit self;
nvim = pkgs.neovim-unwrapped;
inherit (config.packages) plenary-plugin;
};

checks = {
inherit pre-commit-check;
Expand Down
109 changes: 20 additions & 89 deletions lua/git-worktree/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,54 +57,6 @@ function M.has_worktree(path_str, cb)
job:start()
end

-- --- @return boolean
-- function M.is_bare_repo()
-- local inside_worktree_job = Job:new({
-- "git",
-- "rev-parse",
-- "--is-bare-repository",
-- cwd = vim.loop.cwd(),
-- })
--
-- local stdout, code = inside_worktree_job:sync()
-- if code ~= 0 then
-- status:log().error("Error in determining if we are in a worktree")
-- return false
-- end
--
-- stdout = table.concat(stdout, "")
--
-- if stdout == "true" then
-- return true
-- else
-- return false
-- end
-- end
--
-- --- @return boolean
-- function M.is_worktree()
-- local inside_worktree_job = Job:new({
-- "git",
-- "rev-parse",
-- "--is-inside-work-tree",
-- cwd = vim.loop.cwd(),
-- })
--
-- local stdout, code = inside_worktree_job:sync()
-- if code ~= 0 then
-- status:log().error("Error in determining if we are in a worktree")
-- return false
-- end
--
-- stdout = table.concat(stdout, "")
--
-- if stdout == "true" then
-- return true
-- else
-- return false
-- end
-- end

--- @return string|nil
function M.gitroot_dir()
local job = Job:new {
Expand All @@ -113,20 +65,20 @@ function M.gitroot_dir()
'--path-format=absolute',
'--git-common-dir',
cwd = vim.loop.cwd(),
-- on_stderr = function(_, data)
-- status:log().info('ERROR: ' .. data)
-- end,
on_stderr = function(_, data)
Log.error('ERROR: ' .. data)
end,
}

local stdout, code = job:sync()
if code ~= 0 then
-- status:log().error(
-- 'Error in determining the git root dir: code:'
-- .. tostring(code)
-- .. ' out: '
-- .. table.concat(stdout, '')
-- .. '.'
-- )
Log.error(
'Error in determining the git root dir: code:'
.. tostring(code)
.. ' out: '
.. table.concat(stdout, '')
.. '.'
)
return nil
end

Expand All @@ -141,20 +93,20 @@ function M.toplevel_dir()
'--path-format=absolute',
'--show-toplevel',
cwd = vim.loop.cwd(),
-- on_stderr = function(_, data)
-- status:log().info('ERROR: ' .. data)
-- end,
on_stderr = function(_, data)
Log.error('ERROR: ' .. data)
end,
}

local stdout, code = job:sync()
if code ~= 0 then
-- status:log().error(
-- 'Error in determining the git root dir: code:'
-- .. tostring(code)
-- .. ' out: '
-- .. table.concat(stdout, '')
-- .. '.'
-- )
Log.error(
'Error in determining the git root dir: code:'
.. tostring(code)
.. ' out: '
.. table.concat(stdout, '')
.. '.'
)
return nil
end

Expand All @@ -180,27 +132,6 @@ function M.has_branch(branch, cb)
cb(found)
end):start()
end
--
-- function M.has_origin()
-- local found = false
-- local job = Job:new({
-- "git",
-- "remote",
-- "show",
-- on_stdout = function(_, data)
-- data = vim.trim(data)
-- found = found or data == "origin"
-- end,
-- cwd = vim.loop.cwd(),
-- })
--
-- -- TODO: I really don't want status's spread everywhere... seems bad
-- job:after(function()
-- status:status("found origin: " .. tostring(found))
-- end):sync()
--
-- return found
-- end

--- @param path string
--- @param branch string
Expand Down
6 changes: 0 additions & 6 deletions lua/git-worktree/git_spec.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
local git_harness = require('git-worktree.test.git_util')
local gwt_git = require('git-worktree.git')
local Status = require('git-worktree.status')

local status = Status:new()

-- local wait_for_result = function(job, result)
-- if type(result) == 'string' then
Expand All @@ -20,7 +17,6 @@ describe('git-worktree git operations', function()
describe('in normal repo', function()
before_each(function()
working_dir, master_dir = git_harness.prepare_repo()
status:reset(0)
end)
after_each(function()
vim.api.nvim_command('cd ' .. cwd)
Expand Down Expand Up @@ -99,7 +95,6 @@ describe('git-worktree git operations', function()
describe('in bare repo', function()
before_each(function()
working_dir = git_harness.prepare_repo_bare()
status:reset(0)
end)
after_each(function()
vim.api.nvim_command('cd ' .. cwd)
Expand Down Expand Up @@ -177,7 +172,6 @@ describe('git-worktree git operations', function()
describe('in worktree repo', function()
before_each(function()
working_dir, master_dir = git_harness.prepare_repo_bare_worktree(1)
status:reset(0)
end)
after_each(function()
vim.api.nvim_command('cd ' .. cwd)
Expand Down
29 changes: 0 additions & 29 deletions lua/git-worktree/hooks.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
-- local Enum = require("git-worktree.enum")
-- local Status = require("git-worktree.status")
-- local status = Status:new()

--- @class GitWorkTreeHook
--- @field SWITCH? fun(...): nil

Expand Down Expand Up @@ -47,29 +43,4 @@ M.hook_event_names = {
SWITCH = 'SWITCH',
}

-- function M.on_tree_change_handler(op, metadata)
-- if M._config.update_on_change then
-- if op == Enum.Operations.Switch then
-- local changed = M.update_current_buffer(metadata["prev_path"])
-- if not changed then
-- status
-- :log()
-- .debug("Could not change to the file in the new worktree,
-- running the `update_on_change_command`")
-- vim.cmd(M._config.update_on_change_command)
-- end
-- end
-- end
-- end

-- function M.emit_on_change(op, metadata)
-- -- TODO: We don't have a way to async update what is running
-- status:next_status(string.format("Running post %s callbacks", op))
-- print(metadata)
-- -- on_tree_change_handler(op, metadata)
-- -- for idx = 1, #on_change_callbacks do
-- -- on_change_callbacks[idx](op, metadata)
-- -- end
-- end

return M
Loading

0 comments on commit 6494af8

Please sign in to comment.