Skip to content
Merged
Changes from 2 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
10 changes: 7 additions & 3 deletions lua/gitlab/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local M = {}
---@param command table
---@return string|nil, string|nil
local run_system = function(command)
-- Load here to prevent loop
local u = require("gitlab.utils")
local result = vim.fn.trim(vim.fn.system(command))
if vim.v.shell_error ~= 0 then
Expand All @@ -16,9 +17,12 @@ local run_system = function(command)
end

---Returns all branches for the current repository
---@param args table|nil extra arguments for `git branch`
---@return string|nil, string|nil
M.branches = function()
return run_system({ "git", "branch" })
M.branches = function(args)
-- Load here to prevent loop
local u = require("gitlab.utils")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it is worth adding a require_on_index implementation to gitlab.nvim, as I am not sure how often this is actually an issue (require loops). But this can also be solved by adding something like:

M.require_on_index = function(require_path)
  return setmetatable({}, {
    __index = function(_, key)
      return require(require_path)[key]
    end,

    __newindex = function(_, key, value)
      require(require_path)[key] = value
    end,
  })
end

and then doing:

local u = require("gitlab.util.lazy").require_on_index("gitlab.utils")

And since it is not required until it is used, you do not run into the same require looping stuff that causes this to be necessary.

return run_system(u.combine({ "git", "branch" }, args or {}))
end

---Checks whether the tree has any changes that haven't been pushed to the remote
Expand Down Expand Up @@ -60,7 +64,7 @@ end
---Return the list of names of all remote-tracking branches or an empty list.
---@return table, string|nil
M.get_all_remote_branches = function()
local all_branches, err = M.branches()
local all_branches, err = M.branches({ "--remotes" })
if err ~= nil then
return {}, err
end
Expand Down