Esempio n. 1
0
        private static void RunApplication()
        {
            string[] args = Environment.GetCommandLineArgs();

            // This form created to obtain UI synchronization context only
            using (new Form())
            {
                // Store the shared JoinableTaskContext
                ThreadHelper.JoinableTaskContext = new JoinableTaskContext();
            }

            ManagedExtensibility.Initialise(new[]
            {
                typeof(GitUI.GitExtensionsForm).Assembly,
                typeof(GitCommands.GitModule).Assembly
            });

            AppSettings.LoadSettings();

            if (EnvUtils.RunningOnWindows())
            {
                WebBrowserEmulationMode.SetBrowserFeatureControl();
                FormFixHome.CheckHomePath();
            }

            if (string.IsNullOrEmpty(AppSettings.Translation))
            {
                using FormChooseTranslation formChoose = new();
                formChoose.ShowDialog();
            }

            AppSettings.TelemetryEnabled ??= MessageBox.Show(
                null,
                ResourceManager.TranslatedStrings.TelemetryPermissionMessage,
                ResourceManager.TranslatedStrings.TelemetryPermissionCaption,
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question) == DialogResult.Yes;

            try
            {
                // Ensure we can find the git command to execute,
                // unless we are being instructed to uninstall,
                // or AppSettings.CheckSettings is set to false.
                if (!(args.Length >= 2 && args[1] == "uninstall"))
                {
                    if (!CheckSettingsLogic.SolveGitCommand())
                    {
                        if (!LocateMissingGit())
                        {
                            Environment.Exit(-1);
                            return;
                        }
                    }

                    if (AppSettings.CheckSettings)
                    {
                        GitUICommands        uiCommands         = new("");
                        CommonLogic          commonLogic        = new(uiCommands.Module);
                        CheckSettingsLogic   checkSettingsLogic = new(commonLogic);
                        SettingsPageHostMock fakePageHost       = new(checkSettingsLogic);
                        using var checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(fakePageHost);
                        if (!checklistSettingsPage.CheckSettings())
                        {
                            if (!checkSettingsLogic.AutoSolveAllSettings() || !checklistSettingsPage.CheckSettings())
                            {
                                uiCommands.StartSettingsDialog();
                            }
                        }
                    }
                }
            }
            catch
            {
                // TODO: remove catch-all
            }

            if (EnvUtils.RunningOnWindows())
            {
                MouseWheelRedirector.Active = true;
            }

            GitUICommands commands = new(GetWorkingDir(args));

            if (args.Length <= 1)
            {
                commands.StartBrowseDialog();
            }
            else
            {
                // if we are here args.Length > 1

                // Avoid replacing the ExitCode eventually set while parsing arguments,
                // i.e. assume -1 and afterwards, only set it to 0 if no error is indicated.
                Environment.ExitCode = -1;
                if (commands.RunCommand(args))
                {
                    Environment.ExitCode = 0;
                }
            }

            AppSettings.SaveSettings();
        }
Esempio n. 2
0
        public string FormatTextForDrawing(int width, string name, string oldName)
        {
            string truncatePathMethod = AppSettings.TruncatePathMethod;

            if (truncatePathMethod.Equals("fileNameOnly"))
            {
                return(FormatTextForFileNameOnly(name, oldName));
            }

            if ((!truncatePathMethod.Equals("compact", StringComparison.OrdinalIgnoreCase) || !EnvUtils.RunningOnWindows()) &&
                !truncatePathMethod.Equals("trimStart", StringComparison.OrdinalIgnoreCase))
            {
                return(FormatString(name, oldName, 0, false));
            }

            int    step = 0;
            bool   isNameBeingTruncated = true;
            int    maxStep = oldName == null ? name.Length : Math.Max(name.Length, oldName.Length) * 2;
            string result  = string.Empty;

            while (step <= maxStep)
            {
                result = FormatString(name, oldName, step, isNameBeingTruncated);

                if (_graphics.MeasureString(result, _font).Width <= width)
                {
                    break;
                }

                step++;
                isNameBeingTruncated = !isNameBeingTruncated;
            }

            return(result);
        }
