dgutov / diff-hl

Emacs package for highlighting uncommitted changes
GNU General Public License v3.0
914 stars 44 forks source link

diff-hl-show-hunk-next tell "There is no next change", but, `diff-hl-next-hunk` can jump to it. #175

Open zw963 opened 2 years ago

zw963 commented 2 years ago

I don't know which command is work correct, but if one work correct, i guess another one must be incorrect.

Following is a reproduce:

  1. we assume a Gemfile exists some different. image

  2. restart emacs as daemon, and open Gemfile use emacs client

  3. switch to beginning of buffer.

  4. Both C-x v ] and C-x v } can jump to the difference as expect.

  5. run git add Gemfie on command line

  6. C-x v ] can jump, but C-x v } not jump, message: There is no next change Question 1: which command is correct?

When i set (setq diff-hl-show-staged-changes nil), not jump is correct, right?

  1. run git reset on command line

  2. behavior same as 6, in this case, jump is correct, right?

I assume diff-hl check the git operation from command line is not so easy, e.g. when i do staging from command line successful, i still see the fringe indicate exists diff on this line.

image

image

though, that maybe another issue,

but, this issue focus on above two command should not behavior different in this case.

Thank you.

dgutov commented 2 years ago

Hi!

I can reproduce this, I think. Though I think the actual scenario is a little more complicated: you first have to have tested with (setq diff-hl-show-staged-changes nil), and then with (setq diff-hl-show-staged-changes t) again.

Does the below help, or are we talking about different scenarios?

diff --git a/diff-hl-show-hunk.el b/diff-hl-show-hunk.el
index 00f6d92..42c3523 100644
--- a/diff-hl-show-hunk.el
+++ b/diff-hl-show-hunk.el
@@ -342,7 +342,9 @@ end of the OVERLAY, so posframe/inline is placed below the hunk."
 (defun diff-hl-show-hunk-next ()
   "Go to next hunk/change and show it."
   (interactive)
-  (let* ((point (if diff-hl-show-hunk--original-overlay
+  (let* ((point (if (and
+                     diff-hl-show-hunk--original-buffer
+                     diff-hl-show-hunk--original-overlay)
                     (overlay-start diff-hl-show-hunk--original-overlay)
                   nil))
          (next-overlay (diff-hl-show-hunk--next-hunk nil point)))

If it does not, or if the fix doesn't seem enough for you, what if after step 5 you refresh the highlightings with M-x revert-buffer? Does the next step look consistent to you?

zw963 commented 2 years ago

Does the below help, or are we talking about different scenarios?

Yes, i consider behavior is almost same for now, though, there still exists some issue, will describe later.

After run git add diff-hl.el successful, and jump to beginning-of-buffer.

  1. when i run C-x v ], cursor jump to line 181, like this. image

Or

  1. when i run C-x v }, cursor jump to line 191, and we can see "no next hunk` on minibuffer. image

So, i thought we have two issue:

  1. C-x v ] is jump to line 181, C-x v } jump to line 191, they use different logic i guess, that not good. (this is consider as a new issue) ?

  2. C-x v ] can be jump continuously with ] when enable repeat mode, C-x v } do it same way for now, but, with a "no next hunk" error message, but can jump continuously anyway.

zw963 commented 2 years ago

This issue still exists, simply to say, current git status is modifed status:

## master
 M deploy_start.sh

C+v] can jump to next hunk, but (diff-hl-show-hunk-next) can not.