using hooks with git source control from Matlab. Hooks that work from outside Matlab are not executed from within.
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tobias Huth
am 23 Jan. 2017
Kommentiert: Marlos
am 3 Okt. 2024
Hello Everyone,
I'm working with Matlab 2016a try to get the source control going. Commit, Push, Fetch etc work fine, from both the context menu in the Current Folder Window and from the GUI shipped with git. But when I implement a server-sided hook in the remote repository, Matlab fails me by ignoring the hook. When I commit from outside Matlab, the hook works.
hook-file is located in ..\remote_repo\hooks by the name 'pre-receive' without extension. Source Code:
#!/usr/bin/env python
import matplotlib.pyplot as plt
import sys
plt.figure()
plt.show()
sys.exit(1)
The hook is written for testing purposes only. It opens a matplotlib window and when the window is closed, an error is thrown as the Push-Operation is aborted.
As I mentioned, when I push my commit from outside Matlab via the GUI, the expected happens, matplotlib-window and error. But when I push from the same local repository to the same remote repository, the push is successful...
Is there a way to execute hooks both server-sided and local ones from Matlab?
Thanks in advance and greetings,
Tobias
2 Kommentare
Saurabh Gupta
am 30 Jan. 2017
MATLAB uses JGit for integration with Git. If the hooks that you intend to use are not supported by JGit, they will not work with MATLAB either.
Which operating system are you using? You may be required to configure cygwin, if you are on Windows, for using Git hooks.
Akzeptierte Antwort
Rebecca Nakhoul
am 30 Mai 2024
Bearbeitet: Rebecca Nakhoul
am 26 Sep. 2024
- Starting in R2024a, MATLAB Git integration runs Git hooks with no additional setup. Supported hooks are pre-commit, commit-msg, post-commit, prepare-commit-msg, pre-push, pre-merge-commit, post-checkout, and post-merge. For an example, see Use Git Hooks in MATLAB.
- Before R2024a, to use some Git hooks from within MATLAB, install Cygwin™ and add it to the MATLAB library path. For instructions, see Install Cygwin (Before R2024a). Supported hooks are pre-commit, commit-msg, post-commit, and pre-push.
3 Kommentare
Rebecca Nakhoul
am 26 Sep. 2024
- How about you try something like this:
if ! [[ $COMMIT_MSG =~ $PATTERN ]]; then
exec 1>&2
echo "The message needs to start with: [ID-TASKNUMBER]"
exit 1
fi
- Also, better explicitly specify the shell that it is executiing the script at the top of the hook script:
#!/bin/bash
Marlos
am 3 Okt. 2024
Weitere Antworten (1)
James Otterson
am 17 Jan. 2019
Uping this question - I am having the same problem, but in regard of my local repo hook. I am using Windows, and using python to run the hook. RStudio, VS Code and command line in Matlab (!git commit -m "message") will run my hooks but commiting code using the Matlab GUI Git interface will bypass all hooks.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Source Control finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!