Esempio n. 3
0
        private static void RunApplication()
        {
            string[] args = Environment.GetCommandLineArgs();

            // This form created to obtain UI synchronization context only
            using (new Form())
            {
                // Store the shared JoinableTaskContext
                ThreadHelper.JoinableTaskContext = new JoinableTaskContext();
            }

            AppSettings.LoadSettings();
            if (EnvUtils.RunningOnWindows())
            {
                WebBrowserEmulationMode.SetBrowserFeatureControl();
                FormFixHome.CheckHomePath();
            }

            if (string.IsNullOrEmpty(AppSettings.Translation))
            {
                using (var formChoose = new FormChooseTranslation())
                {
                    formChoose.ShowDialog();
                }
            }

            try
            {
                // Ensure we can find the git command to execute,
                // unless we are being instructed to uninstall,
                // or AppSettings.CheckSettings is set to false.
                if (!(args.Length >= 2 && args[1] == "uninstall"))
                {
                    if (!CheckSettingsLogic.SolveGitCommand())
                    {
                        if (!LocateMissingGit())
                        {
                            Environment.Exit(-1);
                            return;
                        }
                    }

                    if (AppSettings.CheckSettings)
                    {
                        var uiCommands         = new GitUICommands("");
                        var commonLogic        = new CommonLogic(uiCommands.Module);
                        var checkSettingsLogic = new CheckSettingsLogic(commonLogic);
                        var fakePageHost       = new SettingsPageHostMock(checkSettingsLogic);
                        using (var checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(fakePageHost))
                        {
                            if (!checklistSettingsPage.CheckSettings())
                            {
                                if (!checkSettingsLogic.AutoSolveAllSettings())
                                {
                                    uiCommands.StartSettingsDialog();
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                // TODO: remove catch-all
            }

            if (EnvUtils.RunningOnWindows())
            {
                MouseWheelRedirector.Active = true;
            }

            var commands = new GitUICommands(GetWorkingDir(args));

            if (args.Length <= 1)
            {
                commands.StartBrowseDialog();
            }
            else
            {
                // if we are here args.Length > 1
                commands.RunCommand(args);
            }

            AppSettings.SaveSettings();
        }
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!EnvUtils.IsMonoRuntime())
            {
                try
                {
                    NBug.Settings.UIMode = NBug.Enums.UIMode.Full;

                    // Uncomment the following after testing to see that NBug is working as configured
                    NBug.Settings.ReleaseMode = true;
                    NBug.Settings.ExitApplicationImmediately = false;
                    NBug.Settings.WriteLogToDisk             = false;
                    NBug.Settings.MaxQueuedReports           = 10;
                    NBug.Settings.StopReportingAfter         = 90;
                    NBug.Settings.SleepBeforeSend            = 30;
                    NBug.Settings.StoragePath = NBug.Enums.StoragePath.WindowsTemp;

                    AppDomain.CurrentDomain.UnhandledException += NBug.Handler.UnhandledException;
                    Application.ThreadException += NBug.Handler.ThreadException;
                }
                catch (TypeInitializationException tie)
                {
                    // is this exception caused by the configuration?
                    if (tie.InnerException != null &&
                        tie.InnerException.GetType()
                        .IsSubclassOf(typeof(System.Configuration.ConfigurationException)))
                    {
                        HandleConfigurationException((System.Configuration.ConfigurationException)tie.InnerException);
                    }
                }
            }

            string[] args = Environment.GetCommandLineArgs();
            FormSplash.ShowSplash();
            //Store here SynchronizationContext.Current, because later sometimes it can be null
            //see http://stackoverflow.com/questions/11621372/synchronizationcontext-current-is-null-in-continuation-on-the-main-ui-thread
            GitUIExtensions.UISynchronizationContext = SynchronizationContext.Current;
            Application.DoEvents();

            AppSettings.LoadSettings();
            if (EnvUtils.RunningOnWindows())
            {
                //Quick HOME check:
                FormSplash.SetAction("Checking home path...");
                Application.DoEvents();

                FormFixHome.CheckHomePath();
            }
            //Register plugins
            FormSplash.SetAction("Loading plugins...");
            Application.DoEvents();

            if (string.IsNullOrEmpty(AppSettings.Translation))
            {
                using (var formChoose = new FormChooseTranslation())
                {
                    formChoose.ShowDialog();
                }
            }

            try
            {
                if (AppSettings.CheckSettings || string.IsNullOrEmpty(AppSettings.GitCommandValue))
                {
                    FormSplash.SetAction("Checking settings...");
                    Application.DoEvents();

                    GitUICommands     uiCommands         = new GitUICommands(string.Empty);
                    var               commonLogic        = new CommonLogic(uiCommands.Module);
                    var               checkSettingsLogic = new CheckSettingsLogic(commonLogic);
                    ISettingsPageHost fakePageHost       = new SettingsPageHostMock(checkSettingsLogic);
                    using (var checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(fakePageHost))
                    {
                        if (!checklistSettingsPage.CheckSettings())
                        {
                            checkSettingsLogic.AutoSolveAllSettings();
                            uiCommands.StartSettingsDialog();
                        }
                    }
                }
            }
            catch
            {
                // TODO: remove catch-all
            }

            FormSplash.HideSplash();

            if (EnvUtils.RunningOnWindows())
            {
                MouseWheelRedirector.Active = true;
            }

            GitUICommands uCommands = new GitUICommands(GetWorkingDir(args));

            if (args.Length <= 1)
            {
                uCommands.StartBrowseDialog();
            }
            else  // if we are here args.Length > 1
            {
                uCommands.RunCommand(args);
            }

            AppSettings.SaveSettings();
        }
Esempio n. 5
0
 public ExListView()
 {
     DoubleBuffered        = true;
     IsGroupStateSupported = EnvUtils.RunningOnWindows() && Environment.OSVersion.Version.Major >= 6;
 }
Esempio n. 6
0
        private void LoadFileHistory()
        {
            FileChanges.Visible = true;

            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }

            _asyncLoader.LoadAsync(
                () => BuildFilter(),
                filter =>
            {
                FileChanges.SetFilters(filter);
                FileChanges.Load();
            });

            return;

            (string revision, string path) BuildFilter()
            {
                var fileName = FileName;

                // Replace windows path separator to Linux path separator.
                // This is needed to keep the file history working when started from file tree in
                // browse dialog.
                fileName = fileName.ToPosixPath();

                // we will need this later to look up proper casing for the file
                var fullFilePath = _fullPathResolver.Resolve(fileName);

                // The section below contains native windows (kernel32) calls
                // and breaks on Linux. Only use it on Windows. Casing is only
                // a Windows problem anyway.
                if (EnvUtils.RunningOnWindows() && File.Exists(fullFilePath))
                {
                    // grab the 8.3 file path
                    var shortPath = new StringBuilder(4096);
                    NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);

                    // use 8.3 file path to get properly cased full file path
                    var longPath = new StringBuilder(4096);
                    NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);

                    // remove the working directory and now we have a properly cased file name.
                    fileName = longPath.ToString().Substring(Module.WorkingDir.Length).ToPosixPath();
                }

                if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
                {
                    fileName = fileName.Substring(Module.WorkingDir.Length);
                }

                FileName = fileName;

                var res = (revision : (string)null, path : $" \"{fileName}\"");

                if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
                {
                    // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                    //
                    // But we can take a more complicated path to get reasonable results:
                    //  1. use git log --follow to get all previous filenames of the file we are interested in
                    //  2. use git log "list of files names" to get the history graph
                    //
                    // note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
                    //

                    var args = new ArgumentBuilder
                    {
                        "log",
                        "--format=\"%n\"",
                        "--name-only",
                        "--format",
                        GitCommandHelpers.FindRenamesAndCopiesOpts(),
                        "--",
                        fileName.Quote()
                    };

                    StringBuilder listOfFileNames;

                    using (var process = Module.RunGitCmdDetached(args.ToString(), GitModule.LosslessEncoding))
                    {
                        listOfFileNames = new StringBuilder("\"" + fileName + "\"");

                        // keep a set of the file names already seen
                        var setOfFileNames = new HashSet <string> {
                            fileName
                        };

                        string line;
                        do
                        {
                            line = process.StandardOutput.ReadLine();
                            line = GitModule.ReEncodeFileNameFromLossless(line);

                            if (!string.IsNullOrEmpty(line) && setOfFileNames.Add(line))
                            {
                                listOfFileNames.Append(" \"");
                                listOfFileNames.Append(line);
                                listOfFileNames.Append('\"');
                            }
                        }while (line != null);
                    }

                    // here we need --name-only to get the previous filenames in the revision graph
                    res.path      = listOfFileNames.ToString();
                    res.revision += " --name-only --parents" + GitCommandHelpers.FindRenamesAndCopiesOpts();
                }
                else if (AppSettings.FollowRenamesInFileHistory)
                {
                    // history of a directory
                    // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                    res.revision = " " + GitCommandHelpers.FindRenamesOpt() + " --follow --parents";
                }
                else
                {
                    // rename following disabled
                    res.revision = " --parents";
                }

                if (AppSettings.FullHistoryInFileHistory)
                {
                    res.revision = string.Concat(" --full-history --simplify-merges ", res.revision);
                }

                return(res);
            }
        }
        public FormSettings(GitUICommands commands, SettingsPageReference initalPage = null)
            : base(commands)
        {
            InitializeComponent();
            Translate();
            _translatedTitle = Text;

            settingsTreeView.SuspendLayout();

            // if form is created for translation purpose
            if (commands == null)
            {
                return;
            }

#if DEBUG
            buttonDiscard.Visible = true;
#endif

            settingsTreeView.AddSettingsPage(new GitExtensionsSettingsGroup(), null);
            SettingsPageReference gitExtPageRef = GitExtensionsSettingsGroup.GetPageReference();

            _commonLogic       = new CommonLogic(Module);
            CheckSettingsLogic = new CheckSettingsLogic(_commonLogic);

            var checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(this);
            settingsTreeView.AddSettingsPage(checklistSettingsPage, gitExtPageRef, true); // as root

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitSettingsPage>(this), gitExtPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitExtensionsSettingsPage>(this), gitExtPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <CommitDialogSettingsPage>(this), gitExtPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AppearanceSettingsPage>(this), gitExtPageRef);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <RevisionLinksSettingsPage>(this), gitExtPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ColorsSettingsPage>(this), gitExtPageRef);

            var gitConfigSettingsSettingsPage = SettingsPageBase.Create <GitConfigSettingsPage>(this);
            settingsTreeView.AddSettingsPage(gitConfigSettingsSettingsPage, gitExtPageRef);

            var gitConfigAdvancedSettingsPage = SettingsPageBase.Create <GitConfigAdvancedSettingsPage>(this);
            settingsTreeView.AddSettingsPage(gitConfigAdvancedSettingsPage, gitConfigSettingsSettingsPage.PageReference);

            var buildServerIntegrationSettingsPage = SettingsPageBase.Create <BuildServerIntegrationSettingsPage>(this);
            settingsTreeView.AddSettingsPage(buildServerIntegrationSettingsPage, gitExtPageRef);

            var sshSettingsPage = SettingsPageBase.Create <SshSettingsPage>(this);
            settingsTreeView.AddSettingsPage(sshSettingsPage, gitExtPageRef);
            checklistSettingsPage.SshSettingsPage = sshSettingsPage;

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ScriptsSettingsPage>(this), gitExtPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <HotkeysSettingsPage>(this), gitExtPageRef);

            if (EnvUtils.RunningOnWindows())
            {
                settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ShellExtensionSettingsPage>(this), gitExtPageRef);
            }

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AdvancedSettingsPage>(this), gitExtPageRef);
            SettingsPageReference advancedPageRef = AdvancedSettingsPage.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <DetailedSettingsPage>(this), gitExtPageRef);
            var detailedSettingsPage = DetailedSettingsPage.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ConfirmationsSettingsPage>(this), advancedPageRef);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <FormBrowseRepoSettingsPage>(this), detailedSettingsPage);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <DiffViewerSettingsPage>(this), detailedSettingsPage);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ToolbarSettingsPage>(this), detailedSettingsPage);

            settingsTreeView.AddSettingsPage(new PluginsSettingsGroup(), null);
            SettingsPageReference pluginsPageRef = PluginsSettingsGroup.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <PluginRootIntroductionPage>(this), pluginsPageRef, true); // as root
            foreach (var gitPlugin in LoadedPlugins.Plugins)
            {
                var settingsPage = PluginSettingsPage.CreateSettingsPageFromPlugin(this, gitPlugin);
                settingsTreeView.AddSettingsPage(settingsPage, pluginsPageRef);
            }

            settingsTreeView.GotoPage(initalPage);
            settingsTreeView.ResumeLayout();

            this.AdjustForDpiScaling();
        }
