This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Create remote with the same name as upstream owner when viewing a PR #1752
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We should fetch from the existing remote, not simply avoid adding it!
Unless this remote already exists with different URL.
When fetching from a URL, create a remote with the same name as the owner of the target repository. If a remote with the same name already exists with a different URL, fall back to using a temporary remote with a unique name.
When deciding whether to create a new remove, compare the Urls of existing remotes ignoring any trailing ".git".
Don't create a new remote if there is an existing one with a Url that that only differs in case.
Compare to see if repository URLs are equivalent.
a5eba76 to
fdd2b48
Compare
jcansdale
commented
Jun 20, 2018
Collaborator
Author
jcansdale
left a comment
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.
There was a bug here. This should have used remote.Name not defaultOriginName.
| if (remoteHttpsString.Equals(httpsString, StringComparison.OrdinalIgnoreCase)) | ||
| if (UriString.RepositoryUrlsAreEqual(new UriString(remote.Url), cloneUrl)) | ||
| { | ||
| return Fetch(repo, defaultOriginName, refspecs); |
Collaborator
Author
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.
There was a bug here. This should have used remote.Name not defaultOriginName.
Contributor
|
This is working as expected for me @jcansdale and I don't end up with empty remotes anymore |
Collaborator
Author
|
@meaghanlewis excellent, thanks for the before and after confirmation! ✨ |
I'm not sure where they came from.
grokys
approved these changes
Jun 21, 2018
Contributor
grokys
left a comment
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.
LGTM!
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


The problem
When a user clones a forked repository and views a PR from upstream, we need to do a fetch on upstream in order to view files in the PR. Previously we were creating a temporary remote for upstream with a unique name, fetching from the remote and removing the remote afterwards.
Unfortunately git doesn't completely remove
configfile entries and users were ending up with lots of empty[remote ...]elements in their.git/config(one for every previewed PR)!For example:
What this PR does
upstream)ssh://)How to test
git clone https://github.com/jcansdale/PullRequestSandboxtype .git/configtype .git/configShould contain
[remote "grokys"]withurl = https://github.com/grokys/PullRequestSandbox.6. Checkout the PR
7.
type .git/configShould contain
[branch ...]withremote = grokys.Related
The
urlin theFetch(...)method is actually a remote name not a URL. 😢Fixes #1749
Fixes #1753