Skip to content

Commit

Permalink
refactor!: re-design implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvirtin committed Dec 6, 2021
1 parent e51a244 commit bfca98e
Show file tree
Hide file tree
Showing 152 changed files with 8,033 additions and 7,298 deletions.
157 changes: 8 additions & 149 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
- See changes in your project in a quickfix list (`:VGit project_hunks_qf`)
- Enhance your workflow by using VGit's buffer navigation `:VGit hunk_up` and `:VGit hunk_down` that can be used on any VGit previews with changes.

If you have Telescope feel free to run `:VGit actions` to quickly checkout your execution options.
<br />
<br />
<img src="https://user-images.githubusercontent.com/25164326/135162562-648a3b64-e403-439f-b4fc-6bc7fc7ddcd0.PNG" alt="commands"/>

## Supported Neovim Versions:
- Neovim **>=** 0.5

Expand Down Expand Up @@ -91,170 +86,34 @@ require('vgit').setup()
EOF
```

## Themes
Predefined supported themes:
- [tokyonight](https://github.com/folke/tokyonight.nvim)
- [monokai](https://github.com/tanvirtin/monokai.nvim)

Colorscheme definitions can be found in `lua/vgit/themes/`, feel free to open a pull request with your own colorscheme!

## Layouts
Predefined supported layouts:
- default (Full screen previews)

Layout definitions can be found in `lua/vgit/layouts/`, feel free to open a pull request with your own layout!

## API
| Function Name | Description |
|---------------|-------------|
| setup | Sets up the plugin for success |
| toggle_buffer_hunks | Shows hunk signs on buffers/Hides hunk signs on buffers |
| toggle_buffer_blames | Enables blames feature on buffers/Disables blames feature on buffers |
| toggle_buffer_blames | Enables/disables showing live blames on buffers |
| toggle_diff_preference | Switches between "horizontal" and "vertical" layout for previews |
| toggle_debug | Enables/disables tracing of the plugin using logs |
| buffer_stage | Stages a buffer you are currently on |
| buffer_unstage | Unstages a buffer you are currently on |
| buffer_diff_preview | Opens a diff preview of the changes in the current buffer |
| buffer_staged_diff_preview | Shows staged changes in a preview window |
| buffer_hunk_preview | Gives you a view through which you can navigate and see the current hunk or other hunks |
| buffer_history_preview | Opens a buffer preview along with a table of logs, enabling users to see different iterations of the buffer in the git history |
| buffer_blame_preview | Opens a preview detailing the blame of the line that the user is currently on |
| buffer_gutter_blame_preview | Opens a preview which shows the blames related to all the lines of a buffer |
| buffer_staged_hunk_preview | Gives you a view through which you can navigate and see the current staged hunk or other staged hunks |
| buffer_history_preview | Opens a buffer preview along with a table of logs, enabling users to see different iterations of the buffer in the git history | TODO
| buffer_blame_preview | Opens a preview detailing the blame of the line that the user is currently on | TODO
| buffer_gutter_blame_preview | Opens a preview which shows the blames related to all the lines of a buffer | TODO
| buffer_reset | Resets the current buffer to HEAD |
| buffer_hunk_stage | Stages a hunk, if cursor is over it |
| buffer_hunk_reset | Removes the hunk from the buffer, if cursor is over it |
| project_hunks_qf | Opens a populated quickfix window with all the hunks of the project |
| project_diff_preview | Opens a preview listing all the files that have been changed |
| project_diff_preview | Opens a preview listing all the files that have been changed | TODO
| hunk_down | Navigate downward through a hunk, this works on any view with diff highlights |
| hunk_up | Navigate upwards through a hunk, this works on any view with diff highlights |
| get_diff_base | Returns the current diff base that all diff and hunks are being compared for all buffers |
| get_diff_preference | Returns the current diff preference of the diff, the value will either be "horizontal" or "vertical" |
| get_diff_strategy | Returns the current diff strategy used to compute hunk signs and buffer preview, the value will either be "remote" or "index" |
| set_diff_base | Sets the current diff base to a different commit, going forward all future hunks and diffs for a given buffer will be against this commit |
| set_diff_strategy | Sets the diff strategy that will be used to show hunk signs and buffer preview, the value can only be "remote" or "index" |
| show_debug_logs | Shows all errors that has occured during program execution |

## Advanced Setup
```lua
local vgit = require('vgit')
local utils = require('vgit.utils')

