Example #1
0
        public static void StartAgent([NotNull] IWin32Window owner, [NotNull] IGitModule module, [NotNull] string remote)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (module == null)
            {
                throw new ArgumentNullException(nameof(module));
            }

            if (remote == null)
            {
                throw new ArgumentNullException(nameof(remote));
            }

            if (GitSshHelpers.Plink())
            {
                if (!File.Exists(AppSettings.Pageant))
                {
                    MessageBoxes.PAgentNotFound(owner);
                }
                else
                {
                    module.StartPageantForRemote(remote);
                }
            }
        }
        protected override void SettingsToPage()
        {
            PlinkPath.Text           = AppSettings.Plink;
            PuttygenPath.Text        = AppSettings.Puttygen;
            PageantPath.Text         = AppSettings.Pageant;
            AutostartPageant.Checked = AppSettings.AutoStartPageant;

            var sshPath = AppSettings.SshPath;

            if (string.IsNullOrEmpty(sshPath))
            {
                OpenSSH.Checked = true;
            }
            else if (GitSshHelpers.Plink())
            {
                Putty.Checked = true;
            }
            else
            {
                OtherSsh.Text = sshPath;
                Other.Checked = true;
            }

            EnableSshOptions();
        }
Example #3
0
 private void EnsurePageant(string remote)
 {
     if (GitSshHelpers.Plink())
     {
         StartPageant(remote);
     }
 }
Example #4
0
 private void FormCloneLoad(object sender, EventArgs e)
 {
     if (!GitSshHelpers.Plink())
     {
         LoadSSHKey.Visible = false;
     }
 }
        protected override void PageToSettings()
        {
            AppSettings.Plink            = PlinkPath.Text;
            AppSettings.Puttygen         = PuttygenPath.Text;
            AppSettings.Pageant          = PageantPath.Text;
            AppSettings.AutoStartPageant = AutostartPageant.Checked;

            string path;

            if (OpenSSH.Checked)
            {
                path = "";
            }
            else if (Putty.Checked)
            {
                path = PlinkPath.Text;
            }
            else
            {
                // Other.Checked
                path = OtherSsh.Text;
            }

            // Set persistent settings as well as the env var used by Git
            GitSshHelpers.SetSsh(path);
            AppSettings.SshPath = path;
        }
Example #6
0
        private void application_Idle(object sender, EventArgs e)
        {
            // we need this event only once, so unwire
            Application.Idle -= application_Idle;

            // make sure only single load option is given
            if (PreselectRemoteOnLoad is not null && PreselectLocalOnLoad is not null)
            {
                throw new ArgumentException($"Only one option allowed:" +
                                            $" Either {nameof(PreselectRemoteOnLoad)} or {nameof(PreselectLocalOnLoad)}");
            }

            pnlMgtPuttySsh.Visible = GitSshHelpers.Plink();

            // if Putty SSH isn't enabled, reduce the minimum height of the form
            MinimumSize = new Size(MinimumSize.Width, pnlMgtPuttySsh.Visible ? MinimumSize.Height : MinimumSize.Height - pnlMgtPuttySsh.Height);

            // adjust width of the labels if required
            // this may be necessary if the translated labels require more space than English versions
            // the longest label is likely to be label3 (Private key file), so use it as a guide
            var widestLabelMinSize = new Size(label3.Width, 0);

            label1.MinimumSize       = label1.MaximumSize = widestLabelMinSize;       // Name
            label2.MinimumSize       = label2.MaximumSize = widestLabelMinSize;       // Url
            labelPushUrl.MinimumSize = labelPushUrl.MaximumSize = widestLabelMinSize; // Push URL

            _remotesManager = new ConfigFileRemoteSettingsManager(() => Module);

            // load the data for the very first time
            Initialize(PreselectRemoteOnLoad, PreselectLocalOnLoad);
        }
