yadm-dev / yadm

Yet Another Dotfiles Manager
https://yadm.io/
GNU General Public License v3.0
5.11k stars 175 forks source link

yadm not applying git filter #472

Closed stefan-muc closed 11 months ago

stefan-muc commented 11 months ago

Motivation: Git does indent .gitconfig with tabs (see StackOverflow), but I have that mixed in my config. I want to make sure that I only commit tabs - which could be done elegantly using a git filter.

But as far as I figured out:

Describe the bug

yadm doesn't seem to apply git filter during staging of a changed file

To reproduce

Steps to reproduce the behavior:

Set up a test filter:

yadm config filter.test.clean "echo 'the filter has been applied'"
echo ".gitconfig filter=test" > $(yadm rev-parse --git-path info/attributes)

You can confirm that configuration is set up correctly reading it:

user@server:~$ yadm config filter.test.clean
echo 'the filter has been applied'
user@server:~$ yadm check-attr filter .gitconfig
.gitconfig: filter: test

But staging a change in the file doesn't apply the filter:

user@server:~$ echo 'test' > .gitconfig
user@server:~$ yadm add -p .gitconfig
[... normal diff get's displayed, no filter applied]

If you re-do the whole setup but use git instead of yadm, it works as expected:

user@server:~/tmp$ git add -p .gitconfig
diff --git a/.gitconfig b/.gitconfig
index 33194a0..e968616 100644
--- a/.gitconfig
+++ b/.gitconfig
@@ -1 +1 @@
-old content
+the filter has been applied
(1/1) Stage this hunk [y,n,q,a,d,e,?]?

I would expect yadm to apply the filter just as git with same config does. How can I achieve this? Documentation didn't tell me why this shouldn't work.

Can this be reproduced with the yadm/testbed docker image: [not tested]

Environment

Tested on Debian 12.2 using git version 2.39.2, yadm version 3.2.2

rasa commented 11 months ago

@stefan-muc Can you retry using yadm gitconfig instead of yadm config, per https://github.com/TheLocehiliosan/yadm/blob/master/yadm.md#commands ?

I know this isn't intuitive. It would be preferable that, if yadm config is passed a setting that doesn't apply to yadm, that yadm simply passes it onto git. Unfortunately, that doesn't seem to be the case.

https://github.com/TheLocehiliosan/yadm/issues/251 may provide you some ideas on how to work around this issue.

stefan-muc commented 11 months ago

@stefan-muc Can you retry using yadm gitconfig instead of yadm config

Oh great, this works! Thank you very much for your support!