lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
4.87k stars 186 forks source link

Feature Request: Unstage Changes on Current Line #1051

Closed hsayed21 closed 2 months ago

hsayed21 commented 2 months ago

Description

Description

I would like to request a feature that allows users to unstage changes on the current line where the cursor is focused. This functionality would complement the existing stage_hunk, reset_hunk, and undo_stage_hunk functions by providing more granular control over staging and unstaging changes.

Proposed Solution

A new function, unstage_hunk, could be introduced with the following behavior:

Thank you for considering this feature request. I believe it would be a valuable addition to the gitsigns.nvim plugin, enhancing its utility and user experience.

Neovim version

_

Operating system and version

_

Expected behavior

_

Actual behavior

_

Minimal config

_

Steps to reproduce

_

Gitsigns debug messages

_

lewis6991 commented 2 months ago

This is already possible with stage_hunk which toggles the stage status.

hsayed21 commented 2 months ago

I tried it nothing changed in two modes normal or visual

_map("n", "<leader>gs", gs.stage_hunk, "Stage hunk")
_map("v", "<leader>gs", function() gs.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) end, "Stage hunk")
hsayed21 commented 2 months ago

https://github.com/lewis6991/gitsigns.nvim/assets/47378309/0d58fd7b-67bd-4f85-904a-7bbd6497c15a

lewis6991 commented 2 months ago

You need to pull in the latest changes to include https://github.com/lewis6991/gitsigns.nvim/commit/b8cf5e8efaa0036d493a2e2dfed768c3a03fac73

hsayed21 commented 2 months ago

Sorry, but I don't understand what I should do. Do you mean I need to update the plugin?

lewis6991 commented 2 months ago

Yes. Make sure to always have the latest version installed before raising issues on a tracker.

hsayed21 commented 2 months ago

Sorry for not paying attention. I did the update and it worked, but there's a problem in visual mode where 'unstage' doesn't work

xzbdmw commented 1 month ago

Yeah unstage does not work in visual mode

                map("v", "<leader>sh", function()
                    gs.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
                end)

Look at the code, if range is specified the staged hunk does not really caculated, it simply using current line https://github.com/lewis6991/gitsigns.nvim/blob/39b5b6f48bde0595ce68007ffce408c5d7ac1f79/lua/gitsigns/actions.lua#L242 @lewis6991 this should be reopen?

lewis6991 commented 1 month ago

@lewis6991 this should be reopen?

That won't fix it. A PR might.