Skip to content

Instantly share code, notes, and snippets.

@orihpt
Last active August 9, 2022 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orihpt/8285c6a297b5f1346078075708c5ea88 to your computer and use it in GitHub Desktop.
Save orihpt/8285c6a297b5f1346078075708c5ea88 to your computer and use it in GitHub Desktop.
Resolve conflicts between apps in Matlab
tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -+= Welcome =+-
% This script was created by Ori Hauptman from Israel.
%
% Because of the way Matlab Apps are saved, it's hard and sometimes
% even not possible to resolve conflicts with Git.
%
% Run this script every time before commiting your changes to Git
% to create a folder for each of your apps, so you can reslove
% the conflicts in there.
%
% After you resolve the conflicts you can make a zip archive
% from your app's folder and change it's name to end with '.mlapp' to
% bring it back to be an app.
%%%%%%%%%
% Configurations - supports file/folder path
appsPaths = ["MyFolder/MyApp.mlapp", "MySecondFolder/MySecApp.mlapp" ];
extractionFolders = ["MyFolder/My Application", "MySecondFolder/My Second Application"];
tempCopy = fullfile(tempdir, "appcopy.zip"); % Will be temporary created to extract the app into folder
allowNonMatlabApps = false; % Set to 'true' to ignore files that does not end with the file extension '.mlapp'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if length(appsPaths) ~= length(extractionFolders)
error("Wrong configurations." + newline + "Please make sure that the names of each of your apps that you just specified match the name of the folder that will be created.")
return;
end
for i = 1:length(appsPaths)
delete(tempCopy);
folder = extractionFolders(i);
[directory, filename, fileextension] = fileparts(appsPaths(i));
disp("Working on " + string(filename) + "...")
assert(string(fileextension) == ".mlapp" || allowNonMatlabApps, "One of the files specified on 'appsPaths' does not have a valid Matlab Application extension (should end with .mlapp)." + newline + "If this is intentionally, set 'allowNonMatlabApps' to true.")
filename = string(filename) + string(fileextension);
deleteFolder(folder);
copyfile(appsPaths(i), tempCopy);
unzip(tempCopy, folder);
end
delete(tempCopy);
disp("Done in " + round(toc,2) + "s! you can now commit your changes.")
function deleteFolder(path)
if ~isfolder(path)
return;
end
filePattern = fullfile(path, '*');
theFiles = dir(filePattern);
for k = 3 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(path, baseFileName);
if isfolder(fullFileName)
deleteFolder(fullFileName);
else
delete(fullFileName);
end
end
rmdir(path);
end
@orihpt
Copy link
Author

orihpt commented Jan 24, 2021

If you have any questions feel free to ask 😄

@orihpt
Copy link
Author

orihpt commented Aug 9, 2022

Updated the script to support file/folder paths
Also, I added a warning when trying to specify file with non-Matlab App extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment