Provide a wrapper for simple submodule clone steps#4637
Conversation
|
Now I don't know what changes you're requesting anymore 😉. |
|
Sorry for my comments being confusing :P The thing is that your function unfortunately doesn't work. The test you've written works by accident due to a bug in |
|
Okay, I fixed the function, so yeah the test wasn't working as expected because of pathing issues (which I wasn't expecting so, good catch 😉). There's two ways to fix : either the clone existence check is wrong, and this should be changed, or it's not, and the clone must be performed manually. Now for the discussion part, is clone wrong ? We're using the "approved"
|
|
I don't like the second option, it's much too specific. While I think the first option is quite nice, I don't know if we really want to relax the check like that. So, option number three:
|
bd490b5 to
95f75e6
Compare
|
I've gone a 4th way: add a private variant of |
pks-t
left a comment
There was a problem hiding this comment.
Thanks for the update! I'm +1 on this, only got some stylistic remarks.
38cc2d5 to
87f34eb
Compare
|
Apart from the naming question, this is good to go (my reply somehow doesn't show up from the conversation view though). |
87f34eb to
df087eb
Compare
|
Rebased, I've renamed the function to |
| */ | ||
| GIT_EXTERN(int) git_submodule_clone( | ||
| git_repository **out, | ||
| git_submodule *submodule); |
There was a problem hiding this comment.
To not repeat past mistakes, do we maybe want to introduce an options struct here from the get-go? Doesn't need to contain anything options for now
There was a problem hiding this comment.
I usually like having a default "do the default thing" and provide an _ext on top of that, if/when the need arises. But it feels a little premature (though only because of a lack of use cases, so if you have a definite not too difficult "this is needed" example, I'll reconsider).
There was a problem hiding this comment.
Hmm. I would very quickly want progress reporting if I were to use this in anger. I concede that this is a bit tricky. I would definitely want, eg, progress reporting but many fields should not be eligible to be set by an end-user, so taking a whole git_clone_options may not be appropriate. Additionally, we may need to do some proxy'ing with some of the callbacks to ensure that payloads are delivered correctly.
Having said that, progress reporting and cancellation still feels like table-stakes for any function that does network I/O.
There was a problem hiding this comment.
I usually like having a default "do the default thing" and provide an _ext on top of that, if/when the need arises.
Well, defaults are easily attainable by just passing NULL. Personally, I'm not too happy with the _ext suffix and I see it rather as a "Okay we f'd up the first time, so let's just tack on a suffix and fix up the function".
There was a problem hiding this comment.
And yeah, fully agree with the usecases @ethomson proposes.
There was a problem hiding this comment.
Hmm, yeah that's a tough decision. I can see pros and cons to simply taking a git_clone_options struct and just ignoring and overwriting parts of it (documenting this of course). Or a simpler struct and proxying that data into a git_clone_options.
The former seems like the simpler strategy for you (the implementer). What I'm not sure of is whether it's easier for users of the library, which is of course where I think the important bits are.
There was a problem hiding this comment.
Simply taking git_clone_options is not going to fly in case there's going to be submodule-cloning specific options at some point in time, which I'd say is not all that unlikely. So I think it should definitely be a new git_submodule_clone_options struct, but as you said it may just embed and forward (parts of) the git_clone_options struct.
There was a problem hiding this comment.
I've noticed that git_submodule_update_options seemed to have mostly what we needed, so I've added this as our option struct. Sorry, I forgot to rebase-ping, but IIRC it was ready to 🚢 as well.
There was a problem hiding this comment.
Oh, didn't see that, sorry.
git_submodule_update_options does look similar to what we need, that's true. I'm still a bit hesitant, though. It includes options that cannot fit the bill right now and we may need to extend the struct for either git_submodule_update or git_submodule_clone with options that are incompatible with the respective other function. If you ask me, that's trading ease of implementation (no need for an additional struct) for a confusing API. I'm more in the camp of using one struct per function whenever it's not obvious that they're always going to take the same set of opts.
Just my 2 cents -- I'm happy to be overruled here due to my recent lack of time for libgit2.
There was a problem hiding this comment.
(Struct for reference)
typedef struct git_submodule_update_options {
unsigned int version;
git_checkout_options checkout_opts;
git_fetch_options fetch_opts;
int allow_fetch;
} git_submodule_update_options;Of theses, allow_fetch feels the most dubious, since we don't have any repository before the call. checkout seems fine (though I think there's a few rough edges), and fetch looks okay.
Now, I don't have that much experience with submodules, but a shared "those are the settings to obey if an update needs to happen", especially given the git submodule update --init --recursive thingie seems to be a nice thing. Writing in the docblock that allow_fetch only makes sense if the submodule is already initialized, and ignoring it if it's set seems sufficient.
|
Thanks, @tiennou! Looks good to me except for the one comment I have |
17ebc26 to
6669106
Compare
6669106 to
3c5d78b
Compare
|
Rebased your branch to fix conflicts. |
The test submodule::add::homemade_clone unfortunately doesn't test what's expected, but does instead clone the submodule to a directory that is outside of the parent repository. Fixing this by cloning to the correct location isn't possible, though, as `git_submodule_add_setup` will have pre-created a ".git" file already, which will cause `git_clone` to error out. As it's not possible to perform the clone without fiddling around with the repo's layout, let's just remove this test as that is in fact what the new `git_submodule_clone` function is for.
The test submodule::add::submodule_clone doesn't use a sandbox, and thus the created repo will not get deleted after the test has finished. Convert the test to use the empty standard repo sandbox instead to fix this.
Add two more tests that verify our behaviour in some edge cases, notably when cloning into a non-empty directory and when cloning the same submodule twice.
|
I've removed the homegrown clone test, which didn't do what one expected (the resulting submodule was cloned outside of the parent repo) and added two new tests |
|
Thanks for keeping up with this ! ✨ |
While working on the submodule-in-worktree issue, I had to finagle with #4149. So let's add that to the API.
Arguably, it could be named
git_submodule_addand perform all the steps by itself.