Form that handles Plink exceptions
Inheritance: FormProcess
 public static new bool ShowDialog(IWin32Window owner, GitModule module, string arguments)
 {
     using (var formRemoteProcess = new FormRemoteProcess(module, arguments))
     {
         formRemoteProcess.ShowDialog(owner);
         return !formRemoteProcess.ErrorOccurred();
     }
 }
示例#2
0
        private void OkClick(object sender, EventArgs e)
        {
            try
            {
                if (threadUpdateBranchList != null)
                {
                    Cursor = Cursors.Default;
                    threadUpdateBranchList.Abort();
                }

                var dirTo = _NO_TRANSLATE_To.Text;
                if (!dirTo.EndsWith(Settings.PathSeparator.ToString()) && !dirTo.EndsWith(Settings.PathSeparatorWrong.ToString()))
                    dirTo += Settings.PathSeparator.ToString();

                dirTo += _NO_TRANSLATE_NewDirectory.Text;

                Repositories.AddMostRecentRepository(_NO_TRANSLATE_From.Text);
                Repositories.AddMostRecentRepository(dirTo);

                if (!Directory.Exists(dirTo))
                    Directory.CreateDirectory(dirTo);

                var cloneCmd = GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo,
                            CentralRepository.Checked, cbIntializeAllSubmodules.Checked, Branches.Text, null);
                var fromProcess = new FormRemoteProcess(Settings.GitCommand, cloneCmd);
                fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text);
                fromProcess.ShowDialog(this);

                if (fromProcess.ErrorOccurred() || Settings.Module.InTheMiddleOfPatch())
                    return;

                if (ShowInTaskbar == false && AskIfNewRepositoryShouldBeOpened(dirTo))
                    Settings.WorkingDir = dirTo;
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
            public void Execute()
            {
                if (CommandText == null)
                    throw new InvalidOperationException("CommandText is required");

                using (var form = new FormRemoteProcess(Module, CommandText))
                {
                    if (Title != null)
                        form.Text = Title;
                    if (Remote != null)
                        form.Remote = Remote;

                    form.HandleOnExitCallback = HandleOnExit;

                    form.ShowDialog(OwnerForm as IWin32Window);

                    ErrorOccurred = form.ErrorOccurred();
                    CommandOutput = form.GetOutputString();
                }
            }
示例#4
0
 public bool StartCommandLineProcessDialog(GitCommand cmd, Form parentForm)
 {
     FormProcess process;
     if (cmd.AccessesRemote())
         process = new FormRemoteProcess(cmd.ToLine());
     else
         process = new FormProcess(cmd.ToLine());
     process.ShowDialog(parentForm);
     return true;
 }
