Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lua/git-worktree/git.lua
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand All @@ -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()

Expand All @@ -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()
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lua/git-worktree/hooks.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion lua/git-worktree/test/system_util.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions lua/git-worktree/worktree.lua
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 7 additions & 6 deletions spec/worktree_spec.lua
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down