Esempio n. 1
0
        private IReadOnlyList <string> GetContainsRevisionBranches()
        {
            var result = new HashSet <string>();

            if (_containRevisons.Length > 0)
            {
                var branches = Module.GetAllBranchesWhichContainGivenCommit(_containRevisons[0], LocalBranch.Checked,
                                                                            !LocalBranch.Checked)
                               .Where(a => !DetachedHeadParser.IsDetachedHead(a) &&
                                      !a.EndsWith("/HEAD"));
                result.UnionWith(branches);
            }

            for (int index = 1; index < _containRevisons.Length; index++)
            {
                var containRevison = _containRevisons[index];
                var branches       =
                    Module.GetAllBranchesWhichContainGivenCommit(containRevison, LocalBranch.Checked,
                                                                 !LocalBranch.Checked)
                    .Where(a => !DetachedHeadParser.IsDetachedHead(a) &&
                           !a.EndsWith("/HEAD"));
                result.IntersectWith(branches);
            }

            return(result.ToList());
        }
        private static string GetModuleBranch(string path, string noBranchText)
        {
            var branch = GitModule.GetSelectedBranchFast(path);
            var text   = DetachedHeadParser.IsDetachedHead(branch) ? noBranchText : branch;

            return($"[{text}]");
        }
Esempio n. 3
0
        private void PopulateBranches()
        {
            if (IsUICommandsInitialized)
            {
                Branches.Items.Clear();

                IEnumerable <string> branchNames;

                if (_containRevisions == null)
                {
                    var branches = LocalBranch.Checked ? GetLocalBranches() : GetRemoteBranches();

                    branchNames = branches.Select(b => b.Name);
                }
                else
                {
                    branchNames = GetContainsRevisionBranches();
                }

                Branches.Items.AddRange(branchNames.Where(name => name.IsNotNullOrWhitespace()).ToArray <object>());

                if (_containRevisions != null && Branches.Items.Count == 1)
                {
                    Branches.SelectedIndex = 0;
                }
                else
                {
                    Branches.Text = null;
                }
            }

            IReadOnlyList <string> GetContainsRevisionBranches()
            {
                var result = new HashSet <string>();

                if (_containRevisions.Count > 0)
                {
                    var branches = Module.GetAllBranchesWhichContainGivenCommit(_containRevisions[0], LocalBranch.Checked,
                                                                                !LocalBranch.Checked)
                                   .Where(a => !DetachedHeadParser.IsDetachedHead(a) &&
                                          !a.EndsWith("/HEAD"));
                    result.UnionWith(branches);
                }

                for (int index = 1; index < _containRevisions.Count; index++)
                {
                    var containRevision = _containRevisions[index];
                    var branches        =
                        Module.GetAllBranchesWhichContainGivenCommit(containRevision, LocalBranch.Checked,
                                                                     !LocalBranch.Checked)
                        .Where(a => !DetachedHeadParser.IsDetachedHead(a) &&
                               !a.EndsWith("/HEAD"));
                    result.IntersectWith(branches);
                }

                return(result.ToList());
            }
        }
Esempio n. 4
0
        private void FormDeleteBranchLoad(object sender, EventArgs e)
        {
            Branches.BranchesToSelect = Module.GetRefs(true, true).Where(h => h.IsHead && !h.IsRemote).ToList();
            foreach (var branch in Module.GetMergedBranches())
            {
                if (!branch.StartsWith("* "))
                {
                    _mergedBranches.Add(branch.Trim());
                }
                else if (!branch.StartsWith("* ") || (branch.StartsWith("* ") && !DetachedHeadParser.IsDetachedHead(branch.Substring(2))))
                {
                    _currentBranch = branch.Trim('*', ' ');
                }
            }

            if (_defaultBranches != null)
            {
                Branches.SetSelectedText(_defaultBranches.Join(", "));
            }
        }