示例#5
0
        private bool PushChanges(IWin32Window owner)
        {
            if (PullFromUrl.Checked && string.IsNullOrEmpty(PushDestination.Text))
            {
                MessageBox.Show(owner, _selectDestinationDirectory.Text);
                return false;
            }
            if (PullFromRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text))
            {
                MessageBox.Show(owner, _selectRemote.Text);
                return false;
            }
            if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text) &&
                !PushAllTags.Checked)
            {
                MessageBox.Show(owner, _selectTag.Text);
                return false;
            }

            bool newBranch = false;

            //Extra check if the branch is already known to the remote, give a warning when not.
            //This is not possible when the remote is an URL, but this is ok since most users push to
            //known remotes anyway.
            if (TabControlTagBranch.SelectedTab == BranchTab && PullFromRemote.Checked)
            {
                //If the current branch is not the default push, and not known by the remote
                //(as far as we know since we are disconnected....)
                if (RemoteBranch.Text != GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text) &&
                    !Settings.Module.GetHeads(true, true).Exists(x => x.Remote == _NO_TRANSLATE_Remotes.Text && x.LocalName == RemoteBranch.Text) )
                    //Ask if this is really what the user wants
                    if (MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) ==
                        DialogResult.No)
                    {
                        return false;
                    }
                    else
                    {
                        newBranch = true;
                    }
            }

            Repositories.AddMostRecentRepository(PushDestination.Text);
            Settings.PushAllTags = PushAllTags.Checked;
            Settings.AutoPullOnRejected = AutoPullOnRejected.Checked;
            Settings.RecursiveSubmodulesCheck = RecursiveSubmodulesCheck.Checked;

            var remote = "";
            string destination;
            if (PullFromUrl.Checked)
            {
                destination = PushDestination.Text;
            }
            else
            {
                if (GitCommandHelpers.Plink())
                {
                    if (!File.Exists(Settings.Pageant))
                        MessageBox.Show(owner, _cannotLoadPutty.Text, PuttyText);
                    else
                        Settings.Module.StartPageantForRemote(_NO_TRANSLATE_Remotes.Text);
                }

                destination = _NO_TRANSLATE_Remotes.Text;
                remote = _NO_TRANSLATE_Remotes.Text.Trim();
            }

            string pushCmd;
            if (TabControlTagBranch.SelectedTab == BranchTab)
            {
                bool track = ReplaceTrackingReference.Checked;
                if (!track)
                {
                    track = newBranch;
                    string[] remotes = _NO_TRANSLATE_Remotes.DataSource as string[];
                    if (remotes != null)
                        foreach (string remoteBranch in remotes)
                            if (!string.IsNullOrEmpty(remoteBranch) && _NO_TRANSLATE_Branch.Text.StartsWith(remoteBranch))
                                track = false;
                }

                pushCmd = GitCommandHelpers.PushCmd(destination, _NO_TRANSLATE_Branch.Text, RemoteBranch.Text,
                    PushAllBranches.Checked, ForcePushBranches.Checked, track, RecursiveSubmodulesCheck.Checked);
            }
            else if (TabControlTagBranch.SelectedTab == TagTab)
                pushCmd = GitCommandHelpers.PushTagCmd(destination, TagComboBox.Text, PushAllTags.Checked,
                                                             ForcePushBranches.Checked);
            else
            {
                // Push Multiple Branches Tab selected
                var pushActions = new List<GitPushAction>();
                foreach (DataRow row in _branchTable.Rows)
                {
                    var push = Convert.ToBoolean(row["Push"]);
                    var force = Convert.ToBoolean(row["Force"]);
                    var delete = Convert.ToBoolean(row["Delete"]);

                    if (push || force)
                        pushActions.Add(new GitPushAction(row["Local"].ToString(), row["Remote"].ToString(), force));
                    else if (delete)
                        pushActions.Add(new GitPushAction(row["Remote"].ToString()));
                }
                pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions);
            }

            ScriptManager.RunEventScripts(ScriptEvent.BeforePush);

            //controls can be accessed only from UI thread
            candidateForRebasingMergeCommit = Settings.PullMerge == Settings.PullAction.Rebase && PullFromRemote.Checked && !PushAllBranches.Checked && TabControlTagBranch.SelectedTab == BranchTab;
            selectedBranch = _NO_TRANSLATE_Branch.Text;
            selectedBranchRemote = _NO_TRANSLATE_Remotes.Text;
            selectedRemoteBranchName = RemoteBranch.Text;

            using (var form = new FormRemoteProcess(pushCmd)
                       {
                           Remote = remote,
                           Text = string.Format(_pushToCaption.Text, destination),
                           HandleOnExitCallback = HandlePushOnExit
                       })
            {

                form.ShowDialog(owner);

                if (!Settings.Module.InTheMiddleOfConflictedMerge() &&
                    !Settings.Module.InTheMiddleOfRebase() && !form.ErrorOccurred())
                {
                    ScriptManager.RunEventScripts(ScriptEvent.AfterPush);
                    if (_createPullRequestCB.Checked)
                        GitUICommands.Instance.StartCreatePullRequest(owner);
                    return true;
                }
            }

            return false;
        }
示例#6
0
        private bool PushChanges()
        {
            if (PullFromUrl.Checked && string.IsNullOrEmpty(PushDestination.Text))
            {
                MessageBox.Show(_selectDestinationDirectory.Text);
                return false;
            }
            if (PullFromRemote.Checked && string.IsNullOrEmpty(Remotes.Text))
            {
                MessageBox.Show(_selectRemote.Text);
                return false;
            }
            if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text) &&
                !PushAllTags.Checked)
            {
                MessageBox.Show(_selectTag.Text);
                return false;
            }

            bool newBranch = false;

            //Extra check if the branch is already known to the remote, give a warning when not.
            //This is not possible when the remote is an URL, but this is ok since most users push to
            //known remotes anyway.
            if (TabControlTagBranch.SelectedTab == BranchTab && PullFromRemote.Checked)
            {
                //The current branch is not known by the remote (as far as we now since we are disconnected....)
                if (!GitCommandHelpers.GetHeads(true, true).Exists(x => x.Remote == Remotes.Text && x.LocalName == RemoteBranch.Text))
                    //Ask if this is what the user wants
                    if (MessageBox.Show(_branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) ==
                        DialogResult.No)
                    {
                        return false;
                    }
                    else
                    {
                        newBranch = true;
                    }
            }

            Repositories.RepositoryHistory.AddMostRecentRepository(PushDestination.Text);
            Settings.PushAllTags = PushAllTags.Checked;
            Settings.AutoPullOnRejected = AutoPullOnRejected.Checked;

            var remote = "";
            string destination;
            if (PullFromUrl.Checked)
            {
                destination = PushDestination.Text;
            }
            else
            {
                if (GitCommandHelpers.Plink())
                {
                    if (!File.Exists(Settings.Pageant))
                        MessageBox.Show(_cannotLoadPutty.Text, PuttyText);
                    else
                        GitCommandHelpers.StartPageantForRemote(Remotes.Text);
                }

                destination = Remotes.Text;
                remote = Remotes.Text.Trim();
            }

            string pushCmd;
            if (TabControlTagBranch.SelectedTab == BranchTab)
            {
                bool track = newBranch;
                string[] remotes = Remotes.DataSource as string[];
                if (remotes != null)
                    foreach (string remoteBranch in remotes)
                        if (!string.IsNullOrEmpty(remoteBranch) && Branch.Text.StartsWith(remoteBranch))
                            track = false;

                pushCmd = GitCommandHelpers.PushCmd(destination, Branch.Text, RemoteBranch.Text,
                                                          PushAllBranches.Checked, ForcePushBranches.Checked, track);
            }
            else if (TabControlTagBranch.SelectedTab == TagTab)
                pushCmd = GitCommandHelpers.PushTagCmd(destination, TagComboBox.Text, PushAllTags.Checked,
                                                             ForcePushBranches.Checked);
            else
            {
                var pushActions = new List<GitPushAction>();
                foreach (DataRow row in _branchTable.Rows)
                {
                    var push = (bool)row["Push"];
                    var force = (bool)row["Force"];
                    var delete = (bool)row["Delete"];

                    if (push || force)
                        pushActions.Add(new GitPushAction(row["Local"].ToString(), row["Remote"].ToString(), force));
                    else if (delete)
                        pushActions.Add(new GitPushAction(row["Remote"].ToString()));
                }
                pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions);
            }

            ScriptManager.RunEventScripts(ScriptEvent.BeforePush);

            var form = new FormRemoteProcess(pushCmd)
                       {
                           Remote = remote,
                           Text = string.Format(_pushToCaption.Text, destination),
                           HandleOnExitCallback = new HandleOnExit(HandlePushOnExit)
                       };

            form.ShowDialog();

            if (!GitCommandHelpers.InTheMiddleOfConflictedMerge() &&
                !GitCommandHelpers.InTheMiddleOfRebase() && !form.ErrorOccurred())
            {
                ScriptManager.RunEventScripts(ScriptEvent.AfterPush);
                if (_createPullRequestCB.Checked)
                    GitUICommands.Instance.StartCreatePullRequest();
                return true;
            }

            return false;
        }
