Git File Permissions and Mobile Sync
Hey 👋
I use a git repo as my personal wiki. I’ve written about this setup before: Vim (Neovim) on my computer, and recently I started using Obsidian + GitSync on my phone. It works surprisingly well, except for one thing that’s been driving me crazy.
Every time I sync from my phone, a script I use to generate the diary pages loses its executable permission.
After every change I make in my phone, the next time I open a new diary page in vim, an error happens. Then I run chmod u+x, and move on. Until the next change from the phone.
What’s going on
I finally looked at the git log. The file showed up in every single “Last Sync (Mobile)” commit (from GitSync). But I never edited that file from my phone. The diff:
old mode 100755
new mode 100644
That’s it. No content changes. Just the mode being reset from executable to not-executable, every single time.
Looks like GitSync checks out the repo, all files become 644. Then on the next sync it runs something like git add -A, re-staging everything. Since the working tree has 644, that’s what gets committed, even if the previous commit had 755.
So there we go: I fix and commit 755, phone commits 644, I fix it again 755…
The fix
With the help of AI I decided to look into a few alternatives.
The first one was a post-merge hook, which would restore the permission after every pull. But that doesn’t stop the ping-pong in the commit history. Every sync would still produce a useless mode-change commit. Typical initial suggestion by AI (it would work!), and one of the reasons you have to always think by yourself.
The next alternative was simpler: stop relying on the executable bit. My vim autocommand was calling the script directly:
au BufNewFile ~/vimwiki/diary/*.md execute 'silent 0r !~/vimwiki/.bin/generate-vimwiki-diary-template %' | $d
Changed it to invoke the interpreter explicitly:
au BufNewFile ~/vimwiki/diary/*.md execute 'silent 0r !python3 ~/vimwiki/.bin/generate-vimwiki-diary-template %' | $d
Now the permission doesn’t matter. The file stays at 644, matching what GitSync produces, and the commit history stays clean.
Permissions on git in multi-platform scenarios have always been a bit confusing (hehehe).
If you’re into vimwiki tweaking, you might also want to read:
Send a comment