Inheritance: IGitRef
        private IList <GitRef> GetRefs()
        {
            var  result          = _module.GetRefs(true);
            bool validWorkingDir = _module.IsValidGitWorkingDir();

            _selectedBranchName = validWorkingDir ? _module.GetSelectedBranch() : string.Empty;
            GitRef selectedRef = result.FirstOrDefault(head => head.Name == _selectedBranchName);

            if (selectedRef != null)
            {
                selectedRef.Selected = true;

                var localConfigFile = _module.LocalConfigFile;

                var selectedHeadMergeSource =
                    result.FirstOrDefault(head => head.IsRemote &&
                                          selectedRef.GetTrackingRemote(localConfigFile) == head.Remote &&
                                          selectedRef.GetMergeWith(localConfigFile) == head.LocalName);

                if (selectedHeadMergeSource != null)
                {
                    selectedHeadMergeSource.SelectedHeadMergeSource = true;
                }
            }

            return(result);
        }
Exemple #2
0
        private void RemotesUpdated(object sender, EventArgs e)
        {
            if (TabControlTagBranch.SelectedTab == MultipleBranchTab)
                UpdateMultiBranchView();

            EnableLoadSshButton();

            // update the text box of the Remote Url combobox to show the URL of selected remote
            {
                string pushUrl = Module.GetPathSetting(string.Format(SettingKeyString.RemotePushUrl, _NO_TRANSLATE_Remotes.Text));
                if (pushUrl.IsNullOrEmpty())
                {
                    pushUrl = Module.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, _NO_TRANSLATE_Remotes.Text));
                }
                PushDestination.Text = pushUrl;
            }

            var pushSettingValue = Module.GetSetting(string.Format("remote.{0}.push", _NO_TRANSLATE_Remotes.Text));

            if (PushToRemote.Checked && !string.IsNullOrEmpty(pushSettingValue))
            {
                string defaultLocal = GetDefaultPushLocal(_NO_TRANSLATE_Remotes.Text);
                string defaultRemote = GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text);

                RemoteBranch.Text = "";
                if (!string.IsNullOrEmpty(defaultLocal))
                {
                    var currentBranch = new GitRef(Module, null, defaultLocal, _NO_TRANSLATE_Remotes.Text);
                    _NO_TRANSLATE_Branch.Items.Add(currentBranch);
                    _NO_TRANSLATE_Branch.SelectedItem = currentBranch;
                }
                if (!string.IsNullOrEmpty(defaultRemote))
                    RemoteBranch.Text = defaultRemote;
                return;
            }

            if (string.IsNullOrEmpty(_NO_TRANSLATE_Branch.Text))
            {
                // Doing this makes it pretty easy to accidentally create a branch on the remote.
                // But leaving it blank will do the 'default' thing, meaning all branches are pushed.
                // Solution: when pushing a branch that doesn't exist on the remote, ask what to do
                var currentBranch = new GitRef(Module, null, _currentBranch, _NO_TRANSLATE_Remotes.Text);
                _NO_TRANSLATE_Branch.Items.Add(currentBranch);
                _NO_TRANSLATE_Branch.SelectedItem = currentBranch;
                return;
            }

            BranchSelectedValueChanged(null, null);
        }
Exemple #3
0
        private IList<GitRef> GetTreeRefs(string tree)
        {
            var itemsStrings = tree.Split('\n');

            var gitRefs = new List<GitRef>();
            var defaultHeads = new Dictionary<string, GitRef>(); // remote -> HEAD
            var remotes = GetRemotes(false);

            foreach (var itemsString in itemsStrings)
            {
                if (itemsString == null || itemsString.Length <= 42)
                    continue;

                var completeName = itemsString.Substring(41).Trim();
                var guid = itemsString.Substring(0, 40);
                var remoteName = GitCommandHelpers.GetRemoteName(completeName, remotes);
                var head = new GitRef(this, guid, completeName, remoteName);
                if (DefaultHeadPattern.IsMatch(completeName))
                    defaultHeads[remoteName] = head;
                else
                    gitRefs.Add(head);
            }

            // do not show default head if remote has a branch on the same commit
            GitRef defaultHead;
            foreach (var gitRef in gitRefs.Where(head => defaultHeads.TryGetValue(head.Remote, out defaultHead) && head.Guid == defaultHead.Guid))
            {
                defaultHeads.Remove(gitRef.Remote);
            }

            gitRefs.AddRange(defaultHeads.Values);

            return gitRefs;
        }
 private static Color GetHeadColor(GitRef gitRef)
 {
     if (gitRef.IsTag)
         return AppSettings.TagColor;
     if (gitRef.IsHead)
         return AppSettings.BranchColor;
     if (gitRef.IsRemote)
         return AppSettings.RemoteBranchColor;
     return AppSettings.OtherTagColor;
 }
        public bool ShowRemoteRef(GitRef r)
        {
            if (r.IsTag)
                return AppSettings.ShowSuperprojectTags;

            if (r.IsHead)
                return AppSettings.ShowSuperprojectBranches;

            if (r.IsRemote)
                return AppSettings.ShowSuperprojectRemoteBranches;

            return false;
        }
        private void comboBoxBranches_TextChanged(object sender, EventArgs e)
        {
            if (comboBoxBranches.DataSource == null)
            {
                return;
            }

            _selectedBranch = ((List<GitRef>)comboBoxBranches.DataSource).FirstOrDefault(a => a.LocalName == comboBoxBranches.Text);
            SetSelectedRevisionByFocusedControl();
        }
