public void SaveRemote_should_throw_if_remoteName_is_null_or_empty()
 {
     ((Action)(() => _controller.SaveRemote(null, null, "b", "c", "d"))).Should().Throw <ArgumentNullException>()
     .WithMessage("Value cannot be null.\r\nParameter name: remoteName");
     ((Action)(() => _controller.SaveRemote(null, "", "b", "c", "d"))).Should().Throw <ArgumentNullException>()
     .WithMessage("Value cannot be null.\r\nParameter name: remoteName");
     ((Action)(() => _controller.SaveRemote(null, "  ", "b", "c", "d"))).Should().Throw <ArgumentNullException>()
     .WithMessage("Value cannot be null.\r\nParameter name: remoteName");
 }
Example #2
0
        private void SaveClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(RemoteName.Text))
            {
                return;
            }

            try
            {
                // disable the control while saving
                tabControl1.Enabled = false;

                if ((string.IsNullOrEmpty(comboBoxPushUrl.Text) && checkBoxSepPushUrl.Checked) ||
                    (comboBoxPushUrl.Text.Equals(Url.Text, StringComparison.OrdinalIgnoreCase)))
                {
                    checkBoxSepPushUrl.Checked = false;
                }

                // update all other remote properties
                var result = _remoteManager.SaveRemote(_selectedRemote,
                                                       RemoteName.Text,
                                                       Url.Text,
                                                       checkBoxSepPushUrl.Checked ? comboBoxPushUrl.Text : null,
                                                       PuttySshKey.Text);

                if (!string.IsNullOrEmpty(result.UserMessage))
                {
                    MessageBox.Show(this, result.UserMessage, _gitMessage.Text);
                }

                // if the user has just created a fresh new remote
                // there may be a need to configure it
                if (result.ShouldUpdateRemote && !string.IsNullOrEmpty(Url.Text) &&
                    DialogResult.Yes == MessageBox.Show(this,
                                                        _questionAutoPullBehaviour.Text,
                                                        _questionAutoPullBehaviourCaption.Text,
                                                        MessageBoxButtons.YesNo))
                {
                    FormRemoteProcess.ShowDialog(this, "remote update");
                    _remoteManager.ConfigureRemotes(RemoteName.Text);
                }
            }
            finally
            {
                // re-enable the control and re-initialize
                tabControl1.Enabled = true;
                Initialize(RemoteName.Text);
            }
        }
Example #3
0
        private void SaveClick(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(RemoteName.Text))
            {
                return;
            }

            var remote        = RemoteName.Text.Trim();
            var remoteUrl     = Url.Text.Trim();
            var remotePushUrl = comboBoxPushUrl.Text.Trim();

            try
            {
                // disable the control while saving
                tabControl1.Enabled = false;

                if ((string.IsNullOrEmpty(remotePushUrl) && checkBoxSepPushUrl.Checked) ||
                    (!string.IsNullOrEmpty(remotePushUrl) && remotePushUrl.Equals(remoteUrl, StringComparison.OrdinalIgnoreCase)))
                {
                    checkBoxSepPushUrl.Checked = false;
                }

                if (_remoteManager.EnabledRemoteExists(remote))
                {
                    MessageBox.Show(this, string.Format(_enabledRemoteAlreadyExists.Text, remote), _gitMessage.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (_remoteManager.DisabledRemoteExists(remote))
                {
                    MessageBox.Show(this, string.Format(_disabledRemoteAlreadyExists.Text, remote), _gitMessage.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // update all other remote properties
                var result = _remoteManager.SaveRemote(_selectedRemote,
                                                       remote,
                                                       remoteUrl,
                                                       checkBoxSepPushUrl.Checked ? remotePushUrl : null,
                                                       PuttySshKey.Text);

                if (!string.IsNullOrEmpty(result.UserMessage))
                {
                    MessageBox.Show(this, result.UserMessage, _gitMessage.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                else
                {
                    ThreadHelper.JoinableTaskFactory.Run(async() =>
                    {
                        var repositoryHistory = await RepositoryHistoryManager.Remotes.LoadRecentHistoryAsync();

                        await this.SwitchToMainThreadAsync();
                        RemoteUpdate(repositoryHistory, _selectedRemote?.Url, remoteUrl);
                        if (checkBoxSepPushUrl.Checked)
                        {
                            RemoteUpdate(repositoryHistory, _selectedRemote?.PushUrl, remotePushUrl);
                        }

                        await RepositoryHistoryManager.Remotes.SaveRecentHistoryAsync(repositoryHistory);
                    });
                }

                // if the user has just created a fresh new remote
                // there may be a need to configure it
                if (result.ShouldUpdateRemote &&
                    !string.IsNullOrEmpty(remoteUrl) &&
                    MessageBox.Show(this,
                                    _questionAutoPullBehaviour.Text,
                                    _questionAutoPullBehaviourCaption.Text,
                                    MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    FormRemoteProcess.ShowDialog(this, "remote update");
                    _remoteManager.ConfigureRemotes(remote);
                    UICommands.RepoChangedNotifier.Notify();
                }
            }
            finally
            {
                // re-enable the control and re-initialize
                tabControl1.Enabled = true;
                Initialize(remote);
            }
        }
Example #4
0
        private void SaveClick(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(RemoteName.Text))
            {
                return;
            }

            var remote        = RemoteName.Text.Trim();
            var remoteUrl     = Url.Text.Trim();
            var remotePushUrl = comboBoxPushUrl.Text.Trim();

            try
            {
                // disable the control while saving
                tabControl1.Enabled = false;

                if ((string.IsNullOrEmpty(remotePushUrl) && checkBoxSepPushUrl.Checked) ||
                    remotePushUrl.Equals(remoteUrl, StringComparison.OrdinalIgnoreCase))
                {
                    checkBoxSepPushUrl.Checked = false;
                }

                // update all other remote properties
                var result = _remoteManager.SaveRemote(_selectedRemote,
                                                       remote,
                                                       remoteUrl,
                                                       checkBoxSepPushUrl.Checked ? remotePushUrl : null,
                                                       PuttySshKey.Text);

                if (!string.IsNullOrEmpty(result.UserMessage))
                {
                    MessageBox.Show(this, result.UserMessage, _gitMessage.Text);
                }
                else
                {
                    var remotes = Repositories.RemoteRepositoryHistory.Repositories;
                    RemoteUpdate(remotes, _selectedRemote?.Url, remoteUrl);
                    if (checkBoxSepPushUrl.Checked)
                    {
                        RemoteUpdate(remotes, _selectedRemote?.PushUrl, remotePushUrl);
                    }

                    Repositories.SaveSettings();
                }

                // if the user has just created a fresh new remote
                // there may be a need to configure it
                if (result.ShouldUpdateRemote &&
                    !string.IsNullOrEmpty(remoteUrl) &&
                    MessageBox.Show(this,
                                    _questionAutoPullBehaviour.Text,
                                    _questionAutoPullBehaviourCaption.Text,
                                    MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    FormRemoteProcess.ShowDialog(this, "remote update");
                    _remoteManager.ConfigureRemotes(remote);
                }
            }
            finally
            {
                // re-enable the control and re-initialize
                tabControl1.Enabled = true;
                Initialize(remote);
            }
        }