-
Notifications
You must be signed in to change notification settings - Fork 920
Submodule add #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Submodule add #684
Conversation
LibGit2Sharp/SubmoduleCollection.cs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not completely familiar with the submodule API, but I think the usage of the name parameter is not quite right. The name of the submodule looks to be the path of the submodule. If the relativePath parameter is provided, then the name parameter is not used in the creation of the submodule, and the lookup on name will not find the submodule.
Maybe this method only takes a path parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done this, it makes sense. moved the relative path to the front of the parameter list. I'll commit and push when I've figured out how to do the default branch thing
|
Thanks for this PR! I have included some initial feedback. |
|
Thanks @jamill I'll take a look. Don't suppose you know how to get the default branch? |
|
What behavior do you want the The clone method in libgit2 supports specifying the initial branch to checkout, or will checkout the remote's HEAD branch by default. This option is not currently wired through LibGit2Sharp, but it should not be much work to expose. I think this follows the capabilities exposed by the If this method should to handle any rev spec, then I think you could still clone with the option to not checkout the working directory. Then, you could manually checkout the version you want. Either way, I think you want to use clone instead of fetch. Clone will handle the default case of checking out the remote's HEAD branch (and it also brings down tags... etc). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, changes made as per your suggestion.
I'm not sure it's the right thing to do tho, since the output is different to the way the git command itself works. For instance if I do a git submodule add repo I would end up with a .git file in my subrepo directory, the contents of which point back to my main .git directory at a subdirectory of that which then houses all the usual files and directories you'd expect to find. Doing the checkout and then running the submodule_add over the top of that houses all the indexing files and directories in .git directory of the subrepo.
It's only a small difference I'll grant you, those files need to live somewhere, but it's the kind of thing that could break in the future. I've done a bit of digging, and I think I know how to do the fetch of the remote head, so I'll plod on with that and do another commit later. You can then choose to take whichever implementation takes your fancy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgive the placing of that comment, it should have been quite a bit lower. (github takes a bit of getting used to).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one other thing. Do I need to do another pull request for the updated change????
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one other thing. Do I need to do another pull request for the updated change????
No, you can just push your changes to the source branch of your pull request (e.g. your submodule_add branch).
The way I would expect this to work (from reading the libgit2 documentation, I have not tried this myself), is that you would:
- Call
git_submodule_add_setup - Clone or (fetch + checkout) the submodule repository
- Call
git_submodule_add_finalize
I believe the useGitLink parameter controls whether the submodule workdir is contained in the .git/submodules directory, or directly in the main repository workdir. I am not sure which directory the fetch should be perfumed in if useGitLink is true.
Maybe @carlosmn has more specific guidance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submodules are more @arrbee 's thing, but I'll try go give some guidance on this.
We need to support the old method of storing the git-dir under the worktree for older git versions, but most tools should use the gitlink versions when creating new ones.
The old version is fairly straightforward to clone. For the new version, we would probably need to use git_clone_into(). I'm not sure if this is currently exposed in libgit2sharp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I try and clone into the directory after I call git_submodule_add_setup then it barfs because the directory already exists. deleting it doesn't seem sensible. I will check, but the setting of use_git_link determines the behaviour of git_submodule_add_setup. (either new style or old style checkout)
git_submodule_add_setup does all the initial setup of the directory and git structure, but doesn't fetch or checkout. I think the git_submodule_add_finalize takes the revision of the submodule and does whatever it needs to do with that in the main git repo to set it as the version.
I'll work on getting the fetch and checkout working, and commit (probably tomorrow now). Can I just confirm that the remote head can be retrieved by examining the contents of the .git/refs/remotes/origin/HEAD in the submodule .git directory? Is there some programatic way I can get that in libgit2sharp??
|
This is not functionality that belongs in As this rather old, I'm going to close it, but if you still want to, something like this would belong in |
just added to the work of olmobrutall. tests included.