private void AddToRecentRepos(String path)
        {
            String?repo = Git.GetBaseRepoDirectory(path);

            if (repo == null)
            {
                LOG.Error($"Failed to add recent repo - Path: {path}");
                return;
            }

            if (Settings.Default.RecentRepos.Contains(repo))
            {
                Settings.Default.RecentRepos.Remove(repo);
            }
            Settings.Default.RecentRepos.Insert(0, repo);

            int maxRecentRepos = Settings.Default.MaxRecentRepos;

            if (Settings.Default.RecentRepos.Count > maxRecentRepos)
            {
                Settings.Default.RecentRepos.RemoveRange(maxRecentRepos, Settings.Default.RecentRepos.Count - maxRecentRepos);
            }

            Settings.Default.Save();
        }
        private void InitializeReferences()
        {
            using (Repository repository = new Repository(Git.GetBaseRepoDirectory(_repo)))
            {
                Branch currentBranch = repository.Head;
                if (currentBranch != null)
                {
                    _currentBranch = repository.Head.CanonicalName;
                    if (_currentBranch == "(no branch)")
                    {
                        _currentBranch = null;
                    }
                }
                else
                {
                    _currentBranch = null;
                }

                AddCurrentBranchButton.Enabled = (_currentBranch != null);

                foreach (Reference r in repository.Refs)
                {
                    String[] splitRef = r.CanonicalName.Split('/');
                    AddReference(r.CanonicalName, splitRef, 0, ReferencesTreeView.Nodes);
                }
            }

            if (ReferencesTreeView.Nodes.Count > 0)
            {
                TreeNode firstNode = ReferencesTreeView.Nodes[0];
                firstNode.Expand();
                ReferencesTreeView.SelectedNode = firstNode;
            }
        }
Example #3
0
 public static Task <String[]> GetReferences(String repo)
 {
     return(Task.Run(() =>
     {
         using Repository repository = new Repository(Git.GetBaseRepoDirectory(repo));
         return repository.Refs.Select((r) => r.CanonicalName).ToArray();
     }));
 }
Example #4
0
 public static Task <String?> GetCurrentBranch(String repo)
 {
     return(Task.Run(() =>
     {
         using var repository = new Repository(Git.GetBaseRepoDirectory(repo));
         var currentBranch = repository.Head.CanonicalName;
         return currentBranch switch
         {
             null => null,
             "(no branch)" => null,
             _ => currentBranch
         };
     }));
 }