Esempio n. 5
0
        private bool CalculateLocalBranch(string remote, out string curLocalBranch, out string curRemoteBranch)
        {
            if (IsPullAll())
            {
                curLocalBranch  = null;
                curRemoteBranch = null;
                return(true);
            }

            curRemoteBranch = Branches.Text;

            if (DetachedHeadParser.IsDetachedHead(_branch))
            {
                curLocalBranch = null;
                return(true);
            }

            var currentBranchRemote = new Lazy <string>(() => Module.GetSetting(string.Format(SettingKeyString.BranchRemote, localBranch.Text)));

            if (_branch == localBranch.Text)
            {
                if (remote == currentBranchRemote.Value || currentBranchRemote.Value.IsNullOrEmpty())
                {
                    curLocalBranch = Branches.Text.IsNullOrEmpty() ? null : _branch;
                }
                else
                {
                    curLocalBranch = localBranch.Text;
                }
            }
            else
            {
                curLocalBranch = localBranch.Text;
            }

            if (Branches.Text.IsNullOrEmpty() && !curLocalBranch.IsNullOrEmpty() &&
                remote != currentBranchRemote.Value && !Fetch.Checked)
            {
                int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(this,
                                                                  _noRemoteBranchCaption.Text,
                                                                  _noRemoteBranch.Text,
                                                                  string.Format(_noRemoteBranchMainInstruction.Text, remote),
                                                                  string.Format(_noRemoteBranchButtons.Text, remote + "/" + curLocalBranch),
                                                                  false);
                switch (idx)
                {
                case 0:
                    curRemoteBranch = curLocalBranch;
                    return(true);

                default:
                    return(false);
                }
            }

            if (Branches.Text.IsNullOrEmpty() && !curLocalBranch.IsNullOrEmpty() &&
                Fetch.Checked)
            {
                // if local branch eq to current branch and remote branch is not specified
                // then run fetch with no refspec
                if (_branch == curLocalBranch)
                {
                    curLocalBranch = null;
                    return(true);
                }

                int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(this,
                                                                  _noRemoteBranchCaption.Text,
                                                                  _noRemoteBranch.Text,
                                                                  string.Format(_noRemoteBranchForFetchMainInstruction.Text, remote),
                                                                  string.Format(_noRemoteBranchForFetchButtons.Text, remote + "/" + curLocalBranch),
                                                                  false);
                switch (idx)
                {
                case 0:
                    curRemoteBranch = curLocalBranch;
                    return(true);

                default:
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 6
0
        private bool CalculateLocalBranch(string remote, out string curLocalBranch, out string curRemoteBranch)
        {
            if (IsPullAll())
            {
                curLocalBranch  = null;
                curRemoteBranch = null;
                return(true);
            }

            curRemoteBranch = Branches.Text;

            if (DetachedHeadParser.IsDetachedHead(_branch))
            {
                curLocalBranch = null;
                return(true);
            }

            var currentBranchRemote = new Lazy <string>(() => Module.GetSetting(string.Format(SettingKeyString.BranchRemote, localBranch.Text)));

            if (_branch == localBranch.Text)
            {
                if (remote == currentBranchRemote.Value || string.IsNullOrEmpty(currentBranchRemote.Value))
                {
                    curLocalBranch = string.IsNullOrEmpty(Branches.Text) ? null : _branch;
                }
                else
                {
                    curLocalBranch = localBranch.Text;
                }
            }
            else
            {
                curLocalBranch = localBranch.Text;
            }

            if (string.IsNullOrEmpty(Branches.Text) && !string.IsNullOrEmpty(curLocalBranch) &&
                remote != currentBranchRemote.Value && !Fetch.Checked)
            {
                int dialogResult = -1;

                using var dialog = new TaskDialog
                      {
                          OwnerWindowHandle = Handle,
                          Text               = string.Format(_noRemoteBranchMainInstruction.Text, remote),
                          Caption            = _noRemoteBranchCaption.Text,
                          InstructionText    = _noRemoteBranch.Text,
                          StandardButtons    = TaskDialogStandardButtons.Cancel,
                          Icon               = TaskDialogStandardIcon.Information,
                          FooterCheckBoxText = _dontShowAgain.Text,
                          FooterIcon         = TaskDialogStandardIcon.Information,
                          StartupLocation    = TaskDialogStartupLocation.CenterOwner,
                          Cancelable         = false
                      };

                var btnPullFrom = new TaskDialogCommandLink("PullFrom", null, string.Format(_noRemoteBranchButton.Text, remote + "/" + curLocalBranch));
                btnPullFrom.Click += (s, e) =>
                {
                    dialogResult = 0;
                    dialog.Close();
                };
                dialog.Controls.Add(btnPullFrom);

                dialog.Show();

                switch (dialogResult)
                {
                case 0:
                    curRemoteBranch = curLocalBranch;
                    return(true);

                default:
                    return(false);
                }
            }

            if (string.IsNullOrEmpty(Branches.Text) && !string.IsNullOrEmpty(curLocalBranch) && Fetch.Checked)
            {
                // if local branch eq to current branch and remote branch is not specified
                // then run fetch with no refspec
                if (_branch == curLocalBranch)
                {
                    curLocalBranch = null;
                    return(true);
                }

                int dialogResult = -1;

                using var dialog = new TaskDialog
                      {
                          OwnerWindowHandle = Handle,
                          Text            = string.Format(_noRemoteBranchForFetchMainInstruction.Text, remote),
                          Caption         = _noRemoteBranchCaption.Text,
                          InstructionText = _noRemoteBranch.Text,
                          StandardButtons = TaskDialogStandardButtons.Cancel,
                          Icon            = TaskDialogStandardIcon.Information,
                          StartupLocation = TaskDialogStartupLocation.CenterOwner,
                          Cancelable      = false
                      };

                var btnPullFrom = new TaskDialogCommandLink("PullFrom", null, string.Format(_noRemoteBranchForFetchButton.Text, remote + "/" + curLocalBranch));
                btnPullFrom.Click += (s, e) =>
                {
                    dialogResult = 0;
                    dialog.Close();
                };
                dialog.Controls.Add(btnPullFrom);

                dialog.Show();

                switch (dialogResult)
                {
                case 0:
                    curRemoteBranch = curLocalBranch;
                    return(true);

                default:
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 7
0
        public void Initialize(bool remote, IReadOnlyList <ObjectId> containRevisions)
        {
            lbChanges.Text       = "";
            LocalBranch.Checked  = !remote;
            Remotebranch.Checked = remote;

            _containRevisions = containRevisions;

            Branches.Items.Clear();
            Branches.Items.AddRange(_containRevisions != null
                ? GetContainsRevisionBranches()
                : LocalBranch.Checked
                    ? GetLocalBranches()
                    : GetRemoteBranches());

            Branches.ResizeDropDownWidth(AppSettings.BranchDropDownMinWidth, AppSettings.BranchDropDownMaxWidth);

            if (_containRevisions != null && Branches.Items.Count == 1)
            {
                Branches.SelectedIndex = 0;
            }
            else
            {
                Branches.Text = null;
            }

            string[] GetLocalBranches()
            {
                if (_localBranches == null)
                {
                    _localBranches = Module.GetRefs(false).Select(b => b.Name).ToArray();
                }

                return(_localBranches);
            }

            string[] GetRemoteBranches()
            {
                if (_remoteBranches == null)
                {
                    _remoteBranches = Module.GetRefs(true, true).Where(h => h.IsRemote && !h.IsTag).Select(b => b.Name).ToArray();
                }

                return(_remoteBranches);
            }

            string[] GetContainsRevisionBranches()
            {
                var result = new HashSet <string>();

                if (_containRevisions.Count > 0)
                {
                    var branches = Module.GetAllBranchesWhichContainGivenCommit(_containRevisions[0], LocalBranch.Checked,
                                                                                !LocalBranch.Checked)
                                   .Where(a => !DetachedHeadParser.IsDetachedHead(a) &&
                                          !a.EndsWith("/HEAD"));
                    result.UnionWith(branches);
                }

                for (int index = 1; index < _containRevisions.Count; index++)
                {
                    var containRevision = _containRevisions[index];
                    var branches        =
                        Module.GetAllBranchesWhichContainGivenCommit(containRevision, LocalBranch.Checked,
                                                                     !LocalBranch.Checked)
                        .Where(a => !DetachedHeadParser.IsDetachedHead(a) &&
                               !a.EndsWith("/HEAD"));
                    result.IntersectWith(branches);
                }

                return(result.ToArray());
            }
        }
 public void ShouldExtractOldVersionOfDetachedHeadOutput()
 {
     Assert.True(DetachedHeadParser.TryParse("(detached from c299581)", out var sha1));
     Assert.AreEqual("c299581", sha1);
 }
 public void ShouldExtractNewVersionOfDetachedHeadOutput()
 {
     Assert.True(DetachedHeadParser.TryParse("(HEAD detached at c299582)", out var sha1));
     Assert.AreEqual("c299582", sha1);
 }