Open vermiculus opened 2 years ago
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
?
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.
git config --list --show-origin | grep delta
yields nothing.
@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
Create a file at /tmp/fake-git
containing this:
#!/bin/bash
OUTFILE=/tmp/git-input
echo "$@" >>$OUTFILE
tee -a $OUTFILE | git $@
echo -------------------------------------------------------------------------- >>$OUTFILE
chmod +x /tmp/fake-git
(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?
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?
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.
I encountered this when I set line-numbers = true
in delta
@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: https://github.com/dandavison/magit-delta/issues/22#issuecomment-1002379108
I have the same situation, and have line-numbers = true
in my config. If I set it to false, everything works.
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.
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?
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
When I have magit-delta-mode enabled, I can't seem to stage individual hunks:
This seem related to #13 and #18, but I don't have line numbers enabled.