Skip to content

Commit

Permalink
Merge pull request #25 from ner0-m/feat/remote-url
Browse files Browse the repository at this point in the history
  • Loading branch information
petertriho authored Oct 31, 2021
2 parents ce7e4f2 + e8055ad commit 1d21a6b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
5 changes: 3 additions & 2 deletions lua/cmp_git/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local M = {
filetypes = { "gitcommit" },
remote = "origin",
git = {
commits = {
limit = 100,
Expand All @@ -16,8 +17,8 @@ local M = {
},
pull_requests = {
limit = 100,
state = "open" -- open, closed, merged, all
}
state = "open", -- open, closed, merged, all
},
},
gitlab = {
issues = {
Expand Down
8 changes: 2 additions & 6 deletions lua/cmp_git/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function Source:complete(params, callback)
trigger_character = params.completion_context.triggerCharacter
end

local git_info = utils.get_git_info(self.config.remote)

if trigger_character == ":" then
if not self.cache_commits[bufnr] then
if self.config.git and self.config.git.commits then
Expand All @@ -57,8 +59,6 @@ function Source:complete(params, callback)
end
elseif trigger_character == "#" then
if not self.cache_issues[bufnr] then
local git_info = utils.get_git_info()

if
self.config.github
and self.config.github.issues
Expand All @@ -84,8 +84,6 @@ function Source:complete(params, callback)
end
elseif trigger_character == "@" then
if not self.cache_mentions[bufnr] then
local git_info = utils.get_git_info()

if
self.config.github
and self.config.github.mentions
Expand All @@ -111,8 +109,6 @@ function Source:complete(params, callback)
end
elseif trigger_character == "!" then
if not self.cache_merge_requests[bufnr] then
local git_info = utils.get_git_info()

if
self.config.gitlab
and self.config.gitlab.mentions
Expand Down
9 changes: 4 additions & 5 deletions lua/cmp_git/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ M.url_encode = function(value)
return string.gsub(value, "([^%w _%%%-%.~])", char_to_hex)
end


M.get_git_info = function()
M.get_git_info = function(remote)
return M.run_in_cwd(M.get_cwd(), function()
local remote_origin_url = vim.fn.system("git config --get remote.origin.url")
local remote_origin_url = vim.fn.system("git config --get remote." .. remote .. ".url")
local clean_remote_origin_url = remote_origin_url:gsub("%.git", ""):gsub("%s", "")

local host, owner, repo = string.match(clean_remote_origin_url, "^git@(.+):(.+)/(.+)$")
Expand All @@ -38,8 +37,8 @@ M.run_in_cwd = function(cwd, callback)
end

M.get_cwd = function()
if vim.fn.getreg('%') ~= '' then
return vim.fn.expand('%:p:h')
if vim.fn.getreg("%") ~= "" then
return vim.fn.expand("%:p:h")
end
return vim.fn.getcwd()
end
Expand Down

0 comments on commit 1d21a6b

Please sign in to comment.