As part of a small web application I'm version controlling the SQLite DB. I've set up clean and smudge filters in order to store the DB on the remote repository as SQL rather than binary, so I can actually read its entries there.
How I've accomplished this:
$ git config --global filter.sqlite3tosql.clean "sqlite3 %f .dump"
$ git config --global filter.sqlite3tosql.smudge "sqlite3 %f"
$ echo "*.db filter=sqlite3tosql" > /etc/gitattributes
This works when I do manual commits, but when I do programmatic commits from the web app–
subprocess.call("git add /home/appuser/repo/db.db", shell=True)
subprocess.call("git commit -m 'update db'", shell=True)
subprocess.call("git push origin master", shell=True)
–the filters are somehow ignored. The commit and push succeed, but the SQLite is stored as binary.
What am I missing here?
For thoroughness, here's the permissions for the gitattributes file:
$ ls -l /etc/gitattributes
-rw-r--r-- 1 root root 25 Nov 18 07:27 /etc/gitattributes
My user belongs to sudoers, and the app is run via systemd and gunicorn using my user and group (not root). I ran the git config --global
calls as my user -- not root or the app user.
I also tried
$ echo "*.db filter=sqlite3tosql" > ~/.config/git/attributes
$ echo "*.db filter=sqlite3tosql" > /home/appuser/.config/git/attributes
$ ls -l ~/.config/git/attributes
-rw-r--r-- 1 myuser www-data 25 Nov 18 07:55 /home/myuser/.config/git/attributes
$ ls -l /home/appuser/.config/git/attributes
-rw-r--r-- 1 myuser www-data 25 Nov 18 07:55 /home/appuser/.config/git/attributes
but this didn't help the situation.
CodePudding user response:
git config --global ...
means global to the user account that runs the command, not to the system
The default "global" config file for user appuser
is /home/appuser/.gitconfig
,
but if you ran :
$ git config --global filter.sqlite3tosql.clean "sqlite3 %f .dump"
$ git config --global filter.sqlite3tosql.smudge "sqlite3 %f"
using your own user account, these settings got written to your own /home/youruseraccount/.gitconfig
file.
Set the config values for the appuser
account, either by running the git config ...
commands as appuser
, or by copying the relevant sections to /home/appuser/.gitconfig
.
Another option is to set the GIT_CONFIG_GLOBAL
environment variable to explicitly name the file to read configuration settings from :
GIT_CONFIG_GLOBAL=/path/to/config/file git commit
check git help git
to have detailed information on these global environment variables.