Exemplo n.º 1
0
        private void LoadMultiBranchViewData(string remote)
        {
            Cursor = Cursors.AppStarting;
            try
            {
                IList <IGitRef> remoteHeads;
                if (Module.EffectiveSettings.Detailed.GetRemoteBranchesDirectlyFromRemote.ValueOrDefault)
                {
                    EnsurePageant(remote);
                    var cmdGetBranchesFromRemote = "ls-remote --heads \"" + remote + "\"";
                    using (var formProcess = new FormRemoteProcess(Module, cmdGetBranchesFromRemote)
                    {
                        Remote = remote
                    })
                    {
                        formProcess.ShowDialog(this);
                        if (formProcess.ErrorOccurred())
                        {
                            return;
                        }

                        var processOutput = formProcess.GetOutputString();
                        var cmdOutput     = TakeCommandOutput(processOutput);
                        remoteHeads = Module.GetTreeRefs(cmdOutput);
                        if (remoteHeads == null)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    // use remote branches from the git's local database if there were problems with receiving branches from the remote server
                    remoteHeads = Module.GetRemoteBranches().Where(r => r.Remote == remote).ToList();
                }

                ProcessHeads(remote, remoteHeads);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Exemplo n.º 2
0
        private void LoadMultiBranchViewData(string remote)
        {
            using (WaitCursorScope.Enter(Cursors.AppStarting))
            {
                IReadOnlyList <IGitRef> remoteHeads;
                if (Module.EffectiveSettings.Detailed.GetRemoteBranchesDirectlyFromRemote.ValueOrDefault)
                {
                    EnsurePageant(remote);

                    var formProcess = new FormRemoteProcess(Module, $"ls-remote --heads \"{remote}\"")
                    {
                        Remote = remote
                    };

                    using (formProcess)
                    {
                        formProcess.ShowDialog(this);

                        if (formProcess.ErrorOccurred())
                        {
                            return;
                        }

                        var refList = CleanCommandOutput(formProcess.GetOutputString());

                        remoteHeads = Module.ParseRefs(refList);
                    }
                }
                else
                {
                    // use remote branches from git's local database if there were problems with receiving branches from the remote server
                    remoteHeads = Module.GetRemoteBranches().Where(r => r.Remote == remote).ToList();
                }

                ProcessHeads(remoteHeads);
            }

            return;

            string CleanCommandOutput(string processOutput)
            {
                // Command output consists of lines of format:
                //
                //     <SHA1> \t <full-ref>
                //
                // Such as:
                //
                //     fa77791d780a01a06d1f7d4ccad4ef93ed0ae2fd\trefs/heads/branchName

                int firstTabIdx = processOutput.IndexOf('\t');

                return(firstTabIdx == 40
                    ? processOutput
                    : firstTabIdx > 40
                        ? processOutput.Substring(firstTabIdx - 40)
                        : string.Empty);
            }

            void ProcessHeads(IReadOnlyList <IGitRef> remoteHeads)
            {
                var localHeads     = GetLocalBranches().ToList();
                var remoteBranches = remoteHeads.ToHashSet(h => h.LocalName);

                // Add all the local branches.
                foreach (var head in localHeads)
                {
                    var remoteName = head.Remote == remote
                        ? head.MergeWith ?? head.Name
                        : head.Name;
                    var isKnownAtRemote = remoteBranches.Contains(remoteName);

                    var row = _branchTable.NewRow();

                    row[ForceColumnName]  = false;
                    row[DeleteColumnName] = false;
                    row[LocalColumnName]  = head.Name;
                    row[RemoteColumnName] = remoteName;
                    row[NewColumnName]    = isKnownAtRemote ? _no.Text : _yes.Text;
                    row[PushColumnName]   = isKnownAtRemote;

                    _branchTable.Rows.Add(row);
                }

                // Offer to delete all the left over remote branches.
                foreach (var remoteHead in remoteHeads)
                {
                    if (localHeads.All(h => h.Name != remoteHead.LocalName))
                    {
                        var row = _branchTable.NewRow();

                        row[LocalColumnName]  = null;
                        row[RemoteColumnName] = remoteHead.LocalName;
                        row[NewColumnName]    = _no.Text;
                        row[PushColumnName]   = false;
                        row[ForceColumnName]  = false;
                        row[DeleteColumnName] = false;

                        _branchTable.Rows.Add(row);
                    }
                }

                BranchGrid.Enabled = true;
            }
        }
Exemplo n.º 3
0
        private void LoadMultiBranchViewData(string remote, IEnumerable<GitRef> localHeads)
        {
            Cursor = Cursors.AppStarting;
            try
            {
                IEnumerable<GitRef> remoteHeads = null;
                if (Module.EffectiveSettings.Detailed.GetRemoteBranchesDirectlyFromRemote.ValueOrDefault)
                {
                    EnsurePageant(remote);
                    var cmdGetBranchesFromRemote = "ls-remote --heads \"" + remote + "\"";
                    using (var formProcess = new FormRemoteProcess(Module, cmdGetBranchesFromRemote)
                    {
                        Remote = remote
                    })
                    {

                        formProcess.ShowDialog(this);
                        if (formProcess.ErrorOccurred())
                        {
                            return;
                        }
                        var processOutput = formProcess.GetOutputString();
                        var cmdOutput = TakeCommandOutput(processOutput);
                        remoteHeads = Module.GetTreeRefs(cmdOutput);
                        if (remoteHeads == null)
                            return;
                    }
                }
                else
                {
                    //use remote branches from the git's local database if there were problems with receiving branches from the remote server
                    remoteHeads = Module.GetRemoteBranches().Where(r => r.Remote == remote);
                }
                ProcessHeads(remote, localHeads, remoteHeads);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }