Skip to content

Fix git_submodule_sync with relative url#5322

Merged
ethomson merged 4 commits intolibgit2:masterfrom
kdj0c:fix_sub_sync
Jan 8, 2020
Merged

Fix git_submodule_sync with relative url#5322
ethomson merged 4 commits intolibgit2:masterfrom
kdj0c:fix_sub_sync

Conversation

@kdj0c
Copy link
Copy Markdown
Contributor

@kdj0c kdj0c commented Dec 5, 2019

git_submodule_sync should resolve submodule before writing to .git/config
to have the same behavior as git_submodule_init, which does the right thing.

This should solve issue #5301

Copy link
Copy Markdown
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks for this straight forward fix! There is one nit with regards to formatting as you use spaces instead of tabs for the dispose, but as soon as that's fixed I'll be happy to merge.

Would you like to try and come up with a test? Please feel free to say "no" if you don't feel comfortable or are lacking time to implement one, that's perfectly fine.

Anyway, thanks for this lovely contribution!

src/submodule.c Outdated
}

git_buf_dispose(&key);
git_buf_dispose(&effective_submodule_url);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is using spaces instead of tabs :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry, will fix this asap ;)

@kdj0c
Copy link
Copy Markdown
Contributor Author

kdj0c commented Dec 5, 2019

I've modified a test in test_submodule_modify__sync() to check for this behaviour.
The test is failed without the "fix" commit.
I forced submodule3 to be relative, but maybe I should add a new submodule4 in this test ?

@gdetrez
Copy link
Copy Markdown

gdetrez commented Dec 6, 2019

@kdj0c I can confirm that this fixes #5301 when I patch the git2 rust crate with this branch 🎉

It does break some edge case however: if the superproject has no commits (i.e. it's a freshly initialized repository), running git_submodule_sync on a submodule now returns an error: "reference \'refs/heads/master\' not found".
But I'm not sure how important this edge case is. I only found out because this is what happens with the reproduction steps in #5301. (This error doesn't happen with the git submodule sync command)

@pks-t
Copy link
Copy Markdown
Member

pks-t commented Dec 13, 2019

@kdj0c: would you feel comfortable with fixing the edge case pointed out by @gdetrez? Let me know if not, then I'll dig into this and amend your PR

@kdj0c
Copy link
Copy Markdown
Contributor Author

kdj0c commented Dec 18, 2019

I looked into your edge case, I think the problem is that get_url_base() calls git_repository_head() which returns GIT_EUNBORNBRANCH error.
but as in your test sequence, you are doing "git remote add origin https://github.com/libgit2/libgit2.git", get_url_base() should have found this url and returned it.
It's a bit too complex for me at this point, and I don't want to break other use-case.
@pks-t you can dig deeper, if you think this edge case is important.

@kdj0c
Copy link
Copy Markdown
Contributor Author

kdj0c commented Dec 18, 2019

@gdetrez can you try again with my latest patchset ? it "may" solve the edge case.

kdj0c and others added 4 commits January 6, 2020 15:03
git_submodule_sync should resolve submodule before writing to .git/config
to have the same behavior as git_submodule_init, which does the right thing.
The submodule code has grown out-of-date regarding its coding style.
Update `git_submodule_reload` and `git_submodule_sync` to more closely
resemble what the rest of our code base uses.
When setting up relative URLs for a submodule, then we resolve it to
the actual location and write that into ".git/config" instead of
writing the relative value. We do not yet have a test to nail down this
behaviour, which is now being added by this commit.
@pks-t
Copy link
Copy Markdown
Member

pks-t commented Jan 6, 2020

While your added test exercised the code path, it didn't verify that results are what we'd expect. I've thus replaced it with a new test case that explicitly checks resulting paths and pushed that on your branch. I've naturally retained authorship of your commits. I hope you don't mind that fixup :)

The fix for unborn branches looks good to me, too, so this PR should be ready to go. I'll give it a few days to settle and wait for feedback. If nobody complains, I'll merge it towards the end of this week. Please feel free to reach out to us in case I forget.

@kdj0c
Copy link
Copy Markdown
Contributor Author

kdj0c commented Jan 6, 2020

Thanks a lot, I'm looking forward to have it merged ;)

@pks-t
Copy link
Copy Markdown
Member

pks-t commented Jan 7, 2020 via email

@gdetrez
Copy link
Copy Markdown

gdetrez commented Jan 8, 2020

@kdj0c Sorry for the delay. I tested the latest version (11e8ee1) and it did fix the issue with fresh repository 👍

@ethomson
Copy link
Copy Markdown
Member

ethomson commented Jan 8, 2020

LGTM. Thanks @kdj0c, @gdetrez and @pks-t!

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