Esempio n. 8
0
        public static bool SolveGitCommand(string?possibleNewPath = null)
        {
            if (EnvUtils.RunningOnWindows())
            {
                foreach (var command in GetWindowsCommandLocations())
                {
                    if (TestGitCommand(command))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            AppSettings.GitCommandValue = "git";
            return(TestGitCommand(AppSettings.GitCommandValue));

            bool TestGitCommand(string command)
            {
                try
                {
                    string output = new Executable(command).GetOutput();
                    if (!string.IsNullOrEmpty(output))
                    {
                        if (command is not null)
                        {
                            AppSettings.GitCommandValue = command;
                            return(true);
                        }
                    }
                }
                catch (Exception)
                {
                    // Ignore expection, we are trying to find a way to execute git.exe
                }

                return(false);
            }

            IEnumerable <string> GetWindowsCommandLocations()
            {
                if (File.Exists(possibleNewPath))
                {
                    yield return(possibleNewPath !);
                }

                if (File.Exists(AppSettings.GitCommandValue))
                {
                    yield return(AppSettings.GitCommandValue);
                }

                foreach (var path in GetGitLocations())
                {
                    if (Directory.Exists(path + @"bin\"))
                    {
                        yield return(path + @"bin\git.exe");
                    }
                }

                foreach (var path in GetGitLocations())
                {
                    if (Directory.Exists(path + @"cmd\"))
                    {
                        yield return(path + @"cmd\git.exe");

                        yield return(path + @"cmd\git.cmd");
                    }
                }

                yield return("git");

                yield return("git.cmd");
            }
        }
Esempio n. 9
0
        private string BuildFilter(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            //Replace windows path separator to Linux path separator.
            //This is needed to keep the file history working when started from file tree in
            //browse dialog.
            fileName = fileName.Replace('\\', '/');

            // we will need this later to look up proper casing for the file
            var fullFilePath = Path.Combine(Module.WorkingDir, fileName);

            //The section below contains native windows (kernel32) calls
            //and breaks on Linux. Only use it on Windows. Casing is only
            //a Windows problem anyway.
            if (EnvUtils.RunningOnWindows() && File.Exists(fullFilePath))
            {
                // grab the 8.3 file path
                var shortPath = new StringBuilder(4096);
                NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);

                // use 8.3 file path to get properly cased full file path
                var longPath = new StringBuilder(4096);
                NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);

                // remove the working dir and now we have a properly cased file name.
                fileName = longPath.ToString().Substring(Module.WorkingDir.Length);
            }

            if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
            {
                fileName = fileName.Substring(Module.WorkingDir.Length);
            }

            FileName = fileName;

            string filter;

            if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
            {
                // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                //
                // But we can take a more complicated path to get reasonable results:
                //  1. use git log --follow to get all previous filenames of the file we are interested in
                //  2. use git log "list of files names" to get the history graph
                //
                // note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
                //

                string  arg = "log --format=\"%n\" --name-only --follow -- \"" + fileName + "\"";
                Process p   = Module.RunGitCmdDetached(arg);

                // the sequence of (quoted) file names - start with the initial filename for the search.
                var listOfFileNames = new StringBuilder("\"" + fileName + "\"");

                // keep a set of the file names already seen
                var setOfFileNames = new HashSet <string> {
                    fileName
                };

                string line;
                do
                {
                    line = p.StandardOutput.ReadLine();

                    if (!string.IsNullOrEmpty(line) && setOfFileNames.Add(line))
                    {
                        listOfFileNames.Append(" \"");
                        listOfFileNames.Append(line);
                        listOfFileNames.Append('\"');
                    }
                } while (line != null);

                // here we need --name-only to get the previous filenames in the revision graph
                filter = " -M -C --name-only --parents -- " + listOfFileNames;
            }
            else
            {
                // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                filter = " --parents -- \"" + fileName + "\"";
            }

            if (AppSettings.FullHistoryInFileHistory)
            {
                filter = string.Concat(" --full-history --simplify-by-decoration ", filter);
            }

            return(filter);
        }
Esempio n. 10
0
        public FormSettings([NotNull] GitUICommands commands, SettingsPageReference initialPage = null)
            : base(commands)
        {
            InitializeComponent();
            _translatedTitle = Text;

            settingsTreeView.SuspendLayout();

#if DEBUG
            buttonDiscard.Visible = true;
#endif

            _commonLogic       = new CommonLogic(Module);
            CheckSettingsLogic = new CheckSettingsLogic(_commonLogic);

            var checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(this);

            // Git Extensions settings
            settingsTreeView.AddSettingsPage(new GitExtensionsSettingsGroup(), null, Images.GitExtensionsLogo16);
            var gitExtPageRef = GitExtensionsSettingsGroup.GetPageReference();
            settingsTreeView.AddSettingsPage(checklistSettingsPage, gitExtPageRef, icon: null, asRoot: true);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GeneralSettingsPage>(this), gitExtPageRef, Images.GeneralSettings);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AppearanceSettingsPage>(this), gitExtPageRef, Images.Appearance);
            var appearanceSettingsPage = AppearanceSettingsPage.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ColorsSettingsPage>(this), appearanceSettingsPage, Images.Colors);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AppearanceFontsSettingsPage>(this), appearanceSettingsPage, Images.Font.AdaptLightness());

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <RevisionLinksSettingsPage>(this), gitExtPageRef, Images.Link.AdaptLightness());
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <BuildServerIntegrationSettingsPage>(this), gitExtPageRef, Images.Integration);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ScriptsSettingsPage>(this), gitExtPageRef, Images.Console);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <HotkeysSettingsPage>(this), gitExtPageRef, Images.Hotkey);

            if (EnvUtils.RunningOnWindows())
            {
                settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ShellExtensionSettingsPage>(this), gitExtPageRef, Images.ShellExtensions);
            }

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AdvancedSettingsPage>(this), gitExtPageRef, Images.AdvancedSettings);
            SettingsPageReference advancedPageRef = AdvancedSettingsPage.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ConfirmationsSettingsPage>(this), advancedPageRef, Images.BisectGood);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <DetailedSettingsPage>(this), gitExtPageRef, Images.Settings);
            var detailedSettingsPage = DetailedSettingsPage.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <FormBrowseRepoSettingsPage>(this), detailedSettingsPage, Images.BranchFolder);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <CommitDialogSettingsPage>(this), detailedSettingsPage, Images.CommitSummary);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <DiffViewerSettingsPage>(this), detailedSettingsPage, Images.Diff);

            var sshSettingsPage = SettingsPageBase.Create <SshSettingsPage>(this);
            settingsTreeView.AddSettingsPage(sshSettingsPage, gitExtPageRef, Images.Key);
            checklistSettingsPage.SshSettingsPage = sshSettingsPage;

            // Git settings
            settingsTreeView.AddSettingsPage(new GitSettingsGroup(), null, Images.GitLogo16);
            var gitPageRef = GitSettingsGroup.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitSettingsPage>(this), gitPageRef, Images.FolderOpen);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitConfigSettingsPage>(this), gitPageRef, Images.GeneralSettings);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitConfigAdvancedSettingsPage>(this), gitPageRef, Images.AdvancedSettings);

            // Plugins settings
            settingsTreeView.AddSettingsPage(new PluginsSettingsGroup(), null, Images.Plugin);
            SettingsPageReference pluginsPageRef = PluginsSettingsGroup.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <PluginRootIntroductionPage>(this), pluginsPageRef, icon: null, asRoot: true);

            var pluginEntries = PluginRegistry.Plugins
                                .Where(p => p.HasSettings)
                                .Select(plugin => (Plugin: plugin, Page: PluginSettingsPage.CreateSettingsPageFromPlugin(this, plugin)))
                                .OrderBy(entry => entry.Page.GetTitle(), StringComparer.CurrentCultureIgnoreCase);

            foreach (var entry in pluginEntries)
            {
                settingsTreeView.AddSettingsPage(entry.Page, pluginsPageRef, entry.Plugin.Icon as Bitmap);
            }

            if (initialPage == null && _lastSelectedSettingsPageType != null)
            {
                initialPage = new SettingsPageReferenceByType(_lastSelectedSettingsPageType);
            }

            settingsTreeView.GotoPage(initialPage);
            settingsTreeView.ResumeLayout();

            InitializeComplete();
        }
        private FixedFilterTuple BuildFilter(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            //Replace windows path separator to Linux path separator.
            //This is needed to keep the file history working when started from file tree in
            //browse dialog.
            fileName = fileName.Replace('\\', '/');

            // we will need this later to look up proper casing for the file
            var fullFilePath = Path.Combine(Module.WorkingDir, fileName);

            //The section below contains native windows (kernel32) calls
            //and breaks on Linux. Only use it on Windows. Casing is only
            //a Windows problem anyway.
            if (EnvUtils.RunningOnWindows() && File.Exists(fullFilePath))
            {
                // grab the 8.3 file path
                var shortPath = new StringBuilder(4096);
                NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);

                // use 8.3 file path to get properly cased full file path
                var longPath = new StringBuilder(4096);
                NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);

                // remove the working directory and now we have a properly cased file name.
                fileName = longPath.ToString().Substring(Module.WorkingDir.Length);
            }

            if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
            {
                fileName = fileName.Substring(Module.WorkingDir.Length);
            }

            FileName = fileName;

            FixedFilterTuple res = new FixedFilterTuple();

            if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
            {
                // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                FollowParentRewriter hrw = new FollowParentRewriter(fileName, delegate(string arg){
                    Process p = Module.RunGitCmdDetached(arg);
                    return(p.StandardOutput);
                });
                // here we need --name-only to get the previous filenames in the revision graph
                if (hrw.RewriteNecessary)
                {
                    res.Rewriter = hrw;
                    res.Filter   = " -M -C --name-only --follow -- \"" + fileName + "\"";
                }
                else
                {
                    res.Filter = " -M -C --name-only --parents -- \"" + fileName + "\"";
                }
            }
            else
            {
                // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                res.Filter = " --follow --parents -- \"" + fileName + "\"";
            }

            if (AppSettings.FullHistoryInFileHistory)
            {
                res.Filter = string.Concat(" --full-history --simplify-by-decoration ", res.Filter);
            }

            return(res);
        }
        // This file is dedicated to init logic for FormBrowse menus and toolbars

        private void InitMenusAndToolbars(string?revFilter, string?pathFilter)
        {
            commandsToolStripMenuItem.DropDownOpening += CommandsToolStripMenuItem_DropDownOpening;

            InitFilters();

            toolPanel.TopToolStripPanel.MouseClick += (s, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    _formBrowseMenus.ShowToolStripContextMenu(Cursor.Position);
                }
            };

            new ToolStripItem[]
            {
                translateToolStripMenuItem,
                recoverLostObjectsToolStripMenuItem,
                branchSelect,
                toolStripButtonPull,
                pullToolStripMenuItem,
                pullToolStripMenuItem1,
                mergeToolStripMenuItem,
                rebaseToolStripMenuItem1,
                fetchToolStripMenuItem,
                fetchAllToolStripMenuItem,
                fetchPruneAllToolStripMenuItem,
                toolStripButtonPush,
                pushToolStripMenuItem,
                branchToolStripMenuItem,
            }.ForEach(ColorHelper.AdaptImageLightness);

            if (!EnvUtils.RunningOnWindows())
            {
                toolStripSeparator6.Visible    = false;
                PuTTYToolStripMenuItem.Visible = false;
            }

            pullToolStripMenuItem1.Tag         = AppSettings.PullAction.None;
            mergeToolStripMenuItem.Tag         = AppSettings.PullAction.Merge;
            rebaseToolStripMenuItem1.Tag       = AppSettings.PullAction.Rebase;
            fetchToolStripMenuItem.Tag         = AppSettings.PullAction.Fetch;
            fetchAllToolStripMenuItem.Tag      = AppSettings.PullAction.FetchAll;
            fetchPruneAllToolStripMenuItem.Tag = AppSettings.PullAction.FetchPruneAll;

            Color toolForeColor = SystemColors.WindowText;

            BackColor = SystemColors.Window;
            ForeColor = toolForeColor;
            mainMenuStrip.ForeColor = toolForeColor;
            InitToolStripStyles(toolForeColor, Color.Transparent);

            UpdateCommitButtonAndGetBrush(status: null, AppSettings.ShowGitStatusInBrowseToolbar);

            FillNextPullActionAsDefaultToolStripMenuItems();
            RefreshDefaultPullAction();

            FillUserShells(defaultShell: BashShell.ShellName);

            WorkaroundToolbarLocationBug();

            return;

            void InitToolStripStyles(Color toolForeColor, Color toolBackColor)
            {
                toolPanel.TopToolStripPanel.BackColor = toolBackColor;
                toolPanel.TopToolStripPanel.ForeColor = toolForeColor;

                mainMenuStrip.BackColor = toolBackColor;

                ToolStripMain.BackColor = toolBackColor;
                ToolStripMain.ForeColor = toolForeColor;

                ToolStripFilters.BackColor = toolBackColor;
                ToolStripFilters.ForeColor = toolForeColor;
                ToolStripFilters.InitToolStripStyles(toolForeColor, toolBackColor);

                ToolStripScripts.BackColor = toolBackColor;
                ToolStripScripts.ForeColor = toolForeColor;
            }

            void InitFilters()
            {
                // ToolStripFilters.UpdateBranchFilterItems() is init in UICommands_PostRepositoryChanged

                if (!string.IsNullOrWhiteSpace(revFilter))
                {
                    ToolStripFilters.SetRevisionFilter(revFilter);
                }

                if (!string.IsNullOrWhiteSpace(pathFilter))
                {
                    SetPathFilter(pathFilter);
                }
            }

            void WorkaroundToolbarLocationBug()
            {
                // Layout engine bug (?) which may change the order of toolbars
                // if the 1st one becomes longer than the 2nd toolbar's Location.X
                // the layout engine will be place the 2nd toolbar first

                // 1. Clear all toolbars
                toolPanel.TopToolStripPanel.Controls.Clear();

                // 2. Add all the toolbars back in a reverse order, every added toolbar pushing existing ones to the right
                ToolStrip[] toolStrips = new[] { ToolStripScripts, ToolStripFilters, ToolStripMain };
                foreach (ToolStrip toolStrip in toolStrips)
                {
                    toolPanel.TopToolStripPanel.Controls.Add(toolStrip);
                }

#if DEBUG
                // 3. Assert all toolbars on the same row
                foreach (ToolStrip toolStrip in toolStrips)
                {
                    Debug.Assert(toolStrip.Top == 0, $"{toolStrip.Name} must be placed on the 1st row");
                }

                // 4. Assert the correct order of toolbars
                for (int i = toolStrips.Length - 1; i > 0; i--)
                {
                    Debug.Assert(toolStrips[i].Left < toolStrips[i - 1].Left, $"{toolStrips[i - 1].Name} must be placed before {toolStrips[i].Name}");
                }
#endif
            }
        }