示例#7
0
        public bool PullChanges()
        {
            if (PullFromUrl.Checked && string.IsNullOrEmpty(PullSource.Text))
            {
                MessageBox.Show(_selectSourceDirectory.Text);
                return false;
            }
            if (PullFromRemote.Checked && string.IsNullOrEmpty(Remotes.Text) && !PullAll())
            {
                MessageBox.Show(_selectRemoteRepository.Text);
                return false;
            }

            if (!Fetch.Checked && Branches.Text == "*")
            {
                MessageBox.Show(_fetchAllBranchesCanOnlyWithFetch.Text);
                return false;
            }

            if (Merge.Checked)
                Settings.PullMerge = "merge";
            if (Rebase.Checked)
                Settings.PullMerge = "rebase";
            if (Fetch.Checked)
                Settings.PullMerge = "fetch";

            Settings.AutoStash = AutoStash.Checked;

            if (Rebase.Checked && GitCommandHelpers.IsMergeCommit("HEAD"))
            {
                if (MessageBox.Show(_areYouSureYouWantToRebaseMerge.Text, _areYouSureYouWantToRebaseMergeCaption.Text, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                    return false;
            }

            Repositories.RepositoryHistory.AddMostRecentRepository(PullSource.Text);

            string source;

            if (PullFromUrl.Checked)
                source = PullSource.Text;
            else
            {
                LoadPuttyKey();
                source = PullAll() ? "--all" : Remotes.Text;
            }

            ScriptManager.RunEventScripts(ScriptEvent.BeforePull);

            var stashed = false;
            if (!Fetch.Checked && AutoStash.Checked && GitCommandHelpers.GitStatus(false).Count > 0)
            {
                new FormProcess("stash save").ShowDialog();
                stashed = true;
            }

            FormProcess process = null;
            if (Fetch.Checked)
            {
                process = new FormRemoteProcess(GitCommandHelpers.FetchCmd(source, Branches.Text, null));
            }
            else
            {
                string localBranch = GitCommandHelpers.GetSelectedBranch();
                if (localBranch.Equals("(no branch)", StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(Branches.Text))
                    localBranch = null;

                if (Merge.Checked)
                    process = new FormRemoteProcess(GitCommandHelpers.PullCmd(source, Branches.Text, localBranch, false));
                else if (Rebase.Checked)
                    process = new FormRemoteProcess(GitCommandHelpers.PullCmd(source, Branches.Text, localBranch, true));
            }

            if (process != null)
            {
                if (!PullAll())
                    process.Remote = source;
                process.ShowDialog();
                ErrorOccurred = process.ErrorOccurred();
            }

            try
            {
                if (!GitCommandHelpers.InTheMiddleOfConflictedMerge() &&
                    !GitCommandHelpers.InTheMiddleOfRebase() &&
                    (process != null && !process.ErrorOccurred()))
                {
                    return true;
                }

                // Rebase failed -> special 'rebase' merge conflict
                if (Rebase.Checked && GitCommandHelpers.InTheMiddleOfRebase())
                {
                    GitUICommands.Instance.StartRebaseDialog(null);
                    if (!GitCommandHelpers.InTheMiddleOfConflictedMerge() &&
                        !GitCommandHelpers.InTheMiddleOfRebase())
                    {
                        return true;
                    }
                }
                else
                {
                    MergeConflictHandler.HandleMergeConflicts();
                    if (!GitCommandHelpers.InTheMiddleOfConflictedMerge() &&
                        !GitCommandHelpers.InTheMiddleOfRebase())
                    {
                        return true;
                    }
                }

                if (!AutoStash.Checked || !stashed || GitCommandHelpers.InTheMiddleOfConflictedMerge() ||
                    GitCommandHelpers.InTheMiddleOfRebase())
                {
                    return true;
                }

            }
            finally
            {
                if (stashed &&
                    process != null &&
                    !process.ErrorOccurred() &&
                    !GitCommandHelpers.InTheMiddleOfConflictedMerge() &&
                    !GitCommandHelpers.InTheMiddleOfRebase() &&
                    MessageBox.Show(_applyShashedItemsAgain.Text, _applyShashedItemsAgainCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    new FormProcess("stash pop").ShowDialog();
                    MergeConflictHandler.HandleMergeConflicts();
                }

                ScriptManager.RunEventScripts(ScriptEvent.AfterPull);
            }

            return false;
        }
示例#8
0
        private void OkClick(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.Default;
                branchListLoader.Cancel();

                var dirTo = _NO_TRANSLATE_To.Text;
                if (!dirTo.EndsWith(Settings.PathSeparator.ToString()) && !dirTo.EndsWith(Settings.PathSeparatorWrong.ToString()))
                    dirTo += Settings.PathSeparator.ToString();

                dirTo += _NO_TRANSLATE_NewDirectory.Text;

                Repositories.AddMostRecentRepository(_NO_TRANSLATE_From.Text);
                Repositories.AddMostRecentRepository(dirTo);

                if (!Directory.Exists(dirTo))
                    Directory.CreateDirectory(dirTo);

                var cloneCmd = GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo,
                            CentralRepository.Checked, cbIntializeAllSubmodules.Checked, Branches.Text, null);
                using (var fromProcess = new FormRemoteProcess(Module, Settings.GitCommand, cloneCmd))
                {
                    fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text);
                    fromProcess.ShowDialog(this);

                    if (fromProcess.ErrorOccurred() || Module.InTheMiddleOfPatch())
                        return;
                }

                if (openedFromProtocolHandler && AskIfNewRepositoryShouldBeOpened(dirTo))
                {
                    Hide();
                    GitUICommands uiCommands = new GitUICommands(dirTo);
                    uiCommands.StartBrowseDialog();
                }
                else if (ShowInTaskbar == false && AskIfNewRepositoryShouldBeOpened(dirTo))
                    if (GitModuleChanged != null)
                        GitModuleChanged(new GitModule(dirTo));

                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void OkClick(object sender, EventArgs e)
        {
            try
            {
                var dirTo = DestinationFolder;

                Repositories.AddMostRecentRepository(_NO_TRANSLATE_From.Text);
                Repositories.AddMostRecentRepository(dirTo);

                if (!Directory.Exists(dirTo))
                    Directory.CreateDirectory(dirTo);

                var fromProcess =
                    new FormRemoteProcess(Settings.GitCommand,
                                    GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo,
                                                                     CentralRepository.Checked, Branches.Text, null));
                fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text);
                fromProcess.ShowDialog(this);

                if (fromProcess.ErrorOccurred || Settings.Module.InTheMiddleOfPatch())
                    return;

                if (ShowInTaskbar == false && AskIfNewRepositoryShouldBeOpened(dirTo))
                {
                    Settings.WorkingDir = dirTo;

                    if (File.Exists(Settings.WorkingDir + ".gitmodules") &&
                        AskIfSubmodulesShouldBeInitialized())
                        GitUICommands.Instance.StartInitSubmodulesRecursiveDialog(this);
                }
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#10
0
 private void PruneClick(object sender, EventArgs e)
 {
     FormRemoteProcess.ShowDialog(this, "remote prune " + _remote);
 }
示例#11
0
 private void UpdateBranchClick(object sender, EventArgs e)
 {
     FormRemoteProcess.ShowDialog(this, "remote update");
 }
示例#12
0
        private void SaveClick(object sender, EventArgs e)
        {
            var output = "";

            if ((string.IsNullOrEmpty(comboBoxPushUrl.Text) && checkBoxSepPushUrl.Checked) ||
                (comboBoxPushUrl.Text == Url.Text))
            {
                checkBoxSepPushUrl.Checked = false;
            }

            if (string.IsNullOrEmpty(_remote))
            {
                if (string.IsNullOrEmpty(RemoteName.Text) && string.IsNullOrEmpty(Url.Text))
                {
                    return;
                }

                output = Module.AddRemote(RemoteName.Text, Url.Text);

                if (checkBoxSepPushUrl.Checked)
                {
                    Module.SetPathSetting(string.Format(SettingKeyString.RemotePushUrl, RemoteName.Text), comboBoxPushUrl.Text);
                }

                if (MessageBox.Show(this, _questionAutoPullBehaviour.Text, _questionAutoPullBehaviourCaption.Text,
                                    MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    var remoteUrl = Url.Text;

                    if (!string.IsNullOrEmpty(remoteUrl))
                    {
                        FormRemoteProcess.ShowDialog(this, "remote update");
                        ConfigureRemotes();
                    }
                    else
                    {
                        MessageBox.Show(this, _warningValidRemote.Text, _warningValidRemoteCaption.Text);
                    }
                }
            }
            else
            {
                if (RemoteName.Text != _remote)
                {
                    output = Module.RenameRemote(_remote, RemoteName.Text);
                }

                Module.SetPathSetting(string.Format(SettingKeyString.RemoteUrl, RemoteName.Text), Url.Text);
                Module.SetPathSetting(string.Format("remote.{0}.puttykeyfile", RemoteName.Text), PuttySshKey.Text);
                if (checkBoxSepPushUrl.Checked)
                {
                    Module.SetPathSetting(string.Format(SettingKeyString.RemotePushUrl, RemoteName.Text), comboBoxPushUrl.Text);
                }
                else
                {
                    Module.UnsetSetting(string.Format(SettingKeyString.RemotePushUrl, RemoteName.Text));
                }
            }

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(this, output, _hintDelete.Text);
            }

            Initialize();
        }
示例#13
0
        private bool PushChanges(IWin32Window owner)
        {
            if (PullFromUrl.Checked && string.IsNullOrEmpty(PushDestination.Text))
            {
                MessageBox.Show(owner, _selectDestinationDirectory.Text);
                return(false);
            }
            if (PullFromRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text))
            {
                MessageBox.Show(owner, _selectRemote.Text);
                return(false);
            }
            if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text) &&
                !PushAllTags.Checked)
            {
                MessageBox.Show(owner, _selectTag.Text);
                return(false);
            }

            //Extra check if the branch is already known to the remote, give a warning when not.
            //This is not possible when the remote is an URL, but this is ok since most users push to
            //known remotes anyway.
            if (TabControlTagBranch.SelectedTab == BranchTab && PullFromRemote.Checked)
            {
                //If the current branch is not the default push, and not known by the remote
                //(as far as we know since we are disconnected....)
                if (RemoteBranch.Text != GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text) &&
                    !Module.GetHeads(true, true).Exists(x => x.Remote == _NO_TRANSLATE_Remotes.Text && x.LocalName == RemoteBranch.Text))
                {
                    //Ask if this is really what the user wants
                    if (MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) ==
                        DialogResult.No)
                    {
                        return(false);
                    }
                }
            }

            Repositories.AddMostRecentRepository(PushDestination.Text);
            Settings.PushAllTags              = PushAllTags.Checked;
            Settings.AutoPullOnRejected       = AutoPullOnRejected.Checked;
            Settings.RecursiveSubmodulesCheck = RecursiveSubmodulesCheck.Checked;

            var    remote = "";
            string destination;

            if (PullFromUrl.Checked)
            {
                destination = PushDestination.Text;
            }
            else
            {
                if (GitCommandHelpers.Plink())
                {
                    if (!File.Exists(Settings.Pageant))
                    {
                        MessageBox.Show(owner, _cannotLoadPutty.Text, PuttyText);
                    }
                    else
                    {
                        Module.StartPageantForRemote(_NO_TRANSLATE_Remotes.Text);
                    }
                }

                destination = _NO_TRANSLATE_Remotes.Text;
                remote      = _NO_TRANSLATE_Remotes.Text.Trim();
            }

            string pushCmd;

            if (TabControlTagBranch.SelectedTab == BranchTab)
            {
                bool track = ReplaceTrackingReference.Checked;
                if (!track && !string.IsNullOrWhiteSpace(RemoteBranch.Text))
                {
                    GitHead selectedLocalBranch = _NO_TRANSLATE_Branch.SelectedItem as GitHead;
                    track = selectedLocalBranch != null && string.IsNullOrEmpty(selectedLocalBranch.TrackingRemote);

                    string[] remotes = _NO_TRANSLATE_Remotes.DataSource as string[];
                    if (remotes != null)
                    {
                        foreach (string remoteBranch in remotes)
                        {
                            if (!string.IsNullOrEmpty(remoteBranch) && _NO_TRANSLATE_Branch.Text.StartsWith(remoteBranch))
                            {
                                track = false;
                            }
                        }
                    }

                    if (track)
                    {
                        DialogResult result = MessageBox.Show(String.Format(_updateTrackingReference.Text, selectedLocalBranch.Name, RemoteBranch.Text), _pushCaption.Text, MessageBoxButtons.YesNoCancel);

                        if (result == DialogResult.Cancel)
                        {
                            return(false);
                        }

                        track = result == DialogResult.OK;
                    }
                }

                pushCmd = GitCommandHelpers.PushCmd(destination, _NO_TRANSLATE_Branch.Text, RemoteBranch.Text,
                                                    PushAllBranches.Checked, ForcePushBranches.Checked, track, RecursiveSubmodulesCheck.Checked);
            }
            else if (TabControlTagBranch.SelectedTab == TagTab)
            {
                pushCmd = GitCommandHelpers.PushTagCmd(destination, TagComboBox.Text, PushAllTags.Checked,
                                                       ForcePushBranches.Checked);
            }
            else
            {
                // Push Multiple Branches Tab selected
                var pushActions = new List <GitPushAction>();
                foreach (DataRow row in _branchTable.Rows)
                {
                    var push   = Convert.ToBoolean(row["Push"]);
                    var force  = Convert.ToBoolean(row["Force"]);
                    var delete = Convert.ToBoolean(row["Delete"]);

                    if (push || force)
                    {
                        pushActions.Add(new GitPushAction(row["Local"].ToString(), row["Remote"].ToString(), force));
                    }
                    else if (delete)
                    {
                        pushActions.Add(new GitPushAction(row["Remote"].ToString()));
                    }
                }
                pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions);
            }

            ScriptManager.RunEventScripts(Module, ScriptEvent.BeforePush);

            //controls can be accessed only from UI thread
            candidateForRebasingMergeCommit = Settings.PullMerge == Settings.PullAction.Rebase && PullFromRemote.Checked && !PushAllBranches.Checked && TabControlTagBranch.SelectedTab == BranchTab;
            selectedBranch           = _NO_TRANSLATE_Branch.Text;
            selectedBranchRemote     = _NO_TRANSLATE_Remotes.Text;
            selectedRemoteBranchName = RemoteBranch.Text;

            using (var form = new FormRemoteProcess(Module, pushCmd)
            {
                Remote = remote,
                Text = string.Format(_pushToCaption.Text, destination),
                HandleOnExitCallback = HandlePushOnExit
            })
            {
                form.ShowDialog(owner);

                if (!Module.InTheMiddleOfConflictedMerge() &&
                    !Module.InTheMiddleOfRebase() && !form.ErrorOccurred())
                {
                    ScriptManager.RunEventScripts(Module, ScriptEvent.AfterPush);
                    if (_createPullRequestCB.Checked)
                    {
                        UICommands.StartCreatePullRequest(owner);
                    }
                    return(true);
                }
            }

            return(false);
        }
