Can't add a file to a project from within a git worktree
14 ビュー (過去 30 日間)
Nickolai Belakovski 2022 年 6 月 3 日
回答済み: Ayush Yadav 2022 年 6 月 6 日
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.
Ayush Yadav 2022 年 6 月 6 日
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.
その他の回答 (0 件)
Find more on Source Control Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!