Esempio n. 13
0
        protected override void OnRuntimeLoad(EventArgs e)
        {
            base.OnRuntimeLoad(e);

            settingsTreeView.SuspendLayout();

            ChecklistSettingsPage checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(this);

            // Git Extensions settings
            settingsTreeView.AddSettingsPage(new GitExtensionsSettingsGroup(), null, Images.GitExtensionsLogo16);
            var gitExtPageRef = GitExtensionsSettingsGroup.GetPageReference();

            settingsTreeView.AddSettingsPage(checklistSettingsPage, gitExtPageRef, icon: null, asRoot: true);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GeneralSettingsPage>(this), gitExtPageRef, Images.GeneralSettings);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AppearanceSettingsPage>(this), gitExtPageRef, Images.Appearance);
            var appearanceSettingsPage = AppearanceSettingsPage.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ColorsSettingsPage>(this), appearanceSettingsPage, Images.Colors);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AppearanceFontsSettingsPage>(this), appearanceSettingsPage, Images.Font.AdaptLightness());

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <RevisionLinksSettingsPage>(this), gitExtPageRef, Images.Link.AdaptLightness());
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <BuildServerIntegrationSettingsPage>(this), gitExtPageRef, Images.Integration);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ScriptsSettingsPage>(this), gitExtPageRef, Images.Console);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <HotkeysSettingsPage>(this), gitExtPageRef, Images.Hotkey);

            if (EnvUtils.RunningOnWindows())
            {
                settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ShellExtensionSettingsPage>(this), gitExtPageRef, Images.ShellExtensions);
            }

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AdvancedSettingsPage>(this), gitExtPageRef, Images.AdvancedSettings);
            SettingsPageReference advancedPageRef = AdvancedSettingsPage.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ConfirmationsSettingsPage>(this), advancedPageRef, Images.BisectGood);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <DetailedSettingsPage>(this), gitExtPageRef, Images.Settings);
            var detailedSettingsPage = DetailedSettingsPage.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <FormBrowseRepoSettingsPage>(this), detailedSettingsPage, Images.BranchFolder);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <CommitDialogSettingsPage>(this), detailedSettingsPage, Images.CommitSummary);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <DiffViewerSettingsPage>(this), detailedSettingsPage, Images.Diff);

            var sshSettingsPage = SettingsPageBase.Create <SshSettingsPage>(this);

            settingsTreeView.AddSettingsPage(sshSettingsPage, gitExtPageRef, Images.Key);
            checklistSettingsPage.SshSettingsPage = sshSettingsPage;

            // Git settings
            settingsTreeView.AddSettingsPage(new GitSettingsGroup(), null, Images.GitLogo16);
            var gitPageRef = GitSettingsGroup.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitSettingsPage>(this), gitPageRef, Images.FolderOpen);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitConfigSettingsPage>(this), gitPageRef, Images.GeneralSettings);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitConfigAdvancedSettingsPage>(this), gitPageRef, Images.AdvancedSettings);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitRootIntroductionPage>(this), gitPageRef, icon: null, asRoot: true);

            // Plugins settings
            settingsTreeView.AddSettingsPage(new PluginsSettingsGroup(), null, Images.Plugin);
            SettingsPageReference pluginsPageRef = PluginsSettingsGroup.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <PluginRootIntroductionPage>(this), pluginsPageRef, icon: null, asRoot: true);

            lock (PluginRegistry.Plugins)
            {
                var pluginEntries = PluginRegistry.Plugins
                                    .Where(p => p.HasSettings)
                                    .Select(plugin => (Plugin: plugin, Page: PluginSettingsPage.CreateSettingsPageFromPlugin(this, plugin)))
                                    .OrderBy(entry => entry.Page.GetTitle(), StringComparer.CurrentCultureIgnoreCase);

                foreach (var entry in pluginEntries)
                {
                    settingsTreeView.AddSettingsPage(entry.Page, pluginsPageRef, entry.Plugin.Icon as Bitmap);
                }
            }

            settingsTreeView.ResumeLayout();
        }
