private static string GetWorkingDir(string[] args) { string workingDir = null; if (args.Length >= 3) { // there is bug in .net // while parsing command line arguments, it unescapes " incorrectly // https://github.com/gitextensions/gitextensions/issues/3489 string dirArg = args[2].TrimEnd('"'); if (!string.IsNullOrWhiteSpace(dirArg)) { if (!Directory.Exists(dirArg)) { dirArg = Path.GetDirectoryName(dirArg); } workingDir = VsrModule.TryFindGitWorkingDir(dirArg); if (Directory.Exists(workingDir)) { workingDir = Path.GetFullPath(workingDir); } // Do not add this working directory to the recent repositories. It is a nice feature, but it // also increases the startup time ////if (Module.ValidWorkingDir()) //// Repositories.RepositoryHistory.AddMostRecentRepository(Module.WorkingDir); } } if (args.Length <= 1 && workingDir == null && AppSettings.StartWithRecentWorkingDir) { if (VsrModule.IsValidVersionrWorkingDir(AppSettings.RecentWorkingDir)) { workingDir = AppSettings.RecentWorkingDir; } } if (args.Length > 1 && workingDir == null) { // If no working dir is yet found, try to find one relative to the current working directory. // This allows the `fileeditor` command to discover repository configuration which is // required for core.commentChar support. workingDir = VsrModule.TryFindGitWorkingDir(Environment.CurrentDirectory); } return(workingDir); }