Skip to content

Commit

Permalink
feat(actions): true partial hunk staging
Browse files Browse the repository at this point in the history
Resolves #338
  • Loading branch information
lewis6991 committed Dec 4, 2021
1 parent 0ffa5a0 commit f362e54
Show file tree
Hide file tree
Showing 14 changed files with 442 additions and 197 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Stage/reset all hunks in buffer | :white_check_mark:
Undo staged hunks | :white_check_mark: | |
Word diff in buffer | :white_check_mark: | |
Word diff in hunk preview | :white_check_mark: | :white_check_mark: |
Stage partial hunks | | :white_check_mark: |
Stage partial hunks | :white_check_mark: | |
Hunk text object | :white_check_mark: | :white_check_mark: |
Diff against index or any commit | :white_check_mark: | :white_check_mark: |
Folding of unchanged text | | :white_check_mark: |
Expand Down
21 changes: 13 additions & 8 deletions doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ prev_hunk({opts}) *gitsigns.prev_hunk()*
See |gitsigns.next_hunk()|.

stage_hunk({range}) *gitsigns.stage_hunk()*
Stage the hunk at the cursor position, or all hunks in the
given range. If {range} is provided, all hunks that intersect
with the given range are staged.
Stage the hunk at the cursor position, or all lines in the
given range. If {range} is provided, all lines in the given
range are staged. This supports partial-hunks, meaning if a
range only includes a portion of a particular hunk, only the
lines within the range will be staged.

Attributes: ~
{async}
Expand All @@ -144,8 +146,10 @@ stage_hunk({range}) *gitsigns.stage_hunk()*
up the line range from which you want to stage the hunks.

undo_stage_hunk() *gitsigns.undo_stage_hunk()*
Undo the last call of stage_hunk(). Note: only the calls to
stage_hunk() performed in the current session can be undone.
Undo the last call of stage_hunk().

Note: only the calls to stage_hunk() performed in the current
session can be undone.

Attributes: ~
{async}
Expand All @@ -166,9 +170,10 @@ reset_buffer_index() *gitsigns.reset_buffer_index()*

reset_hunk({range}) *gitsigns.reset_hunk()*
Reset the lines of the hunk at the cursor position, or all
hunks in the given range, to what it is in Git's index. If
{range} is provided, all hunks that intersect with the given
range are reset.
lines in the given range. If {range} is provided, all lines in
the given range are reset. This supports partial-hunks,
meaning if a range only includes a portion of a particular
hunk, only the lines within the range will be reset.

Parameters:~
{range} table|nil List-like table of two integers making
Expand Down
6 changes: 3 additions & 3 deletions lua/gitsigns.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 41 additions & 50 deletions lua/gitsigns/actions.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions lua/gitsigns/diff_int.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions lua/gitsigns/hunks.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions teal/gitsigns.tl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ local record M
-- Internal, API unstable
_update_highlights : function()
_update_cwd_head : function()
_run_func : function(range: {integer, integer}, func: string, ...: any)
_run_func : function(range: {integer, integer, integer}, func: string, ...: any)
_complete : function(arglead: string, line: string): {string}
_attach_enable : function()
_attach_disable : function()
Expand Down Expand Up @@ -387,15 +387,15 @@ local function parse_args_to_lua(...: string): {any}
return args
end

M._run_func = function(range: {integer, integer}, func: string, ...: string)
M._run_func = function(range: {integer, integer, integer}, func: string, ...: string)
local actions = require('gitsigns.actions')
local actions0 = actions as {string:function}

local args = parse_args_to_lua(...)

if type(actions0[func]) == 'function' then
if range and range[1] ~= range[2] then
actions.user_range = range
if range and range[1] > 0 then
actions.user_range = {range[2], range[3]}
else
actions.user_range = nil
end
Expand Down Expand Up @@ -439,7 +439,7 @@ local function setup_command()
'-nargs=+',
'-complete=customlist,v:lua.package.loaded.gitsigns._complete',
'Gitsigns',
'lua require("gitsigns")._run_func({<line1>, <line2>}, <f-args>)'
'lua require("gitsigns")._run_func({<range>, <line1>, <line2>}, <f-args>)'
}, ' '))
end

Expand Down
Loading

0 comments on commit f362e54

Please sign in to comment.