Esempio n. 14
0
        private static void RunApplication()
        {
            string[] args = Environment.GetCommandLineArgs();

            // This form created for obtain UI synchronization context only
            using (new Form())
            {
                // Store the shared JoinableTaskContext
                ThreadHelper.JoinableTaskContext = new JoinableTaskContext();
            }

            AppSettings.LoadSettings();
            if (EnvUtils.RunningOnWindows())
            {
                WebBrowserEmulationMode.SetBrowserFeatureControl();
                FormFixHome.CheckHomePath();
            }

            if (string.IsNullOrEmpty(AppSettings.Translation))
            {
                using (var formChoose = new FormChooseTranslation())
                {
                    formChoose.ShowDialog();
                }
            }

            try
            {
                if (!(args.Length >= 2 && args[1] == "uninstall") &&
                    (AppSettings.CheckSettings ||
                     string.IsNullOrEmpty(AppSettings.GitCommandValue) ||
                     !File.Exists(AppSettings.GitCommandValue)))
                {
                    GitUICommands     uiCommands         = new GitUICommands(string.Empty);
                    var               commonLogic        = new CommonLogic(uiCommands.Module);
                    var               checkSettingsLogic = new CheckSettingsLogic(commonLogic);
                    ISettingsPageHost fakePageHost       = new SettingsPageHostMock(checkSettingsLogic);
                    using (var checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(fakePageHost))
                    {
                        if (!checklistSettingsPage.CheckSettings())
                        {
                            if (!checkSettingsLogic.AutoSolveAllSettings())
                            {
                                uiCommands.StartSettingsDialog();
                            }
                        }
                    }
                }
            }
            catch
            {
                // TODO: remove catch-all
            }

            if (EnvUtils.RunningOnWindows())
            {
                MouseWheelRedirector.Active = true;
            }

            GitUICommands commands = new GitUICommands(GetWorkingDir(args));

            if (args.Length <= 1)
            {
                commands.StartBrowseDialog(startWithDashboard: !AppSettings.StartWithRecentWorkingDir);
            }
            else
            {
                // if we are here args.Length > 1
                commands.RunCommand(args);
            }

            AppSettings.SaveSettings();
        }