vgit.setup({
debug = false, -- Only enable this to trace issues related to the app,
keymaps = {
['n <C-k>'] = 'hunk_up',
['n <C-j>'] = 'hunk_down',
['n <leader>g'] = 'actions',
['n <leader>gs'] = 'buffer_hunk_stage',
['n <leader>gr'] = 'buffer_hunk_reset',
['n <leader>gp'] = 'buffer_hunk_preview',
['n <leader>gb'] = 'buffer_blame_preview',
['n <leader>gf'] = 'buffer_diff_preview',
['n <leader>gh'] = 'buffer_history_preview',
['n <leader>gu'] = 'buffer_reset',
['n <leader>gg'] = 'buffer_gutter_blame_preview',
['n <leader>gd'] = 'project_diff_preview',
['n <leader>gq'] = 'project',
['n <leader>gx'] = 'toggle_diff_preference',
},
controller = {
hunks_enabled = true,
blames_enabled = true,
diff_strategy = 'index',
diff_preference = 'horizontal',
predict_hunk_signs = true,
predict_hunk_throttle_ms = 300,
predict_hunk_max_lines = 50000,
blame_line_throttle_ms = 150,
action_delay_ms = 300,
},
hls = vgit.themes.tokyonight,
sign = {
VGitViewSignAdd = {
name = 'DiffAdd',
line_hl = 'DiffAdd',
text_hl = nil,
num_hl = nil,
icon = nil,
text = '',
},
VGitViewSignRemove = {
name = 'DiffDelete',
line_hl = 'DiffDelete',
text_hl = nil,
num_hl = nil,
icon = nil,
text = '',
},
VGitSignAdd = {
name = 'VGitSignAdd',
text_hl = 'VGitSignAdd',
num_hl = nil,
icon = nil,
line_hl = nil,
text = '',
},
VGitSignRemove = {
name = 'VGitSignRemove',
text_hl = 'VGitSignRemove',
num_hl = nil,
icon = nil,
line_hl = nil,
text = '',
},
VGitSignChange = {
name = 'VGitSignChange',
text_hl = 'VGitSignChange',
num_hl = nil,
icon = nil,
line_hl = nil,
text = '',
},
},
render = {
layout = vgit.layouts.default,
sign = {
priority = 10,
hls = {
add = 'VGitSignAdd',
remove = 'VGitSignRemove',
change = 'VGitSignChange',
},
},
line_blame = {
hl = 'Comment',
format = function(blame, git_config)
local config_author = git_config['user.name']
local author = blame.author
if config_author == author then
author = 'You'
end
local time = os.difftime(os.time(), blame.author_time) / (24 * 60 * 60)
local time_format = string.format('%s days ago', utils.round(time))
local time_divisions = { { 24, 'hours' }, { 60, 'minutes' }, { 60, 'seconds' } }
local division_counter = 1
while time < 1 and division_counter ~= #time_divisions do
local division = time_divisions[division_counter]
time = time * division[1]
time_format = string.format('%s %s ago', utils.round(time), division[2])
division_counter = division_counter + 1
end
local commit_message = blame.commit_message
if not blame.committed then
author = 'You'
commit_message = 'Uncommitted changes'
local info = string.format('%s • %s', author, commit_message)
return string.format(' %s', info)
end
local max_commit_message_length = 255
if #commit_message > max_commit_message_length then
commit_message = commit_message:sub(1, max_commit_message_length) .. '...'
end
local info = string.format('%s, %s • %s', author, time_format, commit_message)
return string.format(' %s', info)
end,
},
},
})
vgit.setup({})
```


Loading

0 comments on commit bfca98e

Please sign in to comment.