Can't add a file to a project from within a git worktree

23 views (last 30 days)
This question concerns MATLAB Projects and git worktrees. git worktree lets you have another copy of a repo on the same machine, and to link the two. So instead of git clone into two separate directories, you add a 'worktree' to a separate directory. This is great because it saves space (the two worktrees share the .git folder of the original worktree), and the two repos are in sync (so when you do git fetch in one, the other is in sync, because they share the same .git folder).
Worktree doesn't seem to play nice with MATLAB projects though. If I'm in a worktree other than the original one, I can't use addPath(currentProject, 'myfolder'); or addFile(currentProject, 'myfile.m');
It gives me an error:
Error using matlab.project.Project/addFile
Unable to add files to source control.
Exception caught during execution of add command
The system cannot find the path specified
It's not specific as to which path it can't find, but from my testing I think it has to do with being in a worktree. I created an empty repo with just a project file, tried to add a file to it from the main repo and has no issues, then tried to add the file from a worktree and got this error.
MATLAB is still creating the necessary file, it just can't stage them in the worktree. Would be great if this could be fixed.

Accepted Answer

Ayush Yadav
Ayush Yadav on 6 Jun 2022
Currently our git integration is based on JGit, which does not yet support worktrees.
Unfortunately there are no workarounds, other than using the git command line interface through MATLAB.. For example:
!git commit -m "message"
We have marked this as a potential enhancement and it might be considered in a future release.

More Answers (0)

Categories

Find more on Source Control Integration in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!