Esempio n. 15
0
        public FormSettings([NotNull] GitUICommands commands, SettingsPageReference initialPage = null)
            : base(commands)
        {
            InitializeComponent();
            _translatedTitle = Text;

            settingsTreeView.SuspendLayout();

#if DEBUG
            buttonDiscard.Visible = true;
#endif

            _commonLogic       = new CommonLogic(Module);
            CheckSettingsLogic = new CheckSettingsLogic(_commonLogic);

            var checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(this);

            // Git Extensions settings
            settingsTreeView.AddSettingsPage(new GitExtensionsSettingsGroup(), null);
            var gitExtPageRef = GitExtensionsSettingsGroup.GetPageReference();
            settingsTreeView.AddSettingsPage(checklistSettingsPage, gitExtPageRef, true); // as root

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GeneralSettingsPage>(this), gitExtPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AppearanceSettingsPage>(this), gitExtPageRef);
            var appearanceSettingsPage = AppearanceSettingsPage.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ColorsSettingsPage>(this), appearanceSettingsPage);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AppearanceFontsSettingsPage>(this), appearanceSettingsPage);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <RevisionLinksSettingsPage>(this), gitExtPageRef);

            var buildServerIntegrationSettingsPage = SettingsPageBase.Create <BuildServerIntegrationSettingsPage>(this);
            settingsTreeView.AddSettingsPage(buildServerIntegrationSettingsPage, gitExtPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ScriptsSettingsPage>(this), gitExtPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <HotkeysSettingsPage>(this), gitExtPageRef);

            if (EnvUtils.RunningOnWindows())
            {
                settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ShellExtensionSettingsPage>(this), gitExtPageRef);
            }

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <AdvancedSettingsPage>(this), gitExtPageRef);
            SettingsPageReference advancedPageRef = AdvancedSettingsPage.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <ConfirmationsSettingsPage>(this), advancedPageRef);

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <DetailedSettingsPage>(this), gitExtPageRef);
            var detailedSettingsPage = DetailedSettingsPage.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <FormBrowseRepoSettingsPage>(this), detailedSettingsPage);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <CommitDialogSettingsPage>(this), detailedSettingsPage);
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <DiffViewerSettingsPage>(this), detailedSettingsPage);

            var sshSettingsPage = SettingsPageBase.Create <SshSettingsPage>(this);
            settingsTreeView.AddSettingsPage(sshSettingsPage, gitExtPageRef);
            checklistSettingsPage.SshSettingsPage = sshSettingsPage;

            // Git settings
            settingsTreeView.AddSettingsPage(new GitSettingsGroup(), null);
            var gitPageRef = GitSettingsGroup.GetPageReference();

            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <GitSettingsPage>(this), gitPageRef);

            var gitConfigSettingsSettingsPage = SettingsPageBase.Create <GitConfigSettingsPage>(this);
            settingsTreeView.AddSettingsPage(gitConfigSettingsSettingsPage, gitPageRef);

            var gitConfigAdvancedSettingsPage = SettingsPageBase.Create <GitConfigAdvancedSettingsPage>(this);
            settingsTreeView.AddSettingsPage(gitConfigAdvancedSettingsPage, gitPageRef);

            // Plugins settings
            settingsTreeView.AddSettingsPage(new PluginsSettingsGroup(), null);
            SettingsPageReference pluginsPageRef = PluginsSettingsGroup.GetPageReference();
            settingsTreeView.AddSettingsPage(SettingsPageBase.Create <PluginRootIntroductionPage>(this), pluginsPageRef, true); // as root
            foreach (var gitPlugin in PluginRegistry.Plugins)
            {
                var settingsPage = PluginSettingsPage.CreateSettingsPageFromPlugin(this, gitPlugin);
                settingsTreeView.AddSettingsPage(settingsPage, pluginsPageRef);
            }

            if (initialPage == null && _lastSelectedSettingsPageType != null)
            {
                initialPage = new SettingsPageReferenceByType(_lastSelectedSettingsPageType);
            }

            settingsTreeView.GotoPage(initialPage);
            settingsTreeView.ResumeLayout();

            InitializeComplete();
        }
