chciałbym umieścić następującą funkcję na mojej ścieżce:
function varargout = git(varargin)
% GIT Execute a git command.
%
% GIT <ARGS>, when executed in command style, executes the git command and
% displays the git outputs at the MATLAB console.
%
% STATUS = GIT(ARG1, ARG2,...), when executed in functional style, executes
% the git command and returns the output status STATUS.
%
% [STATUS, CMDOUT] = GIT(ARG1, ARG2,...), when executed in functional
% style, executes the git command and returns the output status STATUS and
% the git output CMDOUT.
% Check output arguments.
nargoutchk(0,2)
% Specify the location of the git executable.
gitexepath = 'C:\path\to\GIT-2.7.0\bin\git.exe';
% Construct the git command.
cmdstr = strjoin([gitexepath, varargin]);
% Execute the git command.
[status, cmdout] = system(cmdstr);
switch nargout
case 0
disp(cmdout)
case 1
varargout{1} = status;
case 2
varargout{1} = status;
varargout{2} = cmdout;
end
Następnie można wpisać polecenia git bezpośrednio w linii poleceń, bez użycia !
lub system
. Ale ma tę dodatkową zaletę, że możesz również wywołać cicho komendę git (brak wyjścia do linii poleceń) i wyjście statusu. To sprawia, że jest to wygodne, jeśli tworzysz skrypt do zautomatyzowanej kompilacji lub procesu wydania.
Oh wow. Czy jest to udokumentowane gdzieś w Mathworks? –
To jest tak, ale nie specjalnie do korzystania z Git: https://uk.mathworks.com/help/matlab/matlab_external/run-external-commands-scripts-and-programs.html Innym przydatnym poleceniem jest "system" . Pozwala na powrót statusu i wyniku: '[status, result] = system ('status git')': https://uk.mathworks.com/help/matlab/ref/system.html –
Zakładam, że przez accidet , rozwiązuje moje drugie pytanie: https://stackoverflow.com/questions/42271641/matlab-git-pull. Proszę, odpowiedz tam również. –