Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seems to break staging by hunks #22

Open
vermiculus opened this issue Dec 28, 2021 · 12 comments
Open

Seems to break staging by hunks #22

vermiculus opened this issue Dec 28, 2021 · 12 comments

Comments

@vermiculus
Copy link

When I have magit-delta-mode enabled, I can't seem to stage individual hunks:

image

  1 git … apply --reverse -p0 --ignore-space-change -
error: patch failed: init-custom.el:30
error: init-custom.el: patch does not apply

This seem related to #13 and #18, but I don't have line numbers enabled.

@dandavison
Copy link
Owner

Hi @vermiculus, let's get to the bottom of this. Staging by hunks does work in general (is working for me; wasn't aware of others having problems before this). Can you post your magit-delta config, and the [delta] section from your ~/.gitconfig?

@vermiculus
Copy link
Author

I will check my personal computer when I get home, but I had just installed delta to try this out, so I don't think I have any config unless installation itself created it.

My magit-delta configuration is only what you see in the the use-package form in the screenshot.

@vermiculus
Copy link
Author

git config --list --show-origin | grep delta yields nothing.

@dandavison
Copy link
Owner

@vermiculus would you be able to do a little experiment? I'm thinking, let's capture the args and input that git is receiving so we can see what is wrong with the patch. So instructions would be

  1. Create a file at /tmp/fake-git containing this:

    #!/bin/bash
    OUTFILE=/tmp/git-input
    echo "$@" >>$OUTFILE
    tee -a $OUTFILE | git $@
    echo -------------------------------------------------------------------------- >>$OUTFILE
    
  2. chmod +x /tmp/fake-git

  3. (setq magit-git-executable "/tmp/fake-git")

Now stage a hunk in magit and look in /tmp/git-input. We should be able to see the arguments, and the patch, that git received (along with various other git arguments). In my case while testing I can see this:

--no-pager --literal-pathspecs -c core.preloadindex=true -c log.showSignature=false -c color.ui=false -c color.diff=false apply --cached -p0 --ignore-space-change -
diff --git src/delta.rs src/delta.rs
index 7fbcdf4..0540103 100644
--- src/delta.rs
+++ src/delta.rs
@@ -268,3 +268,4 @@ fn detect_source(line: &str) -> Source {
         Source::Unknown
     }
 }
+hello

Could you post the args and patch that are written to that file when magit reports that the patch failed?

@dandavison
Copy link
Owner

Also, just to check -- is delta working correctly outside magit?

Is it just staging individual hunks that is problematic, or are there any other problems when using magit-delta?

@vermiculus
Copy link
Author

To be fair, I haven't used delta outside of magit-delta :-) but the diff-washing was visually working fine (at least, as I'd expect without prior experience with delta) from within magit.

Staging individual hunks was the only problem I noticed.

@ErnestDong
Copy link

I encountered this when I set line-numbers = true in delta

@dandavison
Copy link
Owner

@vermiculus this problem seems to be specific to your environment. What would be really helpful is if you could capture the patch that is being sent to git:

error: init-custom.el: patch does not apply

I think if we could see that, we'd see what is going wrong. I've put instructions for capturing the patch above: #22 (comment)

@g5pw
Copy link

g5pw commented Jul 11, 2022

I have the same situation, and have line-numbers = true in my config. If I set it to false, everything works.

@dandavison
Copy link
Owner

dandavison commented Jul 11, 2022

Hi @g5pw, that's right: line-numbers cannot be used with magit-delta since it creates invalid patches. The simplest approach is to make magit-delta independent of your command-line delta settings using:

(add-to-list 'magit-delta-delta-args "--no-gitconfig")

And then add the settings you do want in magit-delta using elisp (e.g. more add-to-list calls).

But there are several other possibilities, if you don't like the potential duplication of settings in that solution. E.g. you could use features to define magit-delta and non-magit-delta features and ensure that they are activated accordingly in magit-delta versus your usual command line delta.

g5pw added a commit to g5pw/dotfiles that referenced this issue Jul 14, 2022
@g5pw
Copy link

g5pw commented Jul 21, 2022

Thanks @dandavison, your profile suggestion resolved the issue! Still, it feels a bit like a workaround, maybe there could be a way to automatically disable line numbers when called from magit?

localshred added a commit to localshred/dotfiles that referenced this issue Feb 13, 2023
@choma
Copy link

choma commented Feb 19, 2023

I did what @dandavison suggested:

But there are several other possibilities, if you don't like the potential duplication of settings in that solution. E.g. you could use features to define magit-delta and non-magit-delta features and ensure that they are activated accordingly in magit-delta versus your usual command line delta.

So, in case it is useful for someone, here it is:

;; ~/.emacs.d/init.el
(use-package magit-delta
  :hook (magit-mode . magit-delta-mode)
  :config
  (setq magit-delta-delta-args (append magit-delta-delta-args '("--features" "magit-delta"))))
# ~/.config/git/config
[delta]
    navigate = true  # use n and N to move between diff sections
    side-by-side = true
    # 
    features = default magit-delta

[delta "default"]
    line-numbers = true

[delta "magit-delta"]
    line-numbers = false
# ~/.bashrc
export DELTA_FEATURES=+default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants