Example #1
0
        /// <summary>Creates a 'git remote' command to track/un-track specified branches.</summary>
        /// <param name="remote">Remote whose branches to set.</param>
        /// <param name="option">Indicates the add/remove/reset action to perform.</param>
        /// <param name="trackingBranches">Branches to track/un-track.</param>
        public GitRemote(RemoteInfo remote, SetBranches option, params RemoteInfo.RemoteTrackingBranch[] trackingBranches)
        {                     // 'git remote set-branches [--add] <name> <branch> <branch> ...'
            string add = (option == SetBranches.Append)
                    ? "--add" // add to tracked branches
                    : "";     // reset then track/untrack branches

            IEnumerable <RemoteInfo.RemoteTrackingBranch> cmdBranches;

            if (option == SetBranches.UnTrack)
            {// un-track
                var keepers = new HashSet <RemoteInfo.RemoteTrackingBranch>(remote.RemoteTrackingBranches);
                keepers.ExceptWith(trackingBranches);
                cmdBranches = keepers;
            }
            else
            {
                cmdBranches = trackingBranches.AsEnumerable();
            }

            string branchesString = string.Join(" ", cmdBranches);

            // 'git remote set-branches [--add] <name> <branch> <branch> ...'
            cmd = string.Format("remote set-branches {0} {1} {2}", remote.Name, add, branchesString);
        }
Example #2
0
        /// <summary>Creates a 'git remote' command to track/un-track specified branches.</summary>
        /// <param name="remote">Remote whose branches to set.</param>
        /// <param name="option">Indicates the add/remove/reset action to perform.</param>
        /// <param name="trackingBranches">Branches to track/un-track.</param>
        public GitRemote(RemoteInfo remote, SetBranches option, params RemoteInfo.RemoteTrackingBranch[] trackingBranches)
        {
            // 'git remote set-branches [--add] <name> <branch> <branch> ...'
            string add = (option == SetBranches.Append)
                    ? "--add" // add to tracked branches
                    : "";// reset then track/untrack branches

            IEnumerable<RemoteInfo.RemoteTrackingBranch> cmdBranches;
            if (option == SetBranches.UnTrack)
            {// un-track
                var keepers = new HashSet<RemoteInfo.RemoteTrackingBranch>(remote.RemoteTrackingBranches);
                keepers.ExceptWith(trackingBranches);
                cmdBranches = keepers;

            }
            else
            {
                cmdBranches = trackingBranches.AsEnumerable();
            }

            string branchesString = string.Join(" ", cmdBranches);
            // 'git remote set-branches [--add] <name> <branch> <branch> ...'
            cmd = string.Format("remote set-branches {0} {1} {2}", remote.Name, add, branchesString);
        }