示例#14
0
        public bool PullChanges()
        {
            if (PullFromUrl.Checked && string.IsNullOrEmpty(PullSource.Text))
            {
                MessageBox.Show(this, _selectSourceDirectory.Text);
                return(false);
            }
            if (PullFromRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text) && !PullAll())
            {
                MessageBox.Show(this, _selectRemoteRepository.Text);
                return(false);
            }

            if (!Fetch.Checked && Branches.Text == "*")
            {
                MessageBox.Show(this, _fetchAllBranchesCanOnlyWithFetch.Text);
                return(false);
            }

            if (Merge.Checked)
            {
                Settings.PullMerge = "merge";
            }
            if (Rebase.Checked)
            {
                Settings.PullMerge = "rebase";
            }
            if (Fetch.Checked)
            {
                Settings.PullMerge = "fetch";
            }

            Settings.AutoStash = AutoStash.Checked;

            //ask only if exists commit not pushed to remote yet
            if (Rebase.Checked && PullFromRemote.Checked)
            {
                string branchRemote = _NO_TRANSLATE_Remotes.Text;
                string remoteBranchName;
                if (Branches.Text.IsNullOrEmpty())
                {
                    remoteBranchName = Settings.Module.GetSetting("branch." + branch + ".merge");
                    remoteBranchName = Settings.Module.RunGitCmd("name-rev --name-only \"" + remoteBranchName + "\"").Trim();
                }
                else
                {
                    remoteBranchName = Branches.Text;
                }
                remoteBranchName = branchRemote + "/" + remoteBranchName;
                if (Settings.Module.ExistsMergeCommit(remoteBranchName, branch))
                {
                    DialogResult dr = MessageBox.Show(this, _areYouSureYouWantToRebaseMerge.Text, _areYouSureYouWantToRebaseMergeCaption.Text, MessageBoxButtons.YesNoCancel);
                    if (dr == DialogResult.Cancel)
                    {
                        Close();
                        return(false);
                    }
                    else if (dr != DialogResult.Yes)
                    {
                        return(false);
                    }
                }
            }

            Repositories.RepositoryHistory.AddMostRecentRepository(PullSource.Text);

            string source;

            if (PullFromUrl.Checked)
            {
                source = PullSource.Text;
            }
            else
            {
                LoadPuttyKey();
                source = PullAll() ? "--all" : _NO_TRANSLATE_Remotes.Text;
            }

            ScriptManager.RunEventScripts(ScriptEvent.BeforePull);

            var stashed = false;

            if (!Fetch.Checked && AutoStash.Checked &&
                Settings.Module.GitStatus(UntrackedFilesMode.No, IgnoreSubmodulesMode.Default).Count > 0)
            {
                new FormProcess("stash save").ShowDialog(this);
                stashed = true;
            }

            FormProcess process = null;

            if (Fetch.Checked)
            {
                process = new FormRemoteProcess(Settings.Module.FetchCmd(source, Branches.Text, null));
            }
            else
            {
                string localBranch = Settings.Module.GetSelectedBranch();
                if (localBranch.Equals("(no branch)", StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(Branches.Text))
                {
                    localBranch = null;
                }

                if (Merge.Checked)
                {
                    process = new FormRemoteProcess(Settings.Module.PullCmd(source, Branches.Text, localBranch, false));
                }
                else if (Rebase.Checked)
                {
                    process = new FormRemoteProcess(Settings.Module.PullCmd(source, Branches.Text, localBranch, true));
                }
            }

            if (process != null)
            {
                if (!PullAll())
                {
                    process.Remote = source;
                }
                process.ShowDialog(this);
                ErrorOccurred = process.ErrorOccurred();
            }

            try
            {
                if (!Settings.Module.InTheMiddleOfConflictedMerge() &&
                    !Settings.Module.InTheMiddleOfRebase() &&
                    (process != null && !process.ErrorOccurred()))
                {
                    if (!Fetch.Checked && File.Exists(Settings.WorkingDir + ".gitmodules"))
                    {
                        if (!IsSubmodulesIntialized() && AskIfSubmodulesShouldBeInitialized())
                        {
                            GitUICommands.Instance.StartInitSubmodulesRecursiveDialog(this);
                        }
                    }

                    return(true);
                }

                // Rebase failed -> special 'rebase' merge conflict
                if (Rebase.Checked && Settings.Module.InTheMiddleOfRebase())
                {
                    GitUICommands.Instance.StartRebaseDialog(null);
                    if (!Settings.Module.InTheMiddleOfConflictedMerge() &&
                        !Settings.Module.InTheMiddleOfRebase())
                    {
                        return(true);
                    }
                }
                else
                {
                    MergeConflictHandler.HandleMergeConflicts(this);
                    if (!Settings.Module.InTheMiddleOfConflictedMerge() &&
                        !Settings.Module.InTheMiddleOfRebase())
                    {
                        return(true);
                    }
                }

                if (!AutoStash.Checked || !stashed || Settings.Module.InTheMiddleOfConflictedMerge() ||
                    Settings.Module.InTheMiddleOfRebase())
                {
                    return(true);
                }
            }
            finally
            {
                if (stashed &&
                    process != null &&
                    !process.ErrorOccurred() &&
                    !Settings.Module.InTheMiddleOfConflictedMerge() &&
                    !Settings.Module.InTheMiddleOfRebase() &&
                    MessageBox.Show(this, _applyShashedItemsAgain.Text, _applyShashedItemsAgainCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    new FormProcess("stash pop").ShowDialog(this);
                    MergeConflictHandler.HandleMergeConflicts(this);
                }

                ScriptManager.RunEventScripts(ScriptEvent.AfterPull);
            }

            return(false);
        }
示例#15
0
        public bool PullChanges()
        {
            if (PullFromUrl.Checked && string.IsNullOrEmpty(PullSource.Text))
            {
                MessageBox.Show(this, _selectSourceDirectory.Text);
                return false;
            }
            if (PullFromRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text) && !PullAll())
            {
                MessageBox.Show(this, _selectRemoteRepository.Text);
                return false;
            }

            if (!Fetch.Checked && Branches.Text == "*")
            {
                MessageBox.Show(this, _fetchAllBranchesCanOnlyWithFetch.Text);
                return false;
            }

            if (Merge.Checked)
                Settings.PullMerge = "merge";
            if (Rebase.Checked)
                Settings.PullMerge = "rebase";
            if (Fetch.Checked)
                Settings.PullMerge = "fetch";

            Settings.AutoStash = AutoStash.Checked;

            //ask only if exists commit not pushed to remote yet
            if (Rebase.Checked && PullFromRemote.Checked)
            {

                string branchRemote = _NO_TRANSLATE_Remotes.Text;
                string remoteBranchName;
                if (Branches.Text.IsNullOrEmpty())
                {
                    remoteBranchName = Settings.Module.GetSetting("branch." + branch + ".merge");
                    remoteBranchName = Settings.Module.RunGitCmd("name-rev --name-only \"" + remoteBranchName + "\"").Trim();
                }
                else
                    remoteBranchName = Branches.Text;
                remoteBranchName = branchRemote + "/" + remoteBranchName;
                if (Settings.Module.ExistsMergeCommit(remoteBranchName, branch))
                {
                    DialogResult dr = MessageBox.Show(this, _areYouSureYouWantToRebaseMerge.Text, _areYouSureYouWantToRebaseMergeCaption.Text, MessageBoxButtons.YesNoCancel);
                    if (dr == DialogResult.Cancel)
                    {
                        Close();
                        return false;
                    }
                    else if (dr != DialogResult.Yes)
                        return false;
                }
            }

            Repositories.RepositoryHistory.AddMostRecentRepository(PullSource.Text);

            string source;

            if (PullFromUrl.Checked)
                source = PullSource.Text;
            else
            {
                LoadPuttyKey();
                source = PullAll() ? "--all" : _NO_TRANSLATE_Remotes.Text;
            }

            ScriptManager.RunEventScripts(ScriptEvent.BeforePull);

            var stashed = false;
            if (!Fetch.Checked && AutoStash.Checked && Settings.Module.GitStatus(false).Count > 0)
            {
                new FormProcess("stash save").ShowDialog(this);
                stashed = true;
            }

            FormProcess process = null;
            if (Fetch.Checked)
            {
                process = new FormRemoteProcess(Settings.Module.FetchCmd(source, Branches.Text, null));
            }
            else
            {
                string localBranch = Settings.Module.GetSelectedBranch();
                if (localBranch.Equals("(no branch)", StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(Branches.Text))
                    localBranch = null;

                if (Merge.Checked)
                    process = new FormRemoteProcess(Settings.Module.PullCmd(source, Branches.Text, localBranch, false));
                else if (Rebase.Checked)
                    process = new FormRemoteProcess(Settings.Module.PullCmd(source, Branches.Text, localBranch, true));
            }

            if (process != null)
            {
                if (!PullAll())
                    process.Remote = source;
                process.ShowDialog(this);
                ErrorOccurred = process.ErrorOccurred();
            }

            try
            {
                if (!Settings.Module.InTheMiddleOfConflictedMerge() &&
                    !Settings.Module.InTheMiddleOfRebase() &&
                    (process != null && !process.ErrorOccurred()))
                {
                    if (!Fetch.Checked && File.Exists(Settings.WorkingDir + ".gitmodules"))
                    {
                        if (!IsSubmodulesIntialized() && AskIfSubmodulesShouldBeInitialized())
                            GitUICommands.Instance.StartInitSubmodulesRecursiveDialog(this);
                    }

                    return true;
                }

                // Rebase failed -> special 'rebase' merge conflict
                if (Rebase.Checked && Settings.Module.InTheMiddleOfRebase())
                {
                    GitUICommands.Instance.StartRebaseDialog(null);
                    if (!Settings.Module.InTheMiddleOfConflictedMerge() &&
                        !Settings.Module.InTheMiddleOfRebase())
                    {
                        return true;
                    }
                }
                else
                {
                    MergeConflictHandler.HandleMergeConflicts(this);
                    if (!Settings.Module.InTheMiddleOfConflictedMerge() &&
                        !Settings.Module.InTheMiddleOfRebase())
                    {
                        return true;
                    }
                }

                if (!AutoStash.Checked || !stashed || Settings.Module.InTheMiddleOfConflictedMerge() ||
                    Settings.Module.InTheMiddleOfRebase())
                {
                    return true;
                }

            }
            finally
            {
                if (stashed &&
                    process != null &&
                    !process.ErrorOccurred() &&
                    !Settings.Module.InTheMiddleOfConflictedMerge() &&
                    !Settings.Module.InTheMiddleOfRebase() &&
                    MessageBox.Show(this, _applyShashedItemsAgain.Text, _applyShashedItemsAgainCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    new FormProcess("stash pop").ShowDialog(this);
                    MergeConflictHandler.HandleMergeConflicts(this);
                }

                ScriptManager.RunEventScripts(ScriptEvent.AfterPull);
            }

            return false;
        }
示例#16
0
        private void OkClick(object sender, EventArgs e)
        {
            try
            {
                var dirTo = _NO_TRANSLATE_To.Text;
                if (!dirTo.EndsWith(Settings.PathSeparator.ToString()) && !dirTo.EndsWith(Settings.PathSeparatorWrong.ToString()))
                    dirTo += Settings.PathSeparator.ToString();

                dirTo += _NO_TRANSLATE_NewDirectory.Text;

                Repositories.RepositoryHistory.AddMostRecentRepository(_NO_TRANSLATE_From.Text);
                Repositories.RepositoryHistory.AddMostRecentRepository(dirTo);

                var fromProcess =
                    new FormRemoteProcess(Settings.GitCommand,
                                    GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo,
                                                                     CentralRepository.Checked, Branches.Text, null));
                fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text);
                fromProcess.ShowDialog();

                if (fromProcess.ErrorOccurred() || GitCommandHelpers.InTheMiddleOfPatch())
                    return;

                if (ShowInTaskbar == false && AskIfNewRepositoryShouldBeOpened(dirTo))
                {
                    Settings.WorkingDir = dirTo;

                    if (File.Exists(Settings.WorkingDir + ".gitmodules") &&
                        AskIfSubmodulesShouldBeInitialized())
                        InitSubmodules();
                }
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }