diff --git a/lua/git-worktree/git.lua b/lua/git-worktree/git.lua index c245bfe..d3d9cb7 100644 --- a/lua/git-worktree/git.lua +++ b/lua/git-worktree/git.lua @@ -1,6 +1,7 @@ local Job = require('plenary.job') local Path = require('plenary.path') local Log = require('git-worktree.logger') +local uv = vim.uv or vim.loop ---@class GitWorktreeGitOps local M = {} @@ -16,12 +17,12 @@ function M.has_worktree(path_str, branch, cb) local path if path_str == '.' then - path_str = vim.loop.cwd() + path_str = uv.cwd() end path = Path:new(path_str) if not path:is_absolute() then - path = Path:new(string.format('%s' .. Path.path.sep .. '%s', vim.loop.cwd(), path_str)) + path = Path:new(string.format('%s' .. Path.path.sep .. '%s', uv.cwd(), path_str)) end path = path:absolute() @@ -47,7 +48,7 @@ function M.has_worktree(path_str, branch, cb) end end end, - cwd = vim.loop.cwd(), + cwd = uv.cwd(), } job:after(function() @@ -64,7 +65,7 @@ function M.gitroot_dir() local job = Job:new { command = 'git', args = { 'rev-parse', '--path-format=absolute', '--git-common-dir' }, - cwd = vim.loop.cwd(), + cwd = uv.cwd(), on_stderr = function(_, data) Log.error('ERROR: ' .. data) end, @@ -90,7 +91,7 @@ function M.toplevel_dir() local job = Job:new { command = 'git', args = { 'rev-parse', '--path-format=absolute', '--show-toplevel' }, - cwd = vim.loop.cwd(), + cwd = uv.cwd(), on_stderr = function(_, data) Log.error('ERROR: ' .. data) end, @@ -125,7 +126,7 @@ function M.has_branch(branch, opts, cb) on_stdout = function(_, data) found = found or data == branch end, - cwd = vim.loop.cwd(), + cwd = uv.cwd(), } -- TODO: I really don't want status's spread everywhere... seems bad @@ -166,7 +167,7 @@ function M.create_worktree_job(path, branch, found_branch, upstream, found_upstr return Job:new { command = worktree_add_cmd, args = worktree_add_args, - cwd = vim.loop.cwd(), + cwd = uv.cwd(), on_start = function() Log.debug(worktree_add_cmd .. ' ' .. table.concat(worktree_add_args, ' ')) end, @@ -187,7 +188,7 @@ function M.delete_worktree_job(path, force) return Job:new { command = worktree_del_cmd, args = worktree_del_args, - cwd = vim.loop.cwd(), + cwd = uv.cwd(), on_start = function() Log.debug(worktree_del_cmd .. ' ' .. table.concat(worktree_del_args, ' ')) end, diff --git a/lua/git-worktree/hooks.lua b/lua/git-worktree/hooks.lua index aaf934f..b942474 100644 --- a/lua/git-worktree/hooks.lua +++ b/lua/git-worktree/hooks.lua @@ -1,6 +1,7 @@ ---@mod git-worktree.hooks hooks local M = {} +local uv = vim.uv or vim.loop ---@enum git-worktree.hooks.type M.type = { @@ -68,7 +69,7 @@ M.builtins = { return end - local cwd = vim.loop.cwd() + local cwd = uv.cwd() local current_buf_name = vim.api.nvim_buf_get_name(0) if not current_buf_name or current_buf_name == '' then update_cmd() diff --git a/lua/git-worktree/test/system_util.lua b/lua/git-worktree/test/system_util.lua index 2a1e51a..d325f58 100644 --- a/lua/git-worktree/test/system_util.lua +++ b/lua/git-worktree/test/system_util.lua @@ -1,4 +1,5 @@ local M = {} +local uv = vim.uv or vim.loop ---Runs a system command and errors if it fails ---@param cmd string | table Command to be ran @@ -18,7 +19,7 @@ function M.run(cmd, ignore_err, error_msg) end local function is_macos() - return vim.loop.os_uname().sysname == 'Darwin' + return uv.os_uname().sysname == 'Darwin' end ---Create a temporary directory for use diff --git a/lua/git-worktree/worktree.lua b/lua/git-worktree/worktree.lua index aeb93c4..bd0554b 100644 --- a/lua/git-worktree/worktree.lua +++ b/lua/git-worktree/worktree.lua @@ -1,4 +1,5 @@ local Path = require('plenary.path') +local uv = vim.uv or vim.loop local Git = require('git-worktree.git') local Log = require('git-worktree.logger') @@ -9,7 +10,7 @@ local function get_absolute_path(path) if Path:new(path):is_absolute() then return path else - return Path:new(vim.loop.cwd(), path):absolute() + return Path:new(uv.cwd(), path):absolute() end end @@ -25,7 +26,7 @@ local function change_dirs(path) Log.info('changing dirs: %s ', path) local worktree_path = get_absolute_path(path) - local previous_worktree = vim.loop.cwd() + local previous_worktree = uv.cwd() Config = require('git-worktree.config') -- vim.loop.chdir(worktree_path) @@ -75,7 +76,7 @@ function M.switch(path) if path == nil then change_dirs(path) else - if path == vim.loop.cwd() then + if path == uv.cwd() then return end Git.has_worktree(path, nil, function(found) @@ -194,7 +195,7 @@ function M.delete(path, force, opts) opts.on_failure(e) end - failure(delete.cmd, vim.loop.cwd())(e) + failure(delete.cmd, uv.cwd())(e) end) Log.info('delete start job') delete:start() diff --git a/spec/worktree_spec.lua b/spec/worktree_spec.lua index 504ad5d..cad3876 100644 --- a/spec/worktree_spec.lua +++ b/spec/worktree_spec.lua @@ -1,6 +1,7 @@ local git_harness = require('git-worktree.test.git_util') local Hooks = require('git-worktree.hooks') local Path = require('plenary.path') +local uv = vim.uv or vim.loop local cwd = vim.fn.getcwd() @@ -51,7 +52,7 @@ describe('[Worktree]', function() return completed_switch end, 1000) - assert.are.same(expected_path, vim.loop.cwd()) + assert.are.same(expected_path, uv.cwd()) end) end) @@ -71,7 +72,7 @@ describe('[Worktree]', function() end, 1000) -- Check to make sure directory was switched - assert.are.same(expected_path, vim.loop.cwd()) + assert.are.same(expected_path, uv.cwd()) end) end) end) @@ -94,7 +95,7 @@ describe('[Worktree]', function() end, 1000) -- Check to make sure directory was switched - assert.are.same(expected_path, vim.loop.cwd()) + assert.are.same(expected_path, uv.cwd()) end) end) describe('[normal repo]', function() @@ -113,7 +114,7 @@ describe('[Worktree]', function() end, 1000) -- Check to make sure directory was switched - assert.are.same(expected_path, vim.loop.cwd()) + assert.are.same(expected_path, uv.cwd()) end) end) end) @@ -134,7 +135,7 @@ describe('[Worktree]', function() end, 1000) -- Check to make sure directory was switched - assert.are.same(master_dir, vim.loop.cwd()) + assert.are.same(master_dir, uv.cwd()) end) end) describe('[normal repo]', function() @@ -151,7 +152,7 @@ describe('[Worktree]', function() end, 1000) -- Check to make sure directory was switched - assert.are.same(master_dir, vim.loop.cwd()) + assert.are.same(master_dir, uv.cwd()) end) end) end)