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

35 次查看(过去 30 天)
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Source Control 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by