public void GetFullBranchNameTest() { Assert.AreEqual(null, GitCommandHelpers.GetFullBranchName(null)); Assert.AreEqual("", GitCommandHelpers.GetFullBranchName("")); Assert.AreEqual("", GitCommandHelpers.GetFullBranchName(" ")); Assert.AreEqual("4e0f0fe3f6add43557913c354de02560b8faec32", GitCommandHelpers.GetFullBranchName("4e0f0fe3f6add43557913c354de02560b8faec32")); Assert.AreEqual("refs/heads/master", GitCommandHelpers.GetFullBranchName("master")); Assert.AreEqual("refs/heads/master", GitCommandHelpers.GetFullBranchName(" master ")); Assert.AreEqual("refs/heads/master", GitCommandHelpers.GetFullBranchName("refs/heads/master")); Assert.AreEqual("refs/heads/release/2.48", GitCommandHelpers.GetFullBranchName("refs/heads/release/2.48")); Assert.AreEqual("refs/tags/my-tag", GitCommandHelpers.GetFullBranchName("refs/tags/my-tag")); }
private static string PushCmd(string remote, string toBranch) { remote = remote.ToPosixPath(); toBranch = GitCommandHelpers.GetFullBranchName(toBranch); const string fromBranch = "HEAD"; toBranch = toBranch?.Replace(" ", ""); var sprogressOption = ""; if (GitCommandHelpers.VersionInUse.PushCanAskForProgress) { sprogressOption = "--progress "; } return(string.Format("push {0}\"{1}\" {2}:{3}", sprogressOption, remote.Trim(), fromBranch, toBranch)); }
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.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPush); if (_createPullRequestCB.Checked) { UICommands.StartCreatePullRequest(owner); } return(true); } } return(false); }
/// <summary> /// Push a delete of a remote branch. /// </summary> /// <param name="deleteBranch"></param> public GitPushAction(string deleteBranch) { _remoteBranch = GitCommandHelpers.GetFullBranchName(deleteBranch); _delete = true; }
/// <summary> /// Push a local branch to a remote one, optionally forcing a non-fast-forward commit. /// </summary> /// <param name="fromBranch"></param> /// <param name="toBranch"></param> /// <param name="force"></param> public GitPushAction(string fromBranch, string toBranch, bool force) { _localBranch = GitCommandHelpers.GetFullBranchName(fromBranch); _remoteBranch = GitCommandHelpers.GetFullBranchName(toBranch); _force = force; }