Closed gibfahn closed 2 years ago
I'm not convinced this should be changed. A possible alternative workflow would be to start with everything closed, press i
to cycle through changes (which expands diffs automatically), and press s
on the hunks you want to stage.
A possible alternative workflow would be to start with everything closed, press i to cycle through changes (which expands diffs automatically), and press s on the hunks you want to stage.
The expanding diffs automatically is nice, but this doesn't really make things any easier. Previously to stage the 4 hunks in the above example (cursor starting in the first hunk) it would be ssjs
, and with i
it's ssis
.
Using i
and s
isn't so bad when you're just picking out a few diffs to stage out of a bunch of unconnected changes (when you're mostly not staging things). It's much more painful though when you're staging ~everything, and just using this as a point to do some code review on your changes before submitting.
As I mentioned above though, it's not so much the extra keystrokes as having to constantly remember to check whether the cursor is on a file or a hunk, which distracts from the focus on the code itself.
It looks like this mapping works as a workaround:
" Stage, go up a line, then skip to the next hunk.
:nmap S sk]c
Versions
Background
When staging, I'm either staging by file or by hunk. When staging by file, I'm giving each file a quick look then staging the whole thing. When staging by hunk, I'm carefully reading each diff.
When you stage a hunk, fugitive automatically puts the cursor on the hunk marker (
@@ -1,9 +1,9 @@
) for the next hunk, which is great as it lets you taps
repeatedly to go through the open hunks.However, when you stage the last hunk in a file, fugitive puts the cursor on the next file marker (e.g.
M README.markdown
) instead of the first hunk marker in that file. This means you have to constantly be checkingWorked Example
Screenshot:
Unstaged (2)
and hit=
to expand the hunksScreenshot:
@@ -1,3 +1,4 @@
, and hits
to stage the first hunkScreenshot:
s
again to stage that one too.Screenshot:
M README.markdown
, so hittings
a third time would stage all changes in that file, but we just want to stage hunk-wise. Therefore we have to move one line down to stage only the next (firstR
) hunk rather than everything in this file.Screenshot: