Complementing the other answers, I changed their macros in order to (i) show the output of Git commands at the message panel of TeXstudio by using > txs:///messages
; (ii) call xterm
1 for the Git commands that need input, such as a password; and (iii) use the great tool Git LaTeXdiff to generate PDF diffs of the last pulled revision and the previous one, or the last pulled revision and the working directory.
1. xterm
seems to be available on most Linux-based operating systems. See https://stackoverflow.com/a/1105033/2448553
Git pull:
%SCRIPT
buildManager.runCommand("xterm -e \"git pull; read -n1\"", editor.fileName())
Diff pulled as PDF (requires Git LaTeXdiff):
%SCRIPT
fileNameWithPath = editor.fileName()
fileName = fileNameWithPath.substring(fileNameWithPath.lastIndexOf("/") + 1)
buildManager.runCommand("git latexdiff --main " + fileName + " -b --ignore-latex-errors --latexopt \"-shell-escape\" HEAD~1 > txs:///messages", editor.fileName())
Diff working file as PDF (requires Git LaTeXdiff):
%SCRIPT
fileNameWithPath = editor.fileName()
fileName = fileNameWithPath.substring(fileNameWithPath.lastIndexOf("/") + 1)
buildManager.runCommand("git latexdiff --main " + fileName + " -b --ignore-latex-errors --latexopt \"-shell-escape\" HEAD -- > txs:///messages", editor.fileName())
Git commit added:
%SCRIPT
dialog = new UniversalInputDialog()
dialog.setWindowTitle("Git commit")
dialog.add("-m \"Committed within TeXstudio\"", "Comment: -m \"line0\" -m \"line1\" ...", "comment")
if (dialog.exec() != null) {
comment = dialog.get("comment")
buildManager.runCommand("git commit " + editor.fileName() + " " + comment + " > txs:///messages", editor.fileName())
}
Git commit all tracked:
%SCRIPT
dialog = new UniversalInputDialog()
dialog.setWindowTitle("Git commit all")
dialog.add("-m \"Committed within TeXstudio\"", "Comment: -m \"line0\" -m \"line1\" ...", "comment")
if (dialog.exec() != null) {
comment = dialog.get("comment")
buildManager.runCommand("git commit -a " + comment + " > txs:///messages", editor.fileName())
}
Git push:
%SCRIPT
buildManager.runCommand("xterm -e \"git push origin master; read -n1\"", editor.fileName())
Git status:
%SCRIPT
buildManager.runCommand("git status > txs:///messages", editor.fileName())
Git diff:
%SCRIPT
buildManager.runCommand("git diff HEAD > txs:///messages", editor.fileName())