Skip to content

Commit

Permalink
Merge pull request #37 from b0o/git-remote-url
Browse files Browse the repository at this point in the history
  • Loading branch information
petertriho authored Mar 18, 2022
2 parents 4b2e57b + c8a9fc4 commit 6898983
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ require("cmp_git").setup({
-- defaults
filetypes = { "gitcommit" },
remotes = { "upstream", "origin" }, -- in order of most to least prioritized
enableRemoteUrlRewrites = false, -- enable git url rewrites, see https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf
git = {
commits = {
sort_by = function(commit) -- nil, "sha", "title", "description", "author_name", "author_email", "commit_timestamp", or custom function
Expand Down
1 change: 1 addition & 0 deletions lua/cmp_git/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local utils = require("cmp_git.utils")
local M = {
filetypes = { "gitcommit" },
remotes = { "upstream", "origin" }, -- in order of most to least prioritized
enableRemoteUrlRewrites = false, -- enable git url rewrites, see https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf
git = {
commits = {
limit = 100,
Expand Down
5 changes: 4 additions & 1 deletion lua/cmp_git/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ function Source:complete(params, callback)

for _, trigger in pairs(self.trigger_actions) do
if trigger.trigger_character == trigger_character then
local git_info = utils.get_git_info(self.config.remotes)
local git_info = utils.get_git_info(
self.config.remotes,
{ enableRemoteUrlRewrites = self.config.enableRemoteUrlRewrites }
)

if trigger.action(self.sources, trigger_character, callback, params, git_info) then
break
Expand Down
11 changes: 9 additions & 2 deletions lua/cmp_git/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ M.parse_github_date = function(d)
})
end

M.get_git_info = function(remotes)
M.get_git_info = function(remotes, opts)
opts = opts or {}
return M.run_in_cwd(M.get_cwd(), function()
if type(remotes) == "string" then
remotes = { remotes }
Expand All @@ -51,7 +52,13 @@ M.get_git_info = function(remotes)
local host, owner, repo = nil, nil, nil

for _, r in ipairs(remotes) do
local remote_origin_url = vim.fn.system("git config --get remote." .. r .. ".url")
local cmd
if opts.enableRemoteUrlRewrites then
cmd = "git remote get-url " .. r
else
cmd = "git config --get remote." .. r .. ".url"
end
local remote_origin_url = vim.fn.system(cmd)

if remote_origin_url ~= "" then
local clean_remote_origin_url = remote_origin_url:gsub("%.git", ""):gsub("%s", "")
Expand Down

0 comments on commit 6898983

Please sign in to comment.