{"id":13681666,"url":"https://github.com/petertriho/cmp-git","last_synced_at":"2025-04-30T06:31:36.844Z","repository":{"id":38829210,"uuid":"420577743","full_name":"petertriho/cmp-git","owner":"petertriho","description":"Git source for nvim-cmp","archived":false,"fork":false,"pushed_at":"2024-04-15T10:44:47.000Z","size":100,"stargazers_count":333,"open_issues_count":13,"forks_count":20,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-04-22T15:21:11.057Z","etag":null,"topics":["lua","neovim","neovim-lua-plugin","neovim-plugin","nvim-cmp","plugin"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/petertriho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-24T03:29:23.000Z","updated_at":"2024-05-28T12:20:15.097Z","dependencies_parsed_at":"2024-05-28T12:30:10.095Z","dependency_job_id":null,"html_url":"https://github.com/petertriho/cmp-git","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petertriho%2Fcmp-git","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petertriho%2Fcmp-git/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petertriho%2Fcmp-git/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petertriho%2Fcmp-git/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petertriho","download_url":"https://codeload.github.com/petertriho/cmp-git/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224201713,"owners_count":17272625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua","neovim","neovim-lua-plugin","neovim-plugin","nvim-cmp","plugin"],"created_at":"2024-08-02T13:01:34.024Z","updated_at":"2024-11-12T01:30:24.995Z","avatar_url":"https://github.com/petertriho.png","language":"Lua","readme":"# cmp-git\n\nGit source for [hrsh7th/nvim-cmp](https://github.com/hrsh7th/nvim-cmp)\n\n## Features\n\n| Git     | Trigger |\n| ------- | ------- |\n| Commits | :       |\n\n| GitHub                 | Trigger |\n| ---------------------- | ------- |\n| Issues                 | #       |\n| Mentions (`curl` only) | @       |\n| Pull Requests          | #       |\n\n| GitLab         | Trigger |\n| -------------- | ------- |\n| Issues         | #       |\n| Mentions       | @       |\n| Merge Requests | !       |\n\n## Requirements\n\n- Neovim \u003e= 0.5.1\n- git\n- curl\n- [GitHub CLI](https://cli.github.com/) (optional, will use curl instead if not avaliable)\n- [GitLab CLI](https://gitlab.com/gitlab-org/cli) (optional, will use curl instead if not avaliable)\n\n### GitHub Private Repositories\n\n- `curl`: Generate [token](https://github.com/settings/tokens)\n  with `repo` scope. Set `GITHUB_API_TOKEN` environment variable.\n- `GitHub CLI`: Run [gh auth login](https://cli.github.com/manual/gh_auth_login)\n\n### GitLab Private Repositories\n\n- `curl` Generate [token](https://gitlab.com/-/profile/personal_access_tokens)\n  with `api` scope. Set `GITLAB_TOKEN` environment variable.\n- `GitLab CLI`: Run [glab auth login](https://glab.readthedocs.io/en/latest/auth/login.html)\n\n## Installation\n\n[vim-plug](https://github.com/junegunn/vim-plug)\n\n```vim\nPlug 'nvim-lua/plenary.nvim'\nPlug 'petertriho/cmp-git'\n```\n\n[packer.nvim](https://github.com/wbthomason/packer.nvim)\n\n```lua\nuse({\"petertriho/cmp-git\", requires = \"nvim-lua/plenary.nvim\"})\n```\n\n[lazy.nvim](https://github.com/folke/lazy.nvim)\n\n```lua\nreturn {\n    \"petertriho/cmp-git\",\n    dependencies = { 'hrsh7th/nvim-cmp' },\n    opts = {\n        -- options go here\n    },\n    init = function()\n        table.insert(require(\"cmp\").get_config().sources, { name = \"git\" })\n    end\n}\n```\n\n## Setup\n\n```lua\nrequire(\"cmp\").setup({\n    sources = {\n        { name = \"git\" },\n        -- more sources\n    }\n})\n\nrequire(\"cmp_git\").setup()\n```\n\n## Config\n\n```lua\nlocal format = require(\"cmp_git.format\")\nlocal sort = require(\"cmp_git.sort\")\n\nrequire(\"cmp_git\").setup({\n    -- defaults\n    filetypes = { \"gitcommit\", \"octo\", \"NeogitCommitMessage\" },\n    remotes = { \"upstream\", \"origin\" }, -- in order of most to least prioritized\n    enableRemoteUrlRewrites = false, -- enable git url rewrites, see https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf\n    git = {\n        commits = {\n            limit = 100,\n            sort_by = sort.git.commits,\n            format = format.git.commits,\n            sha_length = 7,\n        },\n    },\n    github = {\n        hosts = {},  -- list of private instances of github\n        issues = {\n            fields = { \"title\", \"number\", \"body\", \"updatedAt\", \"state\" },\n            filter = \"all\", -- assigned, created, mentioned, subscribed, all, repos\n            limit = 100,\n            state = \"open\", -- open, closed, all\n            sort_by = sort.github.issues,\n            format = format.github.issues,\n        },\n        mentions = {\n            limit = 100,\n            sort_by = sort.github.mentions,\n            format = format.github.mentions,\n        },\n        pull_requests = {\n            fields = { \"title\", \"number\", \"body\", \"updatedAt\", \"state\" },\n            limit = 100,\n            state = \"open\", -- open, closed, merged, all\n            sort_by = sort.github.pull_requests,\n            format = format.github.pull_requests,\n        },\n    },\n    gitlab = {\n        hosts = {},  -- list of private instances of gitlab\n        issues = {\n            limit = 100,\n            state = \"opened\", -- opened, closed, all\n            sort_by = sort.gitlab.issues,\n            format = format.gitlab.issues,\n        },\n        mentions = {\n            limit = 100,\n            sort_by = sort.gitlab.mentions,\n            format = format.gitlab.mentions,\n        },\n        merge_requests = {\n            limit = 100,\n            state = \"opened\", -- opened, closed, locked, merged\n            sort_by = sort.gitlab.merge_requests,\n            format = format.gitlab.merge_requests,\n        },\n    },\n    trigger_actions = {\n        {\n            debug_name = \"git_commits\",\n            trigger_character = \":\",\n            action = function(sources, trigger_char, callback, params, git_info)\n                return sources.git:get_commits(callback, params, trigger_char)\n            end,\n        },\n        {\n            debug_name = \"gitlab_issues\",\n            trigger_character = \"#\",\n            action = function(sources, trigger_char, callback, params, git_info)\n                return sources.gitlab:get_issues(callback, git_info, trigger_char)\n            end,\n        },\n        {\n            debug_name = \"gitlab_mentions\",\n            trigger_character = \"@\",\n            action = function(sources, trigger_char, callback, params, git_info)\n                return sources.gitlab:get_mentions(callback, git_info, trigger_char)\n            end,\n        },\n        {\n            debug_name = \"gitlab_mrs\",\n            trigger_character = \"!\",\n            action = function(sources, trigger_char, callback, params, git_info)\n                return sources.gitlab:get_merge_requests(callback, git_info, trigger_char)\n            end,\n        },\n        {\n            debug_name = \"github_issues_and_pr\",\n            trigger_character = \"#\",\n            action = function(sources, trigger_char, callback, params, git_info)\n                return sources.github:get_issues_and_prs(callback, git_info, trigger_char)\n            end,\n        },\n        {\n            debug_name = \"github_mentions\",\n            trigger_character = \"@\",\n            action = function(sources, trigger_char, callback, params, git_info)\n                return sources.github:get_mentions(callback, git_info, trigger_char)\n            end,\n        },\n    },\n  }\n)\n```\n\n---\n\n**NOTE**\n\nIf you want specific behaviour for a trigger or new behaviour for a trigger, you need to add\nan entry in the `trigger_actions` table of the config. The two necessary fields are the `trigger_character`\nand the `action`.\n\nCurrently, `trigger_character` has to be a single character. Multiple actions can be used for the same character.\nAll actions are triggered until one returns true. The parameters to the `actions` function are the\ndifferent sources (currently `git`, `gitlab` and `github`), the completion callback, the trigger character,\nthe parameters passed to `complete` from `nvim-cmp`, and the current git info.\n\nAll source functions take an optional config table as last argument, with which the configuration set\nin `setup` can be overwritten for a specific call.\n\n**NOTE on sorting**\n\nThe default sorting order is last updated (for PRs, MRs and issues) and latest (for commits).\nTo make `nvim-cmp` sort in this order, move `cmp.config.compare.sort_text` closer to the top of (lower index) in `sorting.comparators`. E.g.\n\n```lua\nrequire(\"cmp\").setup({\n    -- As above\n    sorting = {\n        comparators = {\n            cmp.config.compare.offset,\n            cmp.config.compare.exact,\n            cmp.config.compare.sort_text,\n            cmp.config.compare.score,\n            cmp.config.compare.recently_used,\n            cmp.config.compare.kind,\n            cmp.config.compare.length,\n            cmp.config.compare.order,\n        },\n    },\n})\n```\n\n### Working with hosted instances of GitHub or GitLab\n\nYou can add hosted instances of Github Enterprise or GitLab to the corresponding `hosts` list as such:\n```lua\nrequire(\"cmp_git\").setup({\n    github = {\n        hosts = { \"github.mycompany.com\", },\n    },\n    gitlab = {\n        hosts = { \"gitlab.mycompany.com\", }\n    }\n}\n```\n\n---\n\n## Acknowledgements\n\nSpecial thanks to [tjdevries](https://github.com/tjdevries) for their informative video and starting code.\n\n- [TakeTuesday E01: nvim-cmp](https://www.youtube.com/watch?v=_DnmphIwnjo)\n- [tjdevries/config_manager](https://github.com/tjdevries/config_manager)\n\n## Alternatives\n\n- [neoclide/coc-git](https://github.com/neoclide/coc-git)\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","funding_links":[],"categories":["Completion","Lua"],"sub_categories":["Diagnostics"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetertriho%2Fcmp-git","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetertriho%2Fcmp-git","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetertriho%2Fcmp-git/lists"}