public void ConfigureRemotes_Should_not_update_localHead_if_remoteHead_is_local()
        {
            var refs = new[]
            {
                CreateSubstituteRef("f6323b8e80f96dff017dd14bdb28a576556adab4", "refs/heads/local", ""),
            };

            _module.GetRefs().ReturnsForAnyArgs(refs);

            _controller.ConfigureRemotes("origin");

            var mergeWith = "";

            Assert.AreEqual(mergeWith, refs[0].MergeWith);
            refs[0].Received(0).MergeWith = mergeWith;
        }
Пример #2
0
        public void ConfigureRemotes(string remoteName)
        {
            var localConfig = _module.LocalConfigFile;

            foreach (var remoteHead in _module.GetRefs(true, true))
            {
                foreach (var localHead in _module.GetRefs(true, true))
                {
                    if (!remoteHead.IsRemote ||
                        localHead.IsRemote ||
                        !string.IsNullOrEmpty(localHead.GetTrackingRemote(localConfig)) ||
                        remoteHead.IsTag ||
                        localHead.IsTag ||
                        !remoteHead.Name.ToLower().Contains(localHead.Name.ToLower()) ||
                        !remoteHead.Name.ToLower().Contains(remoteName.ToLower()))
                    {
                        continue;
                    }

                    localHead.TrackingRemote = remoteName;
                    localHead.MergeWith      = localHead.Name;
                }
            }
        }
Пример #3
0
        private static GitRevision GetCurrentRevision(
            IGitModule module, [CanBeNull] RevisionGridControl revisionGrid, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches,
            List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches, [CanBeNull] GitRevision currentRevision)
        {
            if (currentRevision == null)
            {
                IEnumerable <IGitRef> refs;

                if (revisionGrid == null)
                {
                    var currentRevisionGuid = module.GetCurrentCheckout();
                    currentRevision = new GitRevision(currentRevisionGuid);
                    refs            = module.GetRefs(true, true).Where(gitRef => gitRef.ObjectId == currentRevisionGuid).ToList();
                }
                else
                {
                    currentRevision = revisionGrid.GetCurrentRevision();
                    refs            = currentRevision.Refs;
                }

                foreach (var gitRef in refs)
                {
                    if (gitRef.IsTag)
                    {
                        currentTags.Add(gitRef);
                    }
                    else if (gitRef.IsHead || gitRef.IsRemote)
                    {
                        currentBranches.Add(gitRef);
                        if (gitRef.IsRemote)
                        {
                            currentRemoteBranches.Add(gitRef);
                        }
                        else
                        {
                            currentLocalBranches.Add(gitRef);
                        }
                    }
                }
            }

            return(currentRevision);
        }
Пример #4
0
        private void PopulateBranches()
        {
            Branch_ComboBox.Items.Clear();

            var branches = _gitCommands.GetRefs(false);

            string[] branchNames;
            branchNames = branches.Select(b => b.Name).Where(name => name.IsNotNullOrWhitespace()).ToArray();

            Branch_ComboBox.Items.AddRange(branchNames);

            for (int i = 0; i < branches.Count; ++i)
            {
                if (branches[i].Name == _gitCommands.GetSelectedBranch())
                {
                    Branch_ComboBox.SelectedIndex = i;
                }
            }
        }
        public void FilteredGitRefsProviderTest()
        {
            var refs = new[]
            {
                CreateSubstituteRef("f6323b8e80f96dff017dd14bdb28a576556adab4", "refs/heads/develop", ""),
                CreateSubstituteRef("02e10a13e06e7562f7c3c516abb2a0e1a0c0dd90", "refs/remotes/origin/develop", "origin"),
                CreateSubstituteRef("f6323b8e80f96dff017dd14bdb28a576556adab5", "refs/heads/local", ""),
            };

            _module.GetRefs(RefsFilter.NoFilter).ReturnsForAnyArgs(refs);

            FilteredGitRefsProvider filteredRefs = new(_module);

            filteredRefs.GetRefs(RefsFilter.NoFilter).Count.Should().Be(3);
            filteredRefs.GetRefs(RefsFilter.Remotes).Count.Should().Be(1);
            filteredRefs.GetRefs(RefsFilter.Heads).Count.Should().Be(2);
            filteredRefs.GetRefs(RefsFilter.Tags).Count.Should().Be(0);
            filteredRefs.GetRefs(RefsFilter.Remotes | RefsFilter.Heads).Count.Should().Be(3);
        }
Пример #6
0
        private static GitRevision GetCurrentRevision(
            [NotNull] IGitModule module, [CanBeNull] IScriptHostControl scriptHostControl, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches,
            List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches)
        {
            GitRevision           currentRevision;
            IEnumerable <IGitRef> refs;

            if (scriptHostControl == null)
            {
                var currentRevisionGuid = module.GetCurrentCheckout();
                currentRevision = currentRevisionGuid == null ? null : new GitRevision(currentRevisionGuid);
                refs            = module.GetRefs(true, true).Where(gitRef => gitRef.ObjectId == currentRevisionGuid);
            }
            else
            {
                currentRevision = scriptHostControl.GetCurrentRevision();
                refs            = currentRevision?.Refs ?? Array.Empty <IGitRef>();
            }

            foreach (var gitRef in refs)
            {
                if (gitRef.IsTag)
                {
                    currentTags.Add(gitRef);
                }
                else if (gitRef.IsHead || gitRef.IsRemote)
                {
                    currentBranches.Add(gitRef);
                    if (gitRef.IsRemote)
                    {
                        currentRemoteBranches.Add(gitRef);
                    }
                    else
                    {
                        currentLocalBranches.Add(gitRef);
                    }
                }
            }

            return(currentRevision);
        }
 public FilteredGitRefsProvider(IGitModule module)
 {
     _refs = new(() => module.GetRefs(RefsFilter.NoFilter));
 }