private void RemoveRemoteTag(string tagName) { var pushCmd = string.Format("push \"{0}\" :refs/tags/{1}", remotesComboboxControl1.SelectedRemote, tagName); ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); using (var form = new FormRemoteProcess(Module, pushCmd) { ////Remote = currentRemote, ////Text = string.Format(_deleteFromCaption.Text, currentRemote), }) { form.ShowDialog(); if (!Module.InTheMiddleOfAction() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPush); } } }
private void RemoveRemoteTag(string tagName) { var pushCmd = string.Format("push \"{0}\" :refs/tags/{1}", currentRemote, tagName); ScriptManager.RunEventScripts(Module, ScriptEvent.BeforePush); using (var form = new FormRemoteProcess(Module, pushCmd) { Remote = currentRemote, Text = string.Format(_deleteFromCaption.Text, currentRemote), }) { form.ShowDialog(); if (!Module.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(Module, ScriptEvent.AfterPush); } } }
private bool PushChanges(IWin32Window owner) { ErrorOccurred = false; if (PushToUrl.Checked && string.IsNullOrEmpty(PushDestination.Text)) { MessageBox.Show(owner, _selectDestinationDirectory.Text); return false; } if (PushToRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text)) { MessageBox.Show(owner, _selectRemote.Text); return false; } if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text)) { 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 && PushToRemote.Checked && !Module.IsBareRepository()) { //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 (_NO_TRANSLATE_Branch.Text != AllRefs && RemoteBranch.Text != GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text) && !Module.GetRefs(true, true).Any(x => x.Remote == _NO_TRANSLATE_Remotes.Text && x.LocalName == RemoteBranch.Text)) { //Ask if this is really what the user wants if (!AppSettings.DontConfirmPushNewBranch && MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) == DialogResult.No) { return false; } } } if (PushToUrl.Checked) Repositories.AddMostRecentRepository(PushDestination.Text); AppSettings.RecursiveSubmodules = RecursiveSubmodules.SelectedIndex; var remote = ""; string destination; if (PushToUrl.Checked) { destination = PushDestination.Text; } else { if (GitCommandHelpers.Plink()) { if (!File.Exists(AppSettings.Pageant)) MessageBoxes.PAgentNotFound(owner); 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)) { GitRef selectedLocalBranch = _NO_TRANSLATE_Branch.SelectedItem as GitRef; 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 && !AppSettings.DontConfirmAddTrackingRef) { 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.Yes; } } // Try to make source rev into a fully qualified branch name. If that // doesn't exist, then it must be something other than a branch, so // fall back to using the name just as it was passed in. string srcRev = ""; bool pushAllBranches = false; if (_NO_TRANSLATE_Branch.Text == AllRefs) pushAllBranches = true; else { srcRev = GitCommandHelpers.GetFullBranchName(_NO_TRANSLATE_Branch.Text); if (String.IsNullOrEmpty(Module.RevParse(srcRev))) srcRev = _NO_TRANSLATE_Branch.Text; } pushCmd = GitCommandHelpers.PushCmd(destination, srcRev, RemoteBranch.Text, pushAllBranches, ForcePushBranches.Checked, track, RecursiveSubmodules.SelectedIndex); } else if (TabControlTagBranch.SelectedTab == TagTab) { string tag = TagComboBox.Text; bool pushAllTags = false; if (tag == AllRefs) { tag = ""; pushAllTags = true; } pushCmd = GitCommandHelpers.PushTagCmd(destination, tag, pushAllTags, 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(this, ScriptEvent.BeforePush); //controls can be accessed only from UI thread _selectedBranch = _NO_TRANSLATE_Branch.Text; _candidateForRebasingMergeCommit = PushToRemote.Checked && (_selectedBranch != AllRefs) && TabControlTagBranch.SelectedTab == BranchTab; _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); ErrorOccurred = form.ErrorOccurred(); if (!Module.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPush); if (_createPullRequestCB.Checked) UICommands.StartCreatePullRequest(owner); return true; } } return false; }
private void PushTag(string tagName) { var pushCmd = GitCommandHelpers.PushTagCmd(_currentRemote, tagName, false); ScriptManager.RunEventScripts(Module, ScriptEvent.BeforePush); using (var form = new FormRemoteProcess(Module, pushCmd) { Remote = _currentRemote, Text = string.Format(_pushToCaption.Text, _currentRemote), }) { form.ShowDialog(); if (!Module.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(Module, ScriptEvent.AfterPush); } } }
private void PushTag(string tagName) { var currentBranchRemote = Settings.Module.GetSetting(string.Format("branch.{0}.remote", Settings.Module.GetSelectedBranch())); var pushCmd = GitCommandHelpers.PushTagCmd(currentBranchRemote, tagName, false); ScriptManager.RunEventScripts(ScriptEvent.BeforePush); var form = new FormRemoteProcess(pushCmd) { Remote = currentBranchRemote, Text = string.Format(_pushToCaption.Text, currentBranchRemote), }; form.ShowDialog(); if (!Settings.Module.InTheMiddleOfConflictedMerge() && !Settings.Module.InTheMiddleOfRebase() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(ScriptEvent.AfterPush); } }
private void OkClick(object sender, EventArgs e) { try { Cursor = Cursors.Default; _branchListLoader.Cancel(); var dirTo = _NO_TRANSLATE_To.Text; if (!dirTo.EndsWith(AppSettings.PathSeparator.ToString()) && !dirTo.EndsWith(AppSettings.PathSeparatorWrong.ToString())) dirTo += AppSettings.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, AppSettings.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 && GitModuleChanged != null && AskIfNewRepositoryShouldBeOpened(dirTo)) 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 { Cursor = Cursors.Default; _branchListLoader.Cancel(); var dirTo = Path.Combine(_NO_TRANSLATE_To.Text, _NO_TRANSLATE_NewDirectory.Text); Repositories.AddMostRecentRepository(_NO_TRANSLATE_From.Text); if (!Directory.Exists(dirTo)) Directory.CreateDirectory(dirTo); // Shallow clone params int? depth = null; bool? isSingleBranch = null; if(!cbDownloadFullHistory.Checked) { depth = 1; // Single branch considerations: // If neither depth nor single-branch family params are specified, then it's like no-single-branch by default. // If depth is specified, then single-branch is assumed. // But with single-branch it's really nontrivial to switch to another branch in the GUI, and it's very hard in cmdline (obvious choices to fetch another branch lead to local repo corruption). // So let's reset it to no-single-branch to (a) have the same branches behavior as with full clone, and (b) make it easier for users when switching branches. isSingleBranch = false; } // Branch name param string branch = _NO_TRANSLATE_Branches.Text; if(branch == _branchDefaultRemoteHead.Text) branch = ""; else if(branch == _branchNone.Text) branch = null; var cloneCmd = GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo, CentralRepository.Checked, cbIntializeAllSubmodules.Checked, branch, depth, isSingleBranch); using (var fromProcess = new FormRemoteProcess(Module, AppSettings.GitCommand, cloneCmd)) { fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text); fromProcess.ShowDialog(this); if (fromProcess.ErrorOccurred() || Module.InTheMiddleOfPatch()) return; } Repositories.AddMostRecentRepository(dirTo); if (openedFromProtocolHandler && AskIfNewRepositoryShouldBeOpened(dirTo)) { Hide(); GitUICommands uiCommands = new GitUICommands(dirTo); uiCommands.StartBrowseDialog(); } else if (ShowInTaskbar == false && GitModuleChanged != null && AskIfNewRepositoryShouldBeOpened(dirTo)) GitModuleChanged(this, new GitModuleEventArgs(new GitModule(dirTo))); Close(); } catch (Exception ex) { MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Clone(IHostedRepository repo) { string targetDir = GetTargetDir(); if (targetDir == null) return; string repoSrc = repo.CloneReadWriteUrl; string cmd = GitCommandHelpers.CloneCmd(repoSrc, targetDir); FormRemoteProcess formRemoteProcess = new FormRemoteProcess(new GitModule(null), AppSettings.GitCommand, cmd); formRemoteProcess.Remote = repoSrc; formRemoteProcess.ShowDialog(); if (formRemoteProcess.ErrorOccurred()) return; GitModule module = new GitModule(targetDir); if (_addRemoteAsTB.Text.Trim().Length > 0 && !string.IsNullOrEmpty(repo.ParentReadOnlyUrl)) { var error = module.AddRemote(_addRemoteAsTB.Text.Trim(), repo.ParentReadOnlyUrl); if (!string.IsNullOrEmpty(error)) MessageBox.Show(this, error, _strCouldNotAddRemote.Text); } if (GitModuleChanged != null) GitModuleChanged(this, new GitModuleEventArgs(module)); Close(); }
private bool PushChanges(IWin32Window owner) { ErrorOccurred = false; if (PushToUrl.Checked && string.IsNullOrEmpty(PushDestination.Text)) { MessageBox.Show(owner, _selectDestinationDirectory.Text); return false; } if (PushToRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text)) { MessageBox.Show(owner, _selectRemote.Text); return false; } if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text)) { 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 && PushToRemote.Checked && !Module.IsBareRepository()) { //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 (_NO_TRANSLATE_Branch.Text != AllRefs && RemoteBranch.Text != GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text, _NO_TRANSLATE_Branch.Text) && !IsBranchKnownToRemote(_NO_TRANSLATE_Remotes.Text, RemoteBranch.Text)) { //Ask if this is really what the user wants if (!AppSettings.DontConfirmPushNewBranch && MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) == DialogResult.No) { return false; } } } if (PushToUrl.Checked) Repositories.AddMostRecentRepository(PushDestination.Text); AppSettings.RecursiveSubmodules = RecursiveSubmodules.SelectedIndex; var remote = ""; string destination; if (PushToUrl.Checked) { destination = PushDestination.Text; } else { EnsurePageant(_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)) { GitRef selectedLocalBranch = _NO_TRANSLATE_Branch.SelectedItem as GitRef; 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; var autoSetupMerge = Module.EffectiveConfigFile.GetValue("branch.autoSetupMerge"); if (autoSetupMerge.IsNotNullOrWhitespace() && autoSetupMerge.ToLowerInvariant() == "false") { track = false; } if (track && !AppSettings.DontConfirmAddTrackingRef) { 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.Yes; } } if (ForcePushBranches.Checked) { if (GitCommandHelpers.VersionInUse.SupportPushForceWithLease) { var choice = MessageBox.Show(this, _useForceWithLeaseInstead.Text, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); switch (choice) { case DialogResult.Yes: ForcePushBranches.Checked = false; ckForceWithLease.Checked = true; break; case DialogResult.Cancel: return false; } } } if (_NO_TRANSLATE_Branch.Text == AllRefs) { pushCmd = Module.PushAllCmd(destination, GetForcePushOption(), track, RecursiveSubmodules.SelectedIndex); } else { pushCmd = Module.PushCmd(destination, _NO_TRANSLATE_Branch.Text, RemoteBranch.Text, GetForcePushOption(), track, RecursiveSubmodules.SelectedIndex); } } else if (TabControlTagBranch.SelectedTab == TagTab) { string tag = TagComboBox.Text; bool pushAllTags = false; if (tag == AllRefs) { tag = ""; pushAllTags = true; } pushCmd = GitCommandHelpers.PushTagCmd(destination, tag, pushAllTags, GetForcePushOption()); } 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(GitPushAction.DeleteRemoteBranch(row["Remote"].ToString())); } pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); //controls can be accessed only from UI thread _selectedBranch = _NO_TRANSLATE_Branch.Text; _candidateForRebasingMergeCommit = PushToRemote.Checked && (_selectedBranch != AllRefs) && TabControlTagBranch.SelectedTab == BranchTab; _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); ErrorOccurred = form.ErrorOccurred(); if (!Module.InTheMiddleOfAction() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPush); if (_createPullRequestCB.Checked) UICommands.StartCreatePullRequest(owner); return true; } } return false; }
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; } }
private bool PushChanges(IWin32Window owner) { ErrorOccurred = false; if (PushToUrl.Checked && string.IsNullOrEmpty(PushDestination.Text)) { MessageBox.Show(owner, _selectDestinationDirectory.Text); return(false); } if (PushToRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text)) { MessageBox.Show(owner, _selectRemote.Text); return(false); } if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text)) { 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 && PushToRemote.Checked && !Module.IsBareRepository()) { //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 (_NO_TRANSLATE_Branch.Text != AllRefs && RemoteBranch.Text != GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text, _NO_TRANSLATE_Branch.Text) && !IsBranchKnownToRemote(_NO_TRANSLATE_Remotes.Text, RemoteBranch.Text)) { //Ask if this is really what the user wants if (!AppSettings.DontConfirmPushNewBranch && MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) == DialogResult.No) { return(false); } } } if (PushToUrl.Checked) { Repositories.AddMostRecentRepository(PushDestination.Text); } AppSettings.RecursiveSubmodules = RecursiveSubmodules.SelectedIndex; var remote = ""; string destination; if (PushToUrl.Checked) { destination = PushDestination.Text; } else { if (GitCommandHelpers.Plink()) { if (!File.Exists(AppSettings.Pageant)) { MessageBoxes.PAgentNotFound(owner); } 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)) { GitRef selectedLocalBranch = _NO_TRANSLATE_Branch.SelectedItem as GitRef; 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 && !AppSettings.DontConfirmAddTrackingRef) { 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.Yes; } } // Try to make source rev into a fully qualified branch name. If that // doesn't exist, then it must be something other than a branch, so // fall back to using the name just as it was passed in. string srcRev = ""; bool pushAllBranches = false; if (_NO_TRANSLATE_Branch.Text == AllRefs) { pushAllBranches = true; } else { srcRev = GitCommandHelpers.GetFullBranchName(_NO_TRANSLATE_Branch.Text); if (String.IsNullOrEmpty(Module.RevParse(srcRev))) { srcRev = _NO_TRANSLATE_Branch.Text; } } pushCmd = GitCommandHelpers.PushCmd(destination, srcRev, RemoteBranch.Text, pushAllBranches, ForcePushBranches.Checked, track, RecursiveSubmodules.SelectedIndex); } else if (TabControlTagBranch.SelectedTab == TagTab) { string tag = TagComboBox.Text; bool pushAllTags = false; if (tag == AllRefs) { tag = ""; pushAllTags = true; } pushCmd = GitCommandHelpers.PushTagCmd(destination, tag, pushAllTags, 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(GitPushAction.DeleteRemoteBranch(row["Remote"].ToString())); } } pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); //controls can be accessed only from UI thread _selectedBranch = _NO_TRANSLATE_Branch.Text; _candidateForRebasingMergeCommit = PushToRemote.Checked && (_selectedBranch != AllRefs) && TabControlTagBranch.SelectedTab == BranchTab; _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); ErrorOccurred = form.ErrorOccurred(); if (!Module.InTheMiddleOfAction() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPush); if (_createPullRequestCB.Checked) { UICommands.StartCreatePullRequest(owner); } return(true); } } return(false); }
private void OkClick(object sender, EventArgs e) { try { Cursor = Cursors.Default; _branchListLoader.Cancel(); // validate if destination path is supplied var destination = _NO_TRANSLATE_To.Text; if (string.IsNullOrWhiteSpace(destination)) { MessageBox.Show(this, _errorDestinationNotSupplied.Text, _errorCloneFailed.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); _NO_TRANSLATE_To.Focus(); return; } if (!Path.IsPathRooted(destination)) { MessageBox.Show(this, _errorDestinationNotRooted.Text, _errorCloneFailed.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); _NO_TRANSLATE_To.Focus(); return; } var dirTo = Path.Combine(destination, _NO_TRANSLATE_NewDirectory.Text); // this will fail if the path is anyhow invalid dirTo = new Uri(dirTo).LocalPath; if (!Directory.Exists(dirTo)) { Directory.CreateDirectory(dirTo); } // Shallow clone params int? depth = null; bool?isSingleBranch = null; if (!cbDownloadFullHistory.Checked) { depth = 1; // Single branch considerations: // If neither depth nor single-branch family params are specified, then it's like no-single-branch by default. // If depth is specified, then single-branch is assumed. // But with single-branch it's really nontrivial to switch to another branch in the GUI, and it's very hard in cmdline (obvious choices to fetch another branch lead to local repo corruption). // So let's reset it to no-single-branch to (a) have the same branches behavior as with full clone, and (b) make it easier for users when switching branches. isSingleBranch = false; } // Branch name param string branch = _NO_TRANSLATE_Branches.Text; if (branch == _branchDefaultRemoteHead.Text) { branch = ""; } else if (branch == _branchNone.Text) { branch = null; } string sourceRepo = _NO_TRANSLATE_From.Text; var cloneCmd = GitCommandHelpers.CloneCmd(sourceRepo, dirTo, CentralRepository.Checked, cbIntializeAllSubmodules.Checked, branch, depth, isSingleBranch, cbLfs.Checked); using (var fromProcess = new FormRemoteProcess(Module, AppSettings.GitCommand, cloneCmd)) { fromProcess.SetUrlTryingToConnect(sourceRepo); fromProcess.ShowDialog(this); if (fromProcess.ErrorOccurred() || Module.InTheMiddleOfPatch()) { return; } } ThreadHelper.JoinableTaskFactory.Run(() => { RepositoryHistoryManager.Remotes.AddAsMostRecentAsync(sourceRepo); RepositoryHistoryManager.Locals.AddAsMostRecentAsync(dirTo); return(Task.CompletedTask); }); if (!string.IsNullOrEmpty(_puttySshKey)) { var clonedGitModule = new GitModule(dirTo); clonedGitModule.SetSetting(string.Format(SettingKeyString.RemotePuttySshKey, "origin"), _puttySshKey); clonedGitModule.LocalConfigFile.Save(); } if (_openedFromProtocolHandler && AskIfNewRepositoryShouldBeOpened(dirTo)) { Hide(); var uiCommands = new GitUICommands(dirTo); uiCommands.StartBrowseDialog(); } else if (ShowInTaskbar == false && _gitModuleChanged != null && AskIfNewRepositoryShouldBeOpened(dirTo)) { _gitModuleChanged(this, new GitModuleEventArgs(new GitModule(dirTo))); } Close(); } catch (Exception ex) { MessageBox.Show(this, "Exception: " + ex.Message, _errorCloneFailed.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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; } }
private bool PushChanges(IWin32Window owner) { ErrorOccurred = false; if (PushToUrl.Checked && !PathUtil.IsUrl(PushDestination.Text)) { MessageBox.Show(owner, _selectDestinationDirectory.Text); return(false); } if (/* PushToRemote.Checked */ !CheckIfRemoteExist()) { return(false); } var selectedRemoteName = _selectedRemote.Name; if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text)) { 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 && PushToRemote.Checked && !Module.IsBareRepository()) { // 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 (_NO_TRANSLATE_Branch.Text != AllRefs && RemoteBranch.Text != _remotesManager.GetDefaultPushRemote(_selectedRemote, _NO_TRANSLATE_Branch.Text) && !IsBranchKnownToRemote(selectedRemoteName, RemoteBranch.Text)) { // Ask if this is really what the user wants if (!AppSettings.DontConfirmPushNewBranch && MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) == DialogResult.No) { return(false); } } } if (PushToUrl.Checked) { var path = PushDestination.Text; ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Remotes.AddAsMostRecentAsync(path)); } AppSettings.RecursiveSubmodules = RecursiveSubmodules.SelectedIndex; var remote = ""; string destination; if (PushToUrl.Checked) { destination = PushDestination.Text; } else { EnsurePageant(selectedRemoteName); destination = selectedRemoteName; remote = selectedRemoteName.Trim(); } string pushCmd; if (TabControlTagBranch.SelectedTab == BranchTab) { bool track = ReplaceTrackingReference.Checked; if (!track && !string.IsNullOrWhiteSpace(RemoteBranch.Text)) { GitRef selectedLocalBranch = _NO_TRANSLATE_Branch.SelectedItem as GitRef; track = selectedLocalBranch != null && string.IsNullOrEmpty(selectedLocalBranch.TrackingRemote) && !UserGitRemotes.Any(x => _NO_TRANSLATE_Branch.Text.StartsWith(x.Name, StringComparison.OrdinalIgnoreCase)); var autoSetupMerge = Module.EffectiveConfigFile.GetValue("branch.autoSetupMerge"); if (autoSetupMerge.IsNotNullOrWhitespace() && autoSetupMerge.ToLowerInvariant() == "false") { track = false; } if (track && !AppSettings.DontConfirmAddTrackingRef) { var result = MessageBox.Show(owner, string.Format(_updateTrackingReference.Text, selectedLocalBranch.Name, RemoteBranch.Text), _pushCaption.Text, MessageBoxButtons.YesNoCancel); if (result == DialogResult.Cancel) { return(false); } track = result == DialogResult.Yes; } } if (ForcePushBranches.Checked) { if (GitVersion.Current.SupportPushForceWithLease) { var choice = MessageBox.Show(owner, _useForceWithLeaseInstead.Text, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); switch (choice) { case DialogResult.Yes: ForcePushBranches.Checked = false; ckForceWithLease.Checked = true; break; case DialogResult.Cancel: return(false); } } } if (_NO_TRANSLATE_Branch.Text == AllRefs) { pushCmd = Module.PushAllCmd(destination, GetForcePushOption(), track, RecursiveSubmodules.SelectedIndex); } else { pushCmd = Module.PushCmd(destination, _NO_TRANSLATE_Branch.Text, RemoteBranch.Text, GetForcePushOption(), track, RecursiveSubmodules.SelectedIndex); } } else if (TabControlTagBranch.SelectedTab == TagTab) { string tag = TagComboBox.Text; bool pushAllTags = false; if (tag == AllRefs) { tag = ""; pushAllTags = true; } pushCmd = GitCommandHelpers.PushTagCmd(destination, tag, pushAllTags, GetForcePushOption()); } else { // Push Multiple Branches Tab selected var pushActions = new List <GitPushAction>(); foreach (DataRow row in _branchTable.Rows) { var push = Convert.ToBoolean(row[PushColumnName]); var force = Convert.ToBoolean(row[ForceColumnName]); var delete = Convert.ToBoolean(row[DeleteColumnName]); if (push || force) { pushActions.Add(new GitPushAction(row[LocalColumnName].ToString(), row[RemoteColumnName].ToString(), force)); } else if (delete) { pushActions.Add(GitPushAction.DeleteRemoteBranch(row[RemoteColumnName].ToString())); } } pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); // controls can be accessed only from UI thread _selectedBranch = _NO_TRANSLATE_Branch.Text; _candidateForRebasingMergeCommit = PushToRemote.Checked && (_selectedBranch != AllRefs) && TabControlTagBranch.SelectedTab == BranchTab; _selectedRemoteBranchName = RemoteBranch.Text; using (var form = new FormRemoteProcess(Module, pushCmd) { Remote = remote, Text = string.Format(_pushToCaption.Text, destination), HandleOnExitCallback = HandlePushOnExit }) { form.ShowDialog(owner); ErrorOccurred = form.ErrorOccurred(); if (!Module.InTheMiddleOfAction() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPush); if (_createPullRequestCB.Checked) { UICommands.StartCreatePullRequest(owner); } return(true); } } return(false); }
private void OkClick(object sender, EventArgs e) { try { Cursor = Cursors.Default; _branchListLoader.Cancel(); var dirTo = Path.Combine(_NO_TRANSLATE_To.Text, _NO_TRANSLATE_NewDirectory.Text); Repositories.AddMostRecentRepository(_NO_TRANSLATE_From.Text); if (!Directory.Exists(dirTo)) { Directory.CreateDirectory(dirTo); } // Shallow clone params int? depth = null; bool?isSingleBranch = null; if (!cbDownloadFullHistory.Checked) { depth = 1; // Single branch considerations: // If neither depth nor single-branch family params are specified, then it's like no-single-branch by default. // If depth is specified, then single-branch is assumed. // But with single-branch it's really nontrivial to switch to another branch in the GUI, and it's very hard in cmdline (obvious choices to fetch another branch lead to local repo corruption). // So let's reset it to no-single-branch to (a) have the same branches behavior as with full clone, and (b) make it easier for users when switching branches. isSingleBranch = false; } // Branch name param string branch = _NO_TRANSLATE_Branches.Text; if (branch == _branchDefaultRemoteHead.Text) { branch = ""; } else if (branch == _branchNone.Text) { branch = null; } var cloneCmd = GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo, CentralRepository.Checked, cbIntializeAllSubmodules.Checked, branch, depth, isSingleBranch); using (var fromProcess = new FormRemoteProcess(Module, AppSettings.GitCommand, cloneCmd)) { fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text); fromProcess.ShowDialog(this); if (fromProcess.ErrorOccurred() || Module.InTheMiddleOfPatch()) { return; } } Repositories.AddMostRecentRepository(dirTo); if (openedFromProtocolHandler && AskIfNewRepositoryShouldBeOpened(dirTo)) { Hide(); GitUICommands uiCommands = new GitUICommands(dirTo); uiCommands.StartBrowseDialog(); } else if (ShowInTaskbar == false && GitModuleChanged != null && AskIfNewRepositoryShouldBeOpened(dirTo)) { GitModuleChanged(this, new GitModuleEventArgs(new GitModule(dirTo))); } Close(); } catch (Exception ex) { MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }