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
More flexible clone URL generation for submodules #3828
Conversation
For which our wrapper had to be extended. One could argue that `.call_git_items_()` would be at least as adequate, but I chose to invest in my prior investments ;-)
The desire is to slim the interface.
To align with get_hexsha()
No StopIteration could have come out of that code block
Codecov Report
@@ Coverage Diff @@
## master #3828 +/- ##
==========================================
+ Coverage 80.71% 80.73% +0.02%
==========================================
Files 273 273
Lines 35905 35925 +20
==========================================
+ Hits 28979 29004 +25
+ Misses 6926 6921 -5
Continue to review full report at Codecov.
|
This touches upon an idea by @yaricoptic expressed in datalad#3827 (comment) and merely lays the foundation for further work. Names are not unique (and I don't see how they could be, or what we would gain from it), hence no dict. Choice of names is debatable too. But given that they are not used ATM, it doesn't really matter and can easily be changed.
datalad/support/gitrepo.py
Outdated
@@ -1308,6 +1309,9 @@ def for_each_ref_(self, fields=('objectname', 'objecttype', 'refname'), | |||
descending order. | |||
count : int, optional | |||
Stop iteration after the given number of matches. | |||
contains : str, optional | |||
Only list refs which contain the specified commit (HEAD if not | |||
specified). |
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 not specified, it's None
, and --contains
isn't added. That's not the same as restricting the results to --contains=HEAD
.
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.
Fixed, by removing that part from the docs (copied from Git).
return [ | ||
remote | ||
for remote in repo.get_remotes(with_urls_only=with_urls_only) | ||
if any(rb.startswith(remote + '/') for rb in remote_branches) |
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'm not sure I see the point of using get_remote(with_urls_only=...)
here, especially given this is only used in one spot. Wouldn't for_each_ref_
s output (with an additional layer stripped) be sufficient?
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.
This is just keeping what the keep did before. I tried to get rid of it, but couldn't figure out why things would break. I'll leave it for another time.
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.
This is just keeping what the keep did before.
Yes...
I tried to get rid of it, but couldn't figure out why things would break.
ah, all right, so my guess that it isn't need is wrong. Thanks.
datalad/support/gitrepo.py
Outdated
except CommandError as e: | ||
if 'does not have any commits' in e.stderr: | ||
if 'unknown revision or path not in the working tree' in e.stderr: |
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.
From my POV it'd be best to avoid brittle error message matching if we can. Given we're in the error handling arm, another git call seems acceptable, so this could be replaced by if self.get_hexsha() is None
. (get_hexsha()
relies on format_commit
which itself does error message matching, but at least we'd avoid introducing another spot with a new message.)
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.
# outside. Additional guesswork can only make it slower | ||
clone_urls.append((name, url)) | ||
|
||
# CANDIDATE: the actual configured gitmodule URL |
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 find this new wording more confusing than what it replaced. In Git's eyes, relative paths have the following resolution: (1) relative to the URL of the tracking branch, (2) if there is not a tracking branch, relative to the URL of "origin", or (3) if there is not a configured remote, relative to the working directory. So the new description is only accurately describing what Git considers to be the configured URL in cases that fall through to no. 3.
(As a sidenote that's not directly related to these changes, it looks like _get_flexible_source_candidates_for_submodule
doesn't handle case no. 2, so there's a scenario where git submodule
can clone something while datalad install
can't.)
datalad/distribution/get.py
Outdated
ds.path, | ||
alternate_suffix=False) | ||
clone_urls.extend( | ||
('origin', url) |
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.
It sounds like these names aren't used for anything at this point, so it doesn't really matter, but perhaps "local" would be a better description?
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.
Funny enough local
is what I had. Now it is local again ;-)
@kyleam Love'ya! |
This fixes gh-3827, while also tweaking a little bit on the sides -- this is rather old code.
This is technically ready. Once agreed on, there will be a use case description in the handbook on feature.