Пример #1
0
        public static string PushTagCmd(string path, string tag, bool all,
                                        ForcePushOptions force = ForcePushOptions.DoNotForce)
        {
            path = path.ToPosixPath();

            tag = tag.Replace(" ", "");

            var sforce = GetForcePushArgument(force);

            var sprogressOption = "";

            if (VersionInUse.PushCanAskForProgress)
            {
                sprogressOption = "--progress ";
            }

            var options = String.Concat(sforce, sprogressOption);

            if (all)
            {
                return("push " + options + "\"" + path.Trim() + "\" --tags");
            }
            if (!string.IsNullOrEmpty(tag))
            {
                return("push " + options + "\"" + path.Trim() + "\" tag " + tag);
            }

            return("");
        }
        /// <summary>
        /// Adds the git argument syntax for members of the <see cref="ForcePushOptions"/> enum.
        /// </summary>
        /// <param name="builder">The <see cref="ArgumentBuilder"/> to add arguments to.</param>
        /// <param name="option">The enum member to add to the builder.</param>
        public static void Add(this ArgumentBuilder builder, ForcePushOptions option)
        {
            builder.Add(GetArgument());

            string?GetArgument()
            {
                return(option switch
                {
                    ForcePushOptions.Force => "-f",
                    ForcePushOptions.ForceWithLease => "--force-with-lease",
                    ForcePushOptions.DoNotForce => null,
                    _ => throw new InvalidEnumArgumentException(nameof(option), (int)option, typeof(ForcePushOptions))
                });
Пример #3
0
        public static string GetForcePushArgument(ForcePushOptions force)
        {
            var sforce = "";

            if (force == ForcePushOptions.Force)
            {
                sforce = "-f ";
            }
            else if (force == ForcePushOptions.ForceWithLease)
            {
                sforce = "--force-with-lease ";
            }
            return(sforce);
        }
Пример #4
0
        public static ArgumentString PushTagCmd(string path, string tag, bool all, ForcePushOptions force = ForcePushOptions.DoNotForce)
        {
            if (!all && string.IsNullOrWhiteSpace(tag))
            {
                // TODO this is probably an error
                return("");
            }

            return(new GitArgumentBuilder("push")
            {
                force,
                { GitVersion.Current.PushCanAskForProgress, "--progress" },
                path.ToPosixPath().Trim().Quote(),
                { all, "--tags" },
                { !all, $"tag {tag.Replace(" ", "")}" }
            });
        }
Пример #5
0
        public static string PushTagCmd(string path, string tag, bool all, ForcePushOptions force = ForcePushOptions.DoNotForce)
        {
            if (!all && string.IsNullOrWhiteSpace(tag))
            {
                // TODO this is probably an error
                return("");
            }

            var args = new ArgumentBuilder
            {
                "push",
                force,
                { VersionInUse.PushCanAskForProgress, "--progress" },
                path.ToPosixPath().Trim().Quote(),
                { all, "--tags" },
                { !all, $"tag {tag.Replace(" ", "")}" }
            };

            return(args.ToString());
        }
        /// <summary>
        /// Adds the git argument syntax for members of the <see cref="ForcePushOptions"/> enum.
        /// </summary>
        /// <param name="builder">The <see cref="ArgumentBuilder"/> to add arguments to.</param>
        /// <param name="option">The enum member to add to the builder.</param>
        public static void Add(this ArgumentBuilder builder, ForcePushOptions option)
        {
            builder.Add(GetArgument());

            string GetArgument()
            {
                switch (option)
                {
                case ForcePushOptions.Force:
                    return("-f");

                case ForcePushOptions.ForceWithLease:
                    return("--force-with-lease");

                case ForcePushOptions.DoNotForce:
                    return(null);

                default:
                    throw new InvalidEnumArgumentException(nameof(option), (int)option, typeof(ForcePushOptions));
                }
            }
        }
Пример #7
0
        /// <summary>Creates a 'git push' command using the specified parameters.</summary>
        /// <param name="remote">Remote repository that is the destination of the push operation.</param>
        /// <param name="fromBranch">Name of the branch to push.</param>
        /// <param name="toBranch">Name of the ref on the remote side to update with the push.</param>
        /// <param name="force">If a remote ref is not an ancestor of the local ref, overwrite it.
        /// <remarks>This can cause the remote repository to lose commits; use it with care.</remarks></param>
        /// <param name="track">For every branch that is up to date or successfully pushed, add upstream (tracking) reference.</param>
        /// <param name="recursiveSubmodules">If '1', check whether all submodule commits used by the revisions to be pushed are available on a remote tracking branch; otherwise, the push will be aborted.</param>
        /// <returns>'git push' command with the specified parameters.</returns>
        public string PushCmd(string remote, string fromBranch, string toBranch,
            ForcePushOptions force, bool track, int recursiveSubmodules)
        {
            remote = remote.ToPosixPath();

            // This method is for pushing to remote branches, so fully qualify the
            // remote branch name with refs/heads/.
            fromBranch = FormatBranchName(fromBranch);
            toBranch = GitCommandHelpers.GetFullBranchName(toBranch);

            if (String.IsNullOrEmpty(fromBranch) && !String.IsNullOrEmpty(toBranch))
                fromBranch = "HEAD";

            if (toBranch != null) toBranch = toBranch.Replace(" ", "");

            var sforce = GitCommandHelpers.GetForcePushArgument(force);

            var strack = "";
            if (track)
                strack = "-u ";

            var srecursiveSubmodules = "";
            if (recursiveSubmodules == 1)
                srecursiveSubmodules = "--recurse-submodules=check ";
            if (recursiveSubmodules == 2)
                srecursiveSubmodules = "--recurse-submodules=on-demand ";

            var sprogressOption = "";
            if (GitCommandHelpers.VersionInUse.PushCanAskForProgress)
                sprogressOption = "--progress ";

            var options = String.Concat(sforce, strack, srecursiveSubmodules, sprogressOption);
            if (!String.IsNullOrEmpty(toBranch) && !String.IsNullOrEmpty(fromBranch))
                return String.Format("push {0}\"{1}\" {2}:{3}", options, remote.Trim(), fromBranch, toBranch);

            return String.Format("push {0}\"{1}\" {2}", options, remote.Trim(), fromBranch);
        }
Пример #8
0
        /// <summary>Creates a 'git push' command using the specified parameters.</summary>
        /// <param name="remote">Remote repository that is the destination of the push operation.</param>
        /// <param name="force">If a remote ref is not an ancestor of the local ref, overwrite it.
        /// <remarks>This can cause the remote repository to lose commits; use it with care.</remarks></param>
        /// <param name="track">For every branch that is up to date or successfully pushed, add upstream (tracking) reference.</param>
        /// <param name="recursiveSubmodules">If '1', check whether all submodule commits used by the revisions to be pushed are available on a remote tracking branch; otherwise, the push will be aborted.</param>
        /// <returns>'git push' command with the specified parameters.</returns>
        public string PushAllCmd(string remote, ForcePushOptions force, bool track, int recursiveSubmodules)
        {
            remote = remote.ToPosixPath();

            var sforce = GitCommandHelpers.GetForcePushArgument(force);

            var strack = "";
            if (track)
                strack = "-u ";

            var srecursiveSubmodules = "";
            if (recursiveSubmodules == 1)
                srecursiveSubmodules = "--recurse-submodules=check ";
            if (recursiveSubmodules == 2)
                srecursiveSubmodules = "--recurse-submodules=on-demand ";

            var sprogressOption = "";
            if (GitCommandHelpers.VersionInUse.PushCanAskForProgress)
                sprogressOption = "--progress ";

            var options = String.Concat(sforce, strack, srecursiveSubmodules, sprogressOption);
            return String.Format("push {0}--all \"{1}\"", options, remote.Trim());
        }
Пример #9
0
        [TestCase(true, true, true, ForcePushOptions.Force)]            // ForcePushBranches and ForcePushTags take precedence over ckForceWithLease
        public void Should_choose_correct_force_push_option_for_checkbox_state(
            bool forcePushBranchWithLeaseChecked, bool forcePushBranchChecked, bool forcePushTagChecked, ForcePushOptions forcePushOption)
        {
            RunFormTest(
                form =>
            {
                var accessor = form.GetTestAccessor();

                accessor.ForcePushTags.Checked     = forcePushTagChecked;
                accessor.ckForceWithLease.Checked  = forcePushBranchWithLeaseChecked;
                accessor.ForcePushBranches.Checked = forcePushBranchChecked;

                accessor.GetForcePushOption().Should().Be(forcePushOption);
            });
        }
Пример #10
0
        public static string PushTagCmd(string path, string tag, bool all,
            ForcePushOptions force = ForcePushOptions.DoNotForce)
        {
            path = path.ToPosixPath();

            tag = tag.Replace(" ", "");

            var sforce = GetForcePushArgument(force);

            var sprogressOption = "";
            if (VersionInUse.PushCanAskForProgress)
                sprogressOption = "--progress ";

            var options = String.Concat(sforce, sprogressOption);

            if (all)
                return "push " + options + "\"" + path.Trim() + "\" --tags";
            if (!string.IsNullOrEmpty(tag))
                return "push " + options + "\"" + path.Trim() + "\" tag " + tag;

            return "";
        }
Пример #11
0
 public static string GetForcePushArgument(ForcePushOptions force)
 {
     var sforce = "";
     if (force == ForcePushOptions.Force)
         sforce = "-f ";
     else if (force == ForcePushOptions.ForceWithLease)
         sforce = "--force-with-lease ";
     return sforce;
 }