protected override void SettingsToPage()
        {
            EnvironmentConfiguration.SetEnvironmentVariables();
            homeIsSetToLabel.Text = string.Concat(_homeIsSetToString.Text, " ", EnvironmentConfiguration.GetHomeDir());

            GitPath.Text    = AppSettings.GitCommandValue;
            GitBinPath.Text = AppSettings.GitBinDir;
        }
        public static ConfigFileSettings CreateGlobal(ConfigFileSettings lowerPriority, bool allowCache = true)
        {
            string configPath = Path.Combine(EnvironmentConfiguration.GetHomeDir(), ".config", "git", "config");

            if (!File.Exists(configPath))
            {
                configPath = Path.Combine(EnvironmentConfiguration.GetHomeDir(), ".gitconfig");
            }

            return(new ConfigFileSettings(lowerPriority,
                                          ConfigFileSettingsCache.Create(configPath, false, allowCache)));
        }
示例#3
0
        /// <summary>
        /// Determine what file contains the global ignores.
        /// </summary>
        /// <remarks>
        /// According to https://git-scm.com/docs/git-config, the following are checked in order:
        ///  - core.excludesFile configuration,
        ///  - $XDG_CONFIG_HOME/git/ignore, if XDG_CONFIG_HOME is set and not empty,
        ///  - $HOME/.config/git/ignore.
        ///  </remarks>
        private string DetermineGlobalIgnoreFilePath()
        {
            string globalExcludeFile = Module.GetEffectiveSetting("core.excludesFile");

            if (!string.IsNullOrWhiteSpace(globalExcludeFile))
            {
                return(Path.GetFullPath(globalExcludeFile));
            }

            string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");

            if (!string.IsNullOrWhiteSpace(xdgConfigHome))
            {
                return(Path.GetFullPath(Path.Combine(xdgConfigHome, "git/ignore")));
            }

            return(Path.GetFullPath(Path.Combine(EnvironmentConfiguration.GetHomeDir(), ".config/git/ignore")));
        }
        private static IReadOnlyList <string> GetDirectories(GitModule currentModule, IEnumerable <Repository> repositoryHistory)
        {
            List <string> directories = new List <string>();

            if (AppSettings.DefaultCloneDestinationPath.IsNotNullOrWhitespace())
            {
                directories.Add(PathUtil.EnsureTrailingPathSeparator(AppSettings.DefaultCloneDestinationPath));
            }

            if (!string.IsNullOrWhiteSpace(currentModule?.WorkingDir))
            {
                DirectoryInfo di = new DirectoryInfo(currentModule.WorkingDir);
                if (di.Parent != null)
                {
                    directories.Add(PathUtil.EnsureTrailingPathSeparator(di.Parent.FullName));
                }
            }

            directories.AddRange(repositoryHistory.Select(r => r.Path));

            if (directories.Count == 0)
            {
                if (AppSettings.RecentWorkingDir.IsNotNullOrWhitespace())
                {
                    directories.Add(PathUtil.EnsureTrailingPathSeparator(AppSettings.RecentWorkingDir));
                }

                string homeDir = EnvironmentConfiguration.GetHomeDir();
                if (homeDir.IsNotNullOrWhitespace())
                {
                    directories.Add(PathUtil.EnsureTrailingPathSeparator(homeDir));
                }
            }

            return(directories.Distinct().ToList());
        }
        private void StartWatchingChanges(string workTreePath, string gitDirPath)
        {
            // reset status info, it was outdated
            GitWorkingDirectoryStatusChanged?.Invoke(this, new GitWorkingDirectoryStatusEventArgs());

            try
            {
                if (!string.IsNullOrEmpty(workTreePath) && Directory.Exists(workTreePath) &&
                    !string.IsNullOrEmpty(gitDirPath) && Directory.Exists(gitDirPath))
                {
                    _workTreeWatcher.Path = workTreePath;
                    _gitDirWatcher.Path   = gitDirPath;
                    _globalIgnoreFilePath = DetermineGlobalIgnoreFilePath();
                    string globalIgnoreDirectory = Path.GetDirectoryName(_globalIgnoreFilePath);
                    if (Directory.Exists(globalIgnoreDirectory))
                    {
                        _globalIgnoreWatcher.Path = globalIgnoreDirectory;
                    }

                    _gitPath               = Path.GetDirectoryName(gitDirPath);
                    _submodulesPath        = Path.Combine(_gitPath, "modules");
                    _currentUpdateInterval = MinUpdateInterval;
                    _previousUpdateTime    = 0;
                    _ignoredFilesAreStale  = true;
                    _ignoredFiles          = new HashSet <string>();
                    _ignoredFilesTimer.Stop();
                    _ignoredFilesTimer.Start();
                    CurrentStatus = GitStatusMonitorState.Running;
                }
                else
                {
                    CurrentStatus = GitStatusMonitorState.Stopped;
                }
            }
            catch
            {
                // no-op
            }

            return;

            string DetermineGlobalIgnoreFilePath()
            {
                // According to https://git-scm.com/docs/git-config, the following are checked in order:
                //  - core.excludesFile configuration,
                //  - $XDG_CONFIG_HOME/git/ignore, if XDG_CONFIG_HOME is set and not empty,
                //  - $HOME/.config/git/ignore.

                string globalExcludeFile = Module.GetEffectiveSetting("core.excludesFile");

                if (!string.IsNullOrWhiteSpace(globalExcludeFile))
                {
                    return(Path.GetFullPath(globalExcludeFile));
                }

                string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");

                if (!string.IsNullOrWhiteSpace(xdgConfigHome))
                {
                    return(Path.GetFullPath(Path.Combine(xdgConfigHome, "git/ignore")));
                }

                return(Path.GetFullPath(Path.Combine(EnvironmentConfiguration.GetHomeDir(), ".config/git/ignore")));
            }
        }