public IEnumerable <GitRemote> GetRemotes(Uri repositoryUri) { if (!IsGitRepo(repositoryUri)) { return(Enumerable.Empty <GitRemote>()); } var discover = Repository.Discover(repositoryUri.AbsolutePath); var gitRemotes = new List <GitRemote>(); using (var repo = new Repository(discover)) { foreach (var remote in repo.Network.Remotes) { Uri.TryCreate(remote.Url, UriKind.Absolute, out repositoryUri); if (repositoryUri != null) { var gitRemote = new GitRemote { Name = remote.Name, Url = repositoryUri }; gitRemotes.Add(gitRemote); } else { _logger.Normal($"Cannot parse {remote.Url} to URI. SSH remote is currently not supported"); } } return(gitRemotes); } }
public void UpdateData(IRepositoryInfoCacheData data) { var now = DateTimeOffset.Now; var isUpdated = false; if (!Nullable.Equals(currentGitRemote, data.CurrentGitRemote)) { currentGitRemote = data.CurrentGitRemote ?? GitRemote.Default; isUpdated = true; } if (!Nullable.Equals(currentGitBranch, data.CurrentGitBranch)) { currentGitBranch = data.CurrentGitBranch ?? GitBranch.Default; isUpdated = true; } if (!Nullable.Equals(currentConfigRemote, data.CurrentConfigRemote)) { currentConfigRemote = data.CurrentConfigRemote ?? ConfigRemote.Default; isUpdated = true; } if (!Nullable.Equals(currentConfigBranch, data.CurrentConfigBranch)) { currentConfigBranch = data.CurrentConfigBranch ?? ConfigBranch.Default; isUpdated = true; } SaveData(now, isUpdated); }
private void Remotes_SelectedIndexChanged(object sender, EventArgs e) { if (_selectedRemote == Remotes.SelectedItem) { return; } // reset all controls and disable all buttons until we have a selection New.Enabled = Delete.Enabled = false; RemoteName.Text = string.Empty; Url.Text = string.Empty; comboBoxPushUrl.Text = string.Empty; checkBoxSepPushUrl.Checked = false; PuttySshKey.Text = string.Empty; gbMgtPanel.Text = _gbMgtPanelHeaderNew.Text; _selectedRemote = Remotes.SelectedItem as GitRemote; if (_selectedRemote == null) { return; } New.Enabled = Delete.Enabled = true; RemoteName.Text = _selectedRemote.Name; Url.Text = _selectedRemote.Url; comboBoxPushUrl.Text = _selectedRemote.PushUrl; checkBoxSepPushUrl.Checked = !string.IsNullOrEmpty(_selectedRemote.PushUrl); PuttySshKey.Text = _selectedRemote.PuttySshKey; gbMgtPanel.Text = _gbMgtPanelHeaderEdit.Text; }
public IEnumerable <GitRemote> GetRemotes(Uri repositoryUri) { if (!IsGitRepo(repositoryUri)) { return(Enumerable.Empty <GitRemote>()); } var discover = Repository.Discover(repositoryUri.AbsolutePath); var repo = new Repository(discover); var gitRemotes = new List <GitRemote>(); foreach (var remote in repo.Network.Remotes) { var gitRemote = new GitRemote { Name = remote.Name, Url = new Uri(remote.Url) }; gitRemotes.Add(gitRemote); } return(gitRemotes); }
public void SaveRemote_should_update_settings(string remoteUrl, string remotePushUrl, string remotePuttySshKey) { var remote = new GitRemote { Name = "bla", Url = remoteUrl }; _controller.SaveRemote(remote, remote.Name, remoteUrl, remotePushUrl, remotePuttySshKey); Action <string, string> ensure = (setting, value) => { setting = string.Format(setting, remote.Name); if (!string.IsNullOrWhiteSpace(value)) { _module.Received(1).SetSetting(setting, value); } else { _module.Received(1).UnsetSetting(setting); } }; ensure(SettingKeyString.RemoteUrl, remoteUrl); ensure(SettingKeyString.RemotePushUrl, remotePushUrl); ensure(SettingKeyString.RemotePuttySshKey, remotePuttySshKey); }
private void BindRemotesDropDown(string selectedRemoteName) { _NO_TRANSLATE_Remotes.SelectedIndexChanged -= RemotesUpdated; _NO_TRANSLATE_Remotes.TextUpdate -= RemotesUpdated; _NO_TRANSLATE_Remotes.Sorted = false; _NO_TRANSLATE_Remotes.DataSource = _gitRemoteController.Remotes; _NO_TRANSLATE_Remotes.DisplayMember = "Name"; _NO_TRANSLATE_Remotes.SelectedIndex = -1; _NO_TRANSLATE_Remotes.SelectedIndexChanged += RemotesUpdated; _NO_TRANSLATE_Remotes.TextUpdate += RemotesUpdated; if (selectedRemoteName.IsNullOrEmpty()) { selectedRemoteName = Module.GetSetting(string.Format(SettingKeyString.BranchRemote, _currentBranchName)); } _currentBranchRemote = _gitRemoteController.Remotes.FirstOrDefault(x => x.Name.Equals(selectedRemoteName, StringComparison.OrdinalIgnoreCase)); if (_currentBranchRemote != null) { _NO_TRANSLATE_Remotes.SelectedItem = _currentBranchRemote; } else if (_gitRemoteController.Remotes.Any()) { // we couldn't find the default assigned remote for the selected branch // it is usually gets mapped via FormRemotes -> "default pull behavior" tab // so pick the default user remote _NO_TRANSLATE_Remotes.SelectedIndex = 0; } else { _NO_TRANSLATE_Remotes.SelectedIndex = -1; } }
public void RemoveRemote_success() { var remote = new GitRemote { Name = "bla" }; _controller.RemoveRemote(remote); _module.Received(1).RemoveRemote(remote.Name); }
public static void AssertEqual(this GitRemote gitRemote, GitRemote other) { gitRemote.Name.Should().Be(other.Name); gitRemote.Url.Should().Be(other.Url); gitRemote.Login.Should().Be(other.Login); gitRemote.User.Should().Be(other.User); gitRemote.Token.Should().Be(other.Token); gitRemote.Host.Should().Be(other.Host); gitRemote.Function.Should().Be(other.Function); }
public void ShouldEqualSelf() { var gitRemote = new GitRemote("Name", "Host", "URL", GitRemoteFunction.Unknown, "User", "Login", "Token"); gitRemote.AssertEqual(gitRemote); }
public void ShouldHaveUniqueHashCode() { var gitRemote = new GitRemote("Name", "Host", "URL", GitRemoteFunction.Unknown, "User", "Login", "Token"); var gitRemote2 = new GitRemote("Name", "Host", "URL", GitRemoteFunction.Push, "User", "Login", "Token"); Assert.AreNotEqual(gitRemote.GetHashCode(), gitRemote2.GetHashCode()); }
public void ShouldNotEqualDifferentRemote() { var gitRemote = new GitRemote("Name", "Host", "URL", GitRemoteFunction.Unknown, "User", "Login", "Token"); var gitRemote2 = new GitRemote("`Name", "`Host", "`URL", GitRemoteFunction.Push, "`User", "`Login", "`Token"); gitRemote.AssertNotEqual(gitRemote2); }
public void SaveRemote_populated_remote_should_require_update_if_remoteUrl_mismatch() { const string remoteName = "a"; const string remoteUrl = "b"; const string output = "yes!"; var gitRemote = new GitRemote { Name = "old", Url = "old" }; _module.RenameRemote(Arg.Any <string>(), Arg.Any <string>()).Returns(x => output); var result = _controller.SaveRemote(gitRemote, remoteName, remoteUrl, null, null); result.UserMessage.Should().Be(output); result.ShouldUpdateRemote.Should().BeTrue(); _module.Received(1).RenameRemote(gitRemote.Name, remoteName); }
private void Remotes_SelectedIndexChanged(object sender, EventArgs e) { if (Remotes.SelectedIndices.Count > 0 && _selectedRemote == Remotes.SelectedItems[0].Tag) { return; } New.Enabled = Delete.Enabled = btnToggleState.Enabled = false; RemoteName.Text = string.Empty; Url.Text = string.Empty; comboBoxPushUrl.Text = string.Empty; checkBoxSepPushUrl.Checked = false; PuttySshKey.Text = string.Empty; gbMgtPanel.Text = _gbMgtPanelHeaderNew.Text; if (Remotes.SelectedIndices.Count < 1) { // we are here because we're adding a new remote - so no remotes selected // we just need to enable the panel so the user can enter the information _selectedRemote = null; flpnlRemoteManagement.Enabled = true; return; } // reset all controls and disable all buttons until we have a selection _selectedRemote = Remotes.SelectedItems[0].Tag as GitRemote; if (_selectedRemote == null) { return; } New.Enabled = Delete.Enabled = btnToggleState.Enabled = true; RemoteName.Text = _selectedRemote.Name; Url.Text = _selectedRemote.Url; comboBoxPushUrl.Text = _selectedRemote.PushUrl; checkBoxSepPushUrl.Checked = !string.IsNullOrEmpty(_selectedRemote.PushUrl); PuttySshKey.Text = _selectedRemote.PuttySshKey; gbMgtPanel.Text = _gbMgtPanelHeaderEdit.Text; BindBtnToggleState(_selectedRemote.Disabled); btnToggleState.Visible = true; flpnlRemoteManagement.Enabled = !_selectedRemote.Disabled; }
public async Task <IEnumerable <GitRemote> > GetRemotes(Uri repositoryUri) { if (repositoryUri == null) { throw new ArgumentNullException(nameof(repositoryUri)); } if (!await IsGitRepo(repositoryUri)) { return(Enumerable.Empty <GitRemote>()); } var discover = Repository.Discover(Uri.UnescapeDataString(repositoryUri.AbsolutePath)); var gitRemotes = new List <GitRemote>(); using (var repo = new Repository(discover)) { foreach (var remote in repo.Network.Remotes) { Uri.TryCreate(remote.Url, UriKind.Absolute, out repositoryUri); if (repositoryUri != null) { var gitRemote = new GitRemote { Name = remote.Name, Url = repositoryUri }; gitRemotes.Add(gitRemote); } else { _logger.Normal($"Cannot parse {remote.Url} to URI. SSH remote is currently not supported"); } } return(gitRemotes); } }
private void Remotes_SelectedIndexChanged(object sender, EventArgs e) { if (Remotes.SelectedIndices.Count > 0 && _selectedRemote == Remotes.SelectedItems[0].Tag) { return; } New.Enabled = Delete.Enabled = btnToggleState.Enabled = false; RemoteName.Text = string.Empty; Url.Text = string.Empty; comboBoxPushUrl.Text = string.Empty; checkBoxSepPushUrl.Checked = false; PuttySshKey.Text = string.Empty; gbMgtPanel.Text = _gbMgtPanelHeaderNew.Text; if (Remotes.SelectedIndices.Count < 1) { _selectedRemote = null; return; } // reset all controls and disable all buttons until we have a selection _selectedRemote = Remotes.SelectedItems[0].Tag as GitRemote; if (_selectedRemote == null) { return; } New.Enabled = Delete.Enabled = btnToggleState.Enabled = true; RemoteName.Text = _selectedRemote.Name; Url.Text = _selectedRemote.Url; comboBoxPushUrl.Text = _selectedRemote.PushUrl; checkBoxSepPushUrl.Checked = !string.IsNullOrEmpty(_selectedRemote.PushUrl); PuttySshKey.Text = _selectedRemote.PuttySshKey; gbMgtPanel.Text = _gbMgtPanelHeaderEdit.Text; btnToggleState.Image = _selectedRemote.Disabled ? Properties.Resources.light_bulb_icon_off_16 : Properties.Resources.light_bulb_icon_on_16; btnToggleState.Visible = true; flpnlRemoteManagement.Enabled = !_selectedRemote.Disabled; }
private void RemotesUpdated(object sender, EventArgs e) { _selectedRemote = _NO_TRANSLATE_Remotes.SelectedItem as GitRemote; if (_selectedRemote == null) { return; } if (TabControlTagBranch.SelectedTab == MultipleBranchTab) { UpdateMultiBranchView(); } EnableLoadSshButton(); // update the text box of the Remote Url combobox to show the URL of selected remote string pushUrl = _selectedRemote.PushUrl; if (pushUrl.IsNullOrEmpty()) { pushUrl = _selectedRemote.Url; } PushDestination.Text = pushUrl; if (string.IsNullOrEmpty(_NO_TRANSLATE_Branch.Text)) { // Doing this makes it pretty easy to accidentally create a branch on the remote. // But leaving it blank will do the 'default' thing, meaning all branches are pushed. // Solution: when pushing a branch that doesn't exist on the remote, ask what to do var currentBranch = new GitRef(Module, null, _currentBranchName, _selectedRemote.Name); _NO_TRANSLATE_Branch.Items.Add(currentBranch); _NO_TRANSLATE_Branch.SelectedItem = currentBranch; } BranchSelectedValueChanged(null, null); }
internal XunitSerializableGitRemote(GitRemote value) => Value = value;
public static void Matches(this GitRemote branch, GitRemote other) { Assert.AreEqual(other, branch); }
public static void AssertNotEqual(this GitRemote gitRemote, GitRemote other) { Action action = () => gitRemote.AssertEqual(other); action.ShouldThrow <AssertionException>(); }
private static void AssertRemote(string expectedName, string expectedFetchUrl, string expectedPushUrl, GitRemote remote) { Assert.Equal(expectedName, remote.Name); Assert.Equal(expectedFetchUrl, remote.FetchUrl); Assert.Equal(expectedPushUrl, remote.PushUrl); }