I have a git clean filter set up for my Obsidian vault repo. When I use commandline git to commit changes the filter is always applied regardless of the file contents, but when I'm using Obsidian Git and I run Obsidian Git: Create Backup, a git commit is created but the configured git filter doesn't run for any files with a “ (&ldquo) character in them.
From the little digging I've done it might be that either Obsidian Git or SimpleGit aren't properly escaping a string somewhere. It's possible that there is also an issue with other characters like \”
Relevant errors (if available)
No response
Steps to reproduce
Should work on both Mac and Linux.
First set everything up:
mkdir /tmp/test
cd /tmp/test
git init .
echo "*.md filter=lastmod_updater" | cat > .gitattributes
git add .gitattributes
git commit -m "add .gitattributes"
git config --local filter.lastmod_updater.clean /tmp/lastmod_updater
cat > /tmp/lastmod_updater <<- EOM
#!/usr/bin/ruby
# These 2 lines added to determine if the hook is being called at all.
require 'fileutils'
FileUtils.touch('/tmp/lastmod_updater_called'+Time.now.to_i.to_s)
require 'time'
data = STDIN.read
last_date = \`/usr/bin/git log --pretty=format:"%ad" -1\`
puts data.gsub(/^lastmod:.+$/, 'lastmod: '+Time.now.iso8601)
EOM
chmod u+x /tmp/lastmod_updater
echo "lastmod: foo“" | cat > cmd.md
echo "lastmod: foo“" | cat > obsidian1.md
echo "lastmod: foo" | cat > obsidian2.md
Now verify that the git filter setup works when running in the commandline:
git add cmd.md
git commit -m "cmd commit"
# We clone the repository to verify HEAD contents because git
# filters don't modify the worktree and you won't see the modified
# files unless you rm them and check them out and I thought that
# cloning was clearer.
cd ..
git clone test test2
grep lastmod test2/*.md
Which should show foo replaced with a timestamp:
lastmod: 2022-04-23T19:05:25+02:00
Now do this:
If you're on Mac you will need to open Finder and add /tmp/test to the sidebar so that you can select it on the "Choose folder" Obsidian window.
Open Obsidian
Open another vault > Open folder as vault and choose /tmp/test
Install Obsidian Git & enable it
Open Command Palette and Run Obsidian Git: Create Backup
Run the following on the commandline to confirm that the filter didn't get applied to obsidian.md:
cd /tmp
git clone -q test test3
grep lastmod test3/obsidian*.md
Wow I was having issues with filters not being applied to a subset of files and I guess this was the reason! Good digging. But unfortunate :( I will just use the command line I guess.
Describe the bug
I have a git clean filter set up for my Obsidian vault repo. When I use commandline git to commit changes the filter is always applied regardless of the file contents, but when I'm using Obsidian Git and I run
Obsidian Git: Create Backup
, a git commit is created but the configured git filter doesn't run for any files with a“
(&ldquo) character in them.From the little digging I've done it might be that either Obsidian Git or SimpleGit aren't properly escaping a string somewhere. It's possible that there is also an issue with other characters like \”
Relevant errors (if available)
No response
Steps to reproduce
Should work on both Mac and Linux.
First set everything up:
Now verify that the git filter setup works when running in the commandline:
Which should show foo replaced with a timestamp:
Now do this:
Which should show something like this:
Expected Behavior
test3/obsidian1.md
should havefoo“
replaced with a timestamp, in other words, it should behave exactly like commandline git.Addition context
No response
Operating system
macOS
Plugin version
1.25.1