public void GetRemoteBranch()
        {
            Assert.AreEqual("master", GitRefName.GetRemoteBranch("refs/remotes/foo/master"));
            Assert.AreEqual("tmp/master", GitRefName.GetRemoteBranch("refs/remotes/foo/tmp/master"));

            Assert.AreEqual("", GitRefName.GetRemoteBranch("refs/remotes/foo"));
            Assert.AreEqual("", GitRefName.GetRemoteBranch("short"));
        }
 private static ArgumentString PushCmd(string remote, string toBranch)
 {
     return(new GitArgumentBuilder("push")
     {
         { GitVersion.Current.PushCanAskForProgress, "--progress" },
         remote.ToPosixPath().Trim().Quote(),
         $"HEAD:{GitRefName.GetFullBranchName(toBranch)?.Replace(" ", "")}"
     });
 }
        public void GetRemoteName()
        {
            Assert.AreEqual("foo", GitRefName.GetRemoteName("refs/remotes/foo/master"));
            Assert.AreEqual("", GitRefName.GetRemoteName("refs/tags/1.0.0"));

            var remotes = new[] { "foo", "bar" };

            Assert.AreEqual("foo", GitRefName.GetRemoteName("foo/master", remotes));
            Assert.AreEqual("", GitRefName.GetRemoteName("food/master", remotes));
            Assert.AreEqual("", GitRefName.GetRemoteName("refs/tags/1.0.0", remotes));
        }
 public void GetFullBranchNameTest()
 {
     Assert.AreEqual(null, GitRefName.GetFullBranchName(null));
     Assert.AreEqual("", GitRefName.GetFullBranchName(""));
     Assert.AreEqual("", GitRefName.GetFullBranchName("    "));
     Assert.AreEqual("4e0f0fe3f6add43557913c354de02560b8faec32", GitRefName.GetFullBranchName("4e0f0fe3f6add43557913c354de02560b8faec32"));
     Assert.AreEqual("refs/heads/master", GitRefName.GetFullBranchName("master"));
     Assert.AreEqual("refs/heads/master", GitRefName.GetFullBranchName(" master "));
     Assert.AreEqual("refs/heads/master", GitRefName.GetFullBranchName("refs/heads/master"));
     Assert.AreEqual("refs/heads/release/2.48", GitRefName.GetFullBranchName("refs/heads/release/2.48"));
     Assert.AreEqual("refs/tags/my-tag", GitRefName.GetFullBranchName("refs/tags/my-tag"));
 }
示例#5
0
        private static string PushCmd(string remote, string toBranch)
        {
            var args = new ArgumentBuilder
            {
                "push",
                { GitCommandHelpers.VersionInUse.PushCanAskForProgress, "--progress" },
                remote.ToPosixPath().Trim().Quote(),
                $"HEAD:{GitRefName.GetFullBranchName(toBranch)?.Replace(" ", "")}"
            };

            return(args.ToString());
        }
示例#6
0
        private void Branches_SelectedIndexChanged(object sender, EventArgs e)
        {
            lbChanges.Text = "";

            var branch = Branches.Text;

            if (branch.IsNullOrWhiteSpace() || !Remotebranch.Checked)
            {
                _remoteName         = string.Empty;
                _localBranchName    = string.Empty;
                _newLocalBranchName = string.Empty;
            }
            else
            {
                _remoteName      = GitRefName.GetRemoteName(branch, Module.GetRemotes(false));
                _localBranchName = Module.GetLocalTrackingBranchName(_remoteName, branch);
                var remoteBranchName = _remoteName.Length > 0 ? branch.Substring(_remoteName.Length + 1) : branch;
                _newLocalBranchName = string.Concat(_remoteName, "_", remoteBranchName);
                int i = 2;
                while (LocalBranchExists(_newLocalBranchName))
                {
                    _newLocalBranchName = string.Concat(_remoteName, "_", _localBranchName, "_", i.ToString());
                    i++;
                }
            }

            bool existsLocalBranch = LocalBranchExists(_localBranchName);

            rbResetBranch.Text       = existsLocalBranch ? _rbResetBranchDefaultText : _createBranch.Text;
            branchName.Text          = "'" + _localBranchName + "'";
            txtCustomBranchName.Text = _newLocalBranchName;

            if (branch.IsNullOrWhiteSpace())
            {
                lbChanges.Text = "";
            }
            else
            {
                ThreadHelper.JoinableTaskFactory.RunAsync(
                    async() =>
                {
                    await TaskScheduler.Default;

                    var text = Module.GetCommitCountString(Module.GetCurrentCheckout(), branch);

                    await this.SwitchToMainThreadAsync();

                    lbChanges.Text = text;
                });
            }
        }
        public void GetFullBranchName()
        {
            Assert.AreEqual("refs/heads/foo", GitRefName.GetFullBranchName("foo"));

            Assert.AreEqual("refs/foo", GitRefName.GetFullBranchName("refs/foo"));

            Assert.AreEqual(
                "4e0f0fe3f6add43557913c354de02560b8faec32",
                GitRefName.GetFullBranchName("4e0f0fe3f6add43557913c354de02560b8faec32"));

            Assert.AreEqual("", GitRefName.GetFullBranchName(""));
            Assert.AreEqual("", GitRefName.GetFullBranchName("    "));

            Assert.IsNull(GitRefName.GetFullBranchName(null));
        }
        public void IsRemoteHead()
        {
            Assert.IsTrue(GitRefName.IsRemoteHead("refs/remotes/origin/HEAD"));
            Assert.IsTrue(GitRefName.IsRemoteHead("refs/remotes/upstream/HEAD"));

            Assert.IsFalse(GitRefName.IsRemoteHead("refs/remotes/ori/gin/HEAD"));
            Assert.IsFalse(GitRefName.IsRemoteHead("refs/remotes//HEAD"));
            Assert.IsFalse(GitRefName.IsRemoteHead("refs/remotes/HEAD"));
            Assert.IsFalse(GitRefName.IsRemoteHead("refs/origin/HEAD"));
            Assert.IsFalse(GitRefName.IsRemoteHead("ref/remotes/origin/HEAD"));
            Assert.IsFalse(GitRefName.IsRemoteHead("remotes/origin/HEAD"));
            Assert.IsFalse(GitRefName.IsRemoteHead("wat/refs/remotes/origin/HEAD"));
            Assert.IsFalse(GitRefName.IsRemoteHead("refs/remotes/origin/HEADZ"));
            Assert.IsFalse(GitRefName.IsRemoteHead("refs/remotes/origin/HEAD/wat"));
            Assert.IsFalse(GitRefName.IsRemoteHead("refs/remotes/origin/HEAD  "));
            Assert.IsFalse(GitRefName.IsRemoteHead("  refs/remotes/origin/HEAD"));
        }
示例#9
0
        private static string PushCmd(string remote, string toBranch)
        {
            remote = remote.ToPosixPath();

            toBranch = GitRefName.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));
        }