-
Notifications
You must be signed in to change notification settings - Fork 1.3k
erepo: fix relative url on default remote (#2756) #3378
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
Changes from all commits
48b646b
ecb44a7
8bea319
505d35c
8976469
ce3b511
9b6261f
80bd6eb
3bc32b7
0790e26
07e28c2
565e4a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ def __init__(self, root_dir, url): | |
| super().__init__(root_dir) | ||
| self.url = url | ||
| self._set_cache_dir() | ||
| self._set_upstream() | ||
| self._fix_upstream() | ||
|
|
||
| def pull_to(self, path, to_info): | ||
| """ | ||
|
|
@@ -123,21 +123,35 @@ def _set_cache_dir(self): | |
|
|
||
| self.cache.local.cache_dir = cache_dir | ||
|
|
||
| def _set_upstream(self): | ||
| # check if the URL is local and no default remote is present | ||
| # add default remote pointing to the original repo's cache location | ||
| if os.path.isdir(self.url): | ||
| if not self.config["core"].get("remote"): | ||
| src_repo = Repo(self.url) | ||
| try: | ||
| cache_dir = src_repo.cache.local.cache_dir | ||
| finally: | ||
| src_repo.close() | ||
|
|
||
| self.config["remote"]["auto-generated-upstream"] = { | ||
| "url": cache_dir | ||
| } | ||
| self.config["core"]["remote"] = "auto-generated-upstream" | ||
| def _fix_upstream(self): | ||
| if not os.path.isdir(self.url): | ||
| return | ||
|
|
||
| remote_name = self.config["core"].get("remote") | ||
| src_repo = Repo(self.url) | ||
| try: | ||
| if remote_name: | ||
| self._fix_local_remote(src_repo, remote_name) | ||
| else: | ||
| self._add_upstream(src_repo) | ||
| finally: | ||
| src_repo.close() | ||
|
|
||
| def _fix_local_remote(self, src_repo, remote_name): | ||
| # If a remote URL is relative to the source repo, | ||
| # it will have changed upon config load and made | ||
| # relative to this new repo. Restore the old one here. | ||
| new_remote = self.config["remote"][remote_name] | ||
| old_remote = src_repo.config["remote"][remote_name] | ||
| if new_remote["url"] != old_remote["url"]: | ||
| new_remote["url"] = old_remote["url"] | ||
|
|
||
|
Comment on lines
+146
to
+148
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would at least add a comment about what is going on here, though.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Btw, should I squash all commits into a single one?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you wish. But we'll squash automatically anyways π Though if you think this is a final patch, you need to remove WIP prefix from the header.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah cool! no need then. "WIP" removed. |
||
| def _add_upstream(self, src_repo): | ||
| # Fill the empty upstream entry with a new remote pointing to the | ||
| # original repo's cache location. | ||
| cache_dir = src_repo.cache.local.cache_dir | ||
| self.config["remote"]["auto-generated-upstream"] = {"url": cache_dir} | ||
| self.config["core"]["remote"] = "auto-generated-upstream" | ||
|
|
||
|
|
||
| class ExternalGitRepo: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.