-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allow user to specify default remote when there's no remote named "origin" #1730
Allow user to specify default remote when there's no remote named "origin" #1730
Conversation
When a repository is cloned, a remote named "origin" is automatically added with the clone URL. The remote list order doesn't change when a remote is added, deleted or renamed. This means that if a user renames "origin", the first remote in the list will still contain the original clone URL.
Check first remote in list is returned when there's no "origin".
This should be used instead of assuming the default remote "origin".
Find original origin using IGitService.FindOriginalRemoteName.
The original remote name will be calculated in the method.
Throw InvalidOperationException if repository contains no remotes. Default to using GetOriginRemoteName in GetHttpRemote.
If remote isn't specified it will use a default origin remote name.
Don't hard-code origin remote as "origin".
Don't hard-code the origin name as "origin".
Should throw InvalidOperationException when no remotes.
GetOriginRemoteName should return the configured remote name.
If there is no "origin" remote, use remote from HEAD or "master" branch.
Rename method from GetOriginRemoteName to GetDefaultRemoteName.
Make sure GitService.GetUri is robust.
We need the default remote to remain consistent.
|
|
||
| Task<Remote> GetHttpRemote(IRepository repo, string remote); | ||
| /// <summary> | ||
| /// Get a <see cref="Remote"/> that used the http protocol. |
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.
Should this be uses?
| /// Get a <see cref="Remote"/> that used the http protocol. | ||
| /// </summary> | ||
| /// <param name="repository">The repository</param> | ||
| /// <param name="remote">The name of the remote or null to use original remote.</param> |
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.
What does "original remote" mean here? origin? I've never heard of that referred to as the "original remote". Would "default remote" maybe be better?
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 was supposed to find the original remote that was created when the repository was cloned. Alas libgit2 returns remotes in alphabetical order, so it's impossible to find the first created remote short of manually parsing the .git\config file. This would be too much of a hack even for my taste. 😉
| if (remoteName != null) | ||
| { | ||
| // Use remote from the "master" branch | ||
| return remoteName; |
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 doesn't seem to do what the PR says in the description. The description says "We can fall back to using the first remote as the originating remote/clone URL.", instead this uses master's remote as the default remote.
I'm not sure this is a good idea as I sometimes make master track upstream/master rather than origin/master on forks.
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.
Yes, I agree completely. Making master track upstream/master is almost certainly what people should be doing. I imagine it's pretty rare to want your own master that's independant of upstream/master.
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.
So do you agree the logic here is wrong? Why does it not do what you say it does in the description, i.e. "fall back to using the first remote as the originating remote/clone 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.
So do you agree the logic here is wrong?
Yup. Fixed in latest push.
Some users like to rename origin and delete master, so this wouldn't have worked for them anyway.
Why does it not do what you say it does in the description, i.e. "fall back to using the first remote as the originating remote/clone URL"?
It turns out that libgit2 sorts the list of remotes in alphabetical order, which completely messes up this logic. 😭
Chances are user would prefer to have master track upstream/master not origin/master!
Some users like to work without an "origin" remote defined. Allow them to set a "ghfvs.origin" config property so GHfVS knows which remote to treat as the origin.
|
@jcansdale is this PR still needed after #1752? |
|
We're planning to warn the user with a call-out notification (see #2026) rather than allowing them to explicitly name the default remote. |
What this PR does
Some users like to rename their "origin" remote so they're forced to be explicit about which repository they're pushing to. When this happend the extension wasn't able to detect their repository originated from GitHub.
This PR takes advantage of the fact the order of remotes doesn't change when a remote is renamed, added or deleted. When a user renames their "origin" remote, it will remain the first defined remote. We can fall back to using the first remote as the originating remote/clone URL.
TODO
The default remote "origin" is hard-coded in a bunch of other places:
How to test
git remote rename origin renamed_originGitHubsection doesn't appear onTeam Explorer - HomeGitHubsection now appears onTeam Explorer - HomeFixes #1729