Esempio n. 16
0
        public static bool SolveGitCommand(string possibleNewPath = null)
        {
            if (EnvUtils.RunningOnWindows())
            {
                foreach (var command in GetWindowsCommandLocations())
                {
                    if (TestGitCommand(command))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            AppSettings.GitCommandValue = "vsr";
            return(TestGitCommand(AppSettings.GitCommandValue));

            bool TestGitCommand(string command)
            {
                try
                {
                    string output = new Executable(command).GetOutput();
                    if (!string.IsNullOrEmpty(output))
                    {
                        if (command != null)
                        {
                            AppSettings.GitCommandValue = command;
                            return(true);
                        }
                    }
                }
                catch (Exception)
                {
                    // Ignore expection, we are trying to find a way to execute git.exe
                }

                return(false);
            }

            IEnumerable <string> GetWindowsCommandLocations()
            {
                if (File.Exists(possibleNewPath))
                {
                    yield return(possibleNewPath);
                }

                if (File.Exists(AppSettings.GitCommandValue))
                {
                    yield return(AppSettings.GitCommandValue);
                }

                var output = new Executable("where").GetOutput("vsr");

                if (!string.IsNullOrEmpty(output))
                {
                    var results = output.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var path in results)
                    {
                        yield return(path);
                    }
                }
            }
        }