Log in

No account? Create an account

TeXstudio and Git

« previous entry | next entry »
Jul. 30th, 2018 | 11:38 am

I use TeXstudio for editing (La)TeX documents. It's a great tool, and I'm generally very happy with it.

Now, what I'd like to is automatically sync my documents with a remote repo. I'm less interested in collaborative editing etc. myself, but I'd like to have a remote backup: backups are important, and the mantra "backup early, backup often" is best followed when making backups is quick and easy.

Tracking changes and being able to revert to old versions is also invaluable, so you'll want to use a revision control system of some sort. These days, Git's a natural choice. You could host your own server (remember we're talking remote backups, so a local repo won't cut it); if you don't want that there's a lot of hosting services out there, both free and paid.

Back to TeXstudio — it supports revision control, but only using SVN, which is less than useful these days (the only time you'll ever want to use SVN is in a legacy environment). Git support has been requested for about 7,5 years, but to no avail so far.

So you gotta do it yourself. A couple of years ago, someone suggested substituting Git for SVN without TeXstudio noticing what's going on, but this didn't work for me. The differences between Git and SVN workflows go beyond different command line arguments (notably, Git requires you to stage changes before committing).

One suggestion I found was to create a shell script (or batch file) doing the necessary work, and adding that as a new build command. I didn't try this, but I imagine it'd work. There was also a question on tex.stackexchange.com (one of the most valuable TeX resources out there) about this a while back which pointed to a user-contributed TeXstudio script.

This works. What I've done is import this as a script, and also add a light-weight version that can be invoked anytime I want a quick-and-dirty automatic backup:

buildManager.runCommand("git commit -a -m \"Committed by TeXstudio\"", editor.fileName())
buildManager.runCommand("git push origin \"master\"", editor.fileName())

Occasionally, this says "Everything up-to-date" in the message log rather than indicating it actually pushed a commit, but the commits themselves are apparently still working. Knock on wood; the whole thing feels like a stop-gap solution, and TeXstudio really needs proper Git support, but it's better than nothing.

If anyone's got any tips, tricks, suggestions, caveats, war stories etc., I'd love to hear them.

EDIT: sadly, this isn't working as I thought it would after all. On my production files, rather than a few test files committed to a test repo, Git is producing a lot of warnings, and nothing is getting committed. Back to the drawing board — which for now means manually invoking Git on the command line.

Tags: ,

Link | Leave a comment |

Comments {0}