Exemple #7
0
        private string GetDefaultPushRemote(String remote, String branch)
        {
            Func<string, string, bool> IsSettingForBranch = (aSetting, aBranch) =>
                {
                    var head = new GitRef(Module, string.Empty, aSetting);
                    return head.IsHead && head.Name.Equals(aBranch);
                };

            var pushSettings = Module.GetSettings(string.Format("remote.{0}.push", remote));
            var remoteHead = pushSettings.
                Select(s => s.Split(':')).
                Where(t => t.Length == 2).
                Where(t => IsSettingForBranch(t[0], branch)).
                Select(t => new GitRef(Module, string.Empty, t[1])).
                Where(h => h.IsHead).
                FirstOrDefault();

            return remoteHead == null ? null : remoteHead.Name;
        }
        private void comboBoxBranches_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (comboBoxBranches.SelectedValue == null)
            {
                return;
            }

            _selectedBranch = (GitRef)comboBoxBranches.SelectedValue;
            SetSelectedRevisionByFocusedControl();
            Go();
        }
        /// <summary>
        /// Returns the default remote for push operation.
        /// </summary>
        /// <param name="remote"></param>
        /// <param name="branch"></param>
        /// <returns>The <see cref="GitRef.Name"/> if found, otheriwse <see langword="null"/>.</returns>
        // TODO: moved verbatim from FormPush.cs, perhaps needs refactoring
        public string GetDefaultPushRemote(GitRemote remote, string branch)
        {
            if (remote == null)
            {
                throw new ArgumentNullException("remote");
            }

            Func<string, string, bool> isSettingForBranch = (setting, branchName) =>
            {
                var head = new GitRef(_module, string.Empty, setting);
                return head.IsHead && head.Name.Equals(branchName, StringComparison.OrdinalIgnoreCase);
            };

            var remoteHead = remote.Push
                                   .Select(s => s.Split(':'))
                                   .Where(t => t.Length == 2)
                                   .Where(t => isSettingForBranch(t[0], branch))
                                   .Select(t => new GitRef(_module, string.Empty, t[1]))
                                   .FirstOrDefault(h => h.IsHead);

            return remoteHead == null ? null : remoteHead.Name;
        }
Exemple #10
0
        private IList<GitRef> GetTreeRefs(string tree)
        {
            var gitRefs = new List<GitRef>();
            var defaultHeads = new Dictionary<string, GitRef>(); // remote -> HEAD
            var remotes = GetRemotes(false);

            using (TextReader tr = new StringReader(tree))
            {
                string line = tr.ReadLine();
                while (line != null)
                {
                    if (line == null || line.Length <= 42 || line.StartsWith("error: "))
                        continue;

                    var completeName = line.Substring(41).Trim();
                    var guid = line.Substring(0, 40);
                    var remoteName = GitCommandHelpers.GetRemoteName(completeName, remotes);
                    var head = new GitRef(this, guid, completeName, remoteName);
                    if (DefaultHeadPattern.IsMatch(completeName))
                        defaultHeads[remoteName] = head;
                    else
                        gitRefs.Add(head);

                    line = tr.ReadLine();
                }
            }

            // do not show default head if remote has a branch on the same commit
            GitRef defaultHead;
            foreach (var gitRef in gitRefs.Where(head => defaultHeads.TryGetValue(head.Remote, out defaultHead) && head.Guid == defaultHead.Guid))
            {
                defaultHeads.Remove(gitRef.Remote);
            }

            gitRefs.AddRange(defaultHeads.Values);

            return gitRefs;
        }
Exemple #11
0
        private void RemotesUpdated(object sender, EventArgs e)
        {
            _selectedRemote = _NO_TRANSLATE_Remotes.SelectedItem as GitRemote;
            if (_selectedRemote == null)
            {
                return;
            }

            if (TabControlTagBranch.SelectedTab == MultipleBranchTab)
            {
                UpdateMultiBranchView();
            }

            EnableLoadSshButton();

            // update the text box of the Remote Url combobox to show the URL of selected remote
            string pushUrl = _selectedRemote.PushUrl;
            if (pushUrl.IsNullOrEmpty())
            {
                pushUrl = _selectedRemote.Url;
            }
            PushDestination.Text = pushUrl;

            if (string.IsNullOrEmpty(_NO_TRANSLATE_Branch.Text))
            {
                // Doing this makes it pretty easy to accidentally create a branch on the remote.
                // But leaving it blank will do the 'default' thing, meaning all branches are pushed.
                // Solution: when pushing a branch that doesn't exist on the remote, ask what to do
                var currentBranch = new GitRef(Module, null, _currentBranchName, _selectedRemote.Name);
                _NO_TRANSLATE_Branch.Items.Add(currentBranch);
                _NO_TRANSLATE_Branch.SelectedItem = currentBranch;
            }

            BranchSelectedValueChanged(null, null);
        }
 public TagNode(Tree aTree, string aFullPath, GitRef tagInfo)
     : base(aTree, aFullPath)
 {
     _tagInfo = tagInfo;
 }