Example #7
0
        private void LoadPuttyKey()
        {
            if (!GitSshHelpers.Plink())
            {
                return;
            }

            if (File.Exists(AppSettings.Pageant))
            {
                var files = new HashSet <string>(new PathEqualityComparer());
                foreach (var remote in GetSelectedRemotes())
                {
                    var sshKeyFile = Module.GetPuttyKeyFileForRemote(remote);
                    if (!string.IsNullOrEmpty(sshKeyFile))
                    {
                        files.Add(sshKeyFile);
                    }
                }

                foreach (var sshKeyFile in files)
                {
                    if (File.Exists(sshKeyFile))
                    {
                        GitModule.StartPageantWithKey(sshKeyFile);
                    }
                }
            }
            else
            {
                MessageBoxes.PAgentNotFound(this);
            }

            return;

            IEnumerable <string> GetSelectedRemotes()
            {
                if (PullFromUrl.Checked)
                {
                    yield break;
                }

                if (IsPullAll())
                {
                    foreach (var remote in (IEnumerable <ConfigFileRemote>)_NO_TRANSLATE_Remotes.DataSource)
                    {
                        if (!string.IsNullOrWhiteSpace(remote.Name) && remote.Name != AllRemotes)
                        {
                            yield return(remote.Name);
                        }
                    }
                }
                else if (!string.IsNullOrWhiteSpace(_NO_TRANSLATE_Remotes.Text))
                {
                    yield return(_NO_TRANSLATE_Remotes.Text);
                }
            }
        }
 private void SshConfig_Click(object sender, EventArgs e)
 {
     if (GitSshHelpers.Plink())
     {
         if (SshSettingsPage.AutoFindPuttyPaths())
         {
             MessageBox.Show(this, _puttyFoundAuto.Text, _putty, MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             PageHost.GotoPage(SshSettingsPage.GetPageReference());
         }
     }
 }
Example #9
0
 private void EnsurePageant(string remote)
 {
     if (GitSshHelpers.Plink())
     {
         if (!File.Exists(AppSettings.Pageant))
         {
             MessageBoxes.PAgentNotFound(this);
         }
         else
         {
             Module.StartPageantForRemote(remote);
         }
     }
 }
        private bool CheckSSHSettings()
        {
            SshConfig.Visible = true;
            if (GitSshHelpers.Plink())
            {
                return(RenderSettingSetUnset(() => !File.Exists(AppSettings.Plink) || !File.Exists(AppSettings.Puttygen) || !File.Exists(AppSettings.Pageant),
                                             SshConfig, SshConfig_Fix,
                                             _plinkputtyGenpageantNotFound.Text,
                                             _puttyConfigured.Text));
            }

            var ssh = _sshPathLocator.Find(AppSettings.GitBinDir);

            RenderSettingSet(SshConfig, SshConfig_Fix, string.IsNullOrEmpty(ssh) ? _opensshUsed.Text : string.Format(_unknownSshClient.Text, ssh));
            return(true);
        }
        public void Initialize(ITelemetry telemetry)
        {
            string sshClient;
            var    sshPath = _sshPathLocator.Find(AppSettings.GitBinDir);

            if (string.IsNullOrEmpty(sshPath))
            {
                sshClient = "OpenSSH";
            }
            else if (GitSshHelpers.Plink())
            {
                sshClient = "PuTTY";
            }
            else
            {
                sshClient = "Other";
            }

            telemetry.Context.GlobalProperties["Git"]      = GitVersion.Current.ToString();
            telemetry.Context.GlobalProperties["SSH"]      = sshClient;
            telemetry.Context.GlobalProperties["SSH.Path"] = sshPath;
        }
Example #12
0
        protected override void PageToSettings()
        {
            AppSettings.Plink            = PlinkPath.Text;
            AppSettings.Puttygen         = PuttygenPath.Text;
            AppSettings.Pageant          = PageantPath.Text;
            AppSettings.AutoStartPageant = AutostartPageant.Checked;

            if (OpenSSH.Checked)
            {
                GitSshHelpers.SetSsh("");
            }

            if (Putty.Checked)
            {
                GitSshHelpers.SetSsh(PlinkPath.Text);
            }

            if (Other.Checked)
            {
                GitSshHelpers.SetSsh(OtherSsh.Text);
            }
        }
Example #13
0
        public static async Task <string> RunGerritCommandAsync([NotNull] IWin32Window owner, [NotNull] IGitModule module, [NotNull] string command, [NotNull] Uri fetchUrl, [NotNull] string remote, byte[] stdIn)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (module == null)
            {
                throw new ArgumentNullException(nameof(module));
            }

            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (fetchUrl == null)
            {
                throw new ArgumentNullException(nameof(fetchUrl));
            }

            if (remote == null)
            {
                throw new ArgumentNullException(nameof(remote));
            }

            StartAgent(owner, module, remote);

            var sshCmd = GitSshHelpers.Plink()
                ? AppSettings.Plink
                : SshPathLocatorInstance.Find(AppSettings.GitBinDir);

            if (string.IsNullOrEmpty(sshCmd))
            {
                sshCmd = "ssh.exe";
            }

            string hostname = fetchUrl.Host;
            string username = fetchUrl.UserInfo;
            string portFlag = GitSshHelpers.Plink() ? " -P " : " -p ";
            int    port     = fetchUrl.Port;

            if (port == -1 && fetchUrl.Scheme == "ssh")
            {
                port = 22;
            }

            var sb = new StringBuilder();

            sb.Append('"');

            if (!string.IsNullOrEmpty(username))
            {
                sb.Append(username);
                sb.Append('@');
            }

            sb.Append(hostname);
            sb.Append('"');
            sb.Append(portFlag);
            sb.Append(port);

            sb.Append(" \"");
            sb.Append(command);
            sb.Append("\"");

            return(await new Executable(sshCmd)
                   .GetOutputAsync(sb.ToString(), stdIn).ConfigureAwait(false));
        }
