GitCommands.GitModule.PushCmd C# (CSharp) Method

PushCmd() public method

Creates a 'git push' command using the specified parameters.
public PushCmd ( string remote, string fromBranch, string toBranch, ForcePushOptions force, bool track, int recursiveSubmodules ) : string
remote string Remote repository that is the destination of the push operation.
fromBranch string Name of the branch to push.
toBranch string Name of the ref on the remote side to update with the push.
force ForcePushOptions If a remote ref is not an ancestor of the local ref, overwrite it. /// This can cause the remote repository to lose commits; use it with care.
track bool For every branch that is up to date or successfully pushed, add upstream (tracking) reference.
recursiveSubmodules int 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.
return string
        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);
        }
GitModule