Skip to content

Commit

Permalink
Auto select the good protocol to use to fetch from github
Browse files Browse the repository at this point in the history
  • Loading branch information
pmiossec committed May 31, 2019
1 parent ef3cd4d commit 07acef9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions GitUI/CommandsDialogs/RepoHosting/ViewPullRequestsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ public partial class ViewPullRequestsForm : GitModuleForm
private readonly TranslationString _strCouldNotAddRemote = new TranslationString("Could not add remote with name {0} and URL {1}");
#endregion

private GitProtocol _cloneGitProtocol;
private IPullRequestInformation _currentPullRequestInfo;
private Dictionary<string, string> _diffCache;
private readonly IRepositoryHostPlugin _gitHoster;
private IReadOnlyList<IHostedRemote> _hostedRemotes;
private bool _isFirstLoad;
private IReadOnlyList<IPullRequestInformation> _pullRequestsInfo;
private readonly AsyncLoader _loader = new AsyncLoader();

[Obsolete("For VS designer and translation test only. Do not remove.")]
Expand Down Expand Up @@ -56,10 +61,6 @@ public ViewPullRequestsForm(GitUICommands commands, IRepositoryHostPlugin gitHos
_gitHoster = gitHoster;
}

private IReadOnlyList<IHostedRemote> _hostedRemotes;
private IReadOnlyList<IPullRequestInformation> _pullRequestsInfo;
private IPullRequestInformation _currentPullRequestInfo;

private void ViewPullRequestsForm_Load(object sender, EventArgs e)
{
_fileStatusList.SelectedIndexChanged += _fileStatusList_SelectedIndexChanged;
Expand Down Expand Up @@ -154,6 +155,8 @@ private void SetPullRequestsData(IReadOnlyList<IPullRequestInformation> infos)
private void SelectHostedRepositoryForCurrentRemote()
{
var currentRemote = Module.GetCurrentRemote();
_cloneGitProtocol = ThreadHelper.JoinableTaskFactory.Run(async () => (await Module.GetRemotesAsync())
.First(r => r.Name == currentRemote).FetchUrl.IsUrlUsingHttp() ? GitProtocol.Https : GitProtocol.Ssh);
var hostedRemote = _selectHostedRepoCB.Items.
Cast<IHostedRemote>().
FirstOrDefault(remote => remote.Name.Equals(currentRemote, StringComparison.OrdinalIgnoreCase));
Expand Down Expand Up @@ -258,6 +261,8 @@ private void _pullRequestsList_SelectedIndexChanged(object sender, EventArgs e)
return;
}

_currentPullRequestInfo.HeadRepo.CloneProtocol = _cloneGitProtocol;

_discussionWB.DocumentText = DiscussionHtmlCreator.CreateFor(_currentPullRequestInfo);
_diffViewer.ViewPatch(null);
_fileStatusList.SetDiffs();
Expand Down Expand Up @@ -329,7 +334,6 @@ private void LoadDiffPatch()
.FileAndForget();
}

private Dictionary<string, string> _diffCache;
private void SplitAndLoadDiff(string diffData)
{
_diffCache = new Dictionary<string, string>();
Expand Down Expand Up @@ -401,10 +405,12 @@ private void _addAsRemoteAndFetch_Click(object sender, EventArgs e)
var existingRepo = _hostedRemotes.FirstOrDefault(el => el.Name == remoteName);
if (existingRepo != null)
{
if (existingRepo.GetHostedRepository().CloneReadOnlyUrl != remoteUrl)
var hostedRepository = existingRepo.GetHostedRepository();
hostedRepository.CloneProtocol = _cloneGitProtocol;
if (hostedRepository.CloneReadOnlyUrl != remoteUrl)
{
MessageBox.Show(this, string.Format(_strRemoteAlreadyExist.Text,
remoteName, existingRepo.GetHostedRepository().CloneReadOnlyUrl, remoteUrl));
remoteName, hostedRepository.CloneReadOnlyUrl, remoteUrl));
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Plugins/GitHub3/GitHubRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public string ParentOwner

public string CloneReadWriteUrl => CloneProtocol == GitProtocol.Ssh ? _repo.SshUrl : _repo.CloneUrl;

public string CloneReadOnlyUrl => _repo.GitUrl;
public string CloneReadOnlyUrl => CloneProtocol == GitProtocol.Ssh ? _repo.GitUrl : _repo.CloneUrl;

public IReadOnlyList<IHostedBranch> GetBranches()
{
Expand Down

0 comments on commit 07acef9

Please sign in to comment.