Example #14
0
        public override void StartProcess(string command, string arguments, string workDir, Dictionary <string, string> envVariables)
        {
            ProcessOperation operation = CommandLog.LogProcessStart(command, arguments, workDir);

            try
            {
                EnvironmentConfiguration.SetEnvironmentVariables();

                bool ssh = GitSshHelpers.UseSsh(arguments);

                KillProcess();

                // process used to execute external commands
                var outputEncoding = GitModule.SystemEncoding;
                var startInfo      = new ProcessStartInfo
                {
                    UseShellExecute        = false,
                    ErrorDialog            = false,
                    CreateNoWindow         = !ssh && !AppSettings.ShowGitCommandLine,
                    RedirectStandardInput  = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    StandardOutputEncoding = outputEncoding,
                    StandardErrorEncoding  = outputEncoding,
                    FileName         = command,
                    Arguments        = arguments,
                    WorkingDirectory = workDir
                };

                foreach (var(name, value) in envVariables)
                {
                    startInfo.EnvironmentVariables.Add(name, value);
                }

                var process = new Process {
                    StartInfo = startInfo, EnableRaisingEvents = true
                };

                process.OutputDataReceived += (sender, args) => FireDataReceived(new TextEventArgs((args.Data ?? "") + '\n'));
                process.ErrorDataReceived  += (sender, args) => FireDataReceived(new TextEventArgs((args.Data ?? "") + '\n'));
                process.Exited             += delegate
                {
                    this.InvokeAsync(
                        () =>
                    {
                        if (_process is null)
                        {
                            operation.LogProcessEnd(new Exception("Process instance is null in Exited event"));
                            return;
                        }

                        // The process is exited already, but this command waits also until all output is received.
                        // Only WaitForExit when someone is connected to the exited event. For some reason a
                        // null reference is thrown sometimes when staging/unstaging in the commit dialog when
                        // we wait for exit, probably a timing issue...
                        try
                        {
                            _process.WaitForExit();
                        }
                        catch (Exception ex)
                        {
                            operation.LogProcessEnd(ex);
                        }

                        _exitcode = _process.ExitCode;
                        operation.LogProcessEnd(_exitcode);
                        _process = null;
                        _outputThrottle?.FlushOutput();
                        FireProcessExited();
                        _outputThrottle?.Stop(flush: true);
                    }).FileAndForget();
                };

                process.Start();
                operation.SetProcessId(process.Id);
                _process = process;
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }
            catch (Exception ex)
            {
                operation.LogProcessEnd(ex);
                ex.Data.Add("command", command);
                ex.Data.Add("arguments", arguments);
                throw;
            }
        }
Example #15
0
 protected override void BeforeProcessStart()
 {
     _restart = false;
     Plink    = GitSshHelpers.Plink();
     base.BeforeProcessStart();
 }