Skip to content

Conversation

@pms1969
Copy link

@pms1969 pms1969 commented Apr 22, 2014

just added to the work of olmobrutall. tests included.

Copy link
Member

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?

Copy link
Author

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

@jamill
Copy link
Member

jamill commented Apr 23, 2014

Thanks for this PR! I have included some initial feedback.

@pms1969
Copy link
Author

pms1969 commented Apr 23, 2014

Thanks @jamill I'll take a look. Don't suppose you know how to get the default branch?

@jamill
Copy link
Member

jamill commented Apr 23, 2014

What behavior do you want the Add method to support in regards to the initial commit of the submodule? Do you want to be able to specify an arbitrary revision (e.g. commit ID, branch name, etc..) or just a branch name?

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 git submodule add command.

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).

Copy link
Author

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.

Copy link
Author

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).

Copy link
Author

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????

Copy link
Member

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:

  1. Call git_submodule_add_setup
  2. Clone or (fetch + checkout) the submodule repository
  3. 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.

Copy link
Member

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.

Copy link
Author

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??

@carlosmn
Copy link
Member

This is not functionality that belongs in SubmoduleCollection which should be about managing them, rather than emulating git's higher-level commands.

As this rather old, I'm going to close it, but if you still want to, something like this would belong in Commands.

@carlosmn carlosmn closed this Apr 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants