PullConfig(RemoteInfo remote, string line, IEnumerable <string> proceedingLines, bool isRebase) { Remote = remote; line = line.Trim(); int gapStart = line.IndexOf(" "); LocalBranch = line.Substring(0, gapStart); if (isRebase) {// {local} rebases onto remote {remoteBranch} RemoteBranches = new string[] { GetRemoteBranch(line, RebasesOntoRemote) }; Config = MergeAction.Rebase; } else { // "localBranch merges with remote remoteBranch" // and with remote remoteBranch // and with remote remoteBranch // ... const string mergeMarker = "with remote"; var remotes = new List <string> { GetRemoteBranch(line, mergeMarker) }; remotes.AddRange(from branch in proceedingLines select GetRemoteBranch(branch, mergeMarker)); RemoteBranches = remotes; Config = MergeAction.Merge; } }
// Remote branches: // LibGit2Sharp tracked // LibGit2Sharp new (next fetch will store in remotes/{remote})" // LibGit2Sharp stale (use 'git remote prune' to remove)" internal RemoteTrackingBranch(string line, RemoteInfo remote) { int gapStart = line.IndexOf(" "); Name = line.Substring(0, gapStart);// branch name ends right before first space string status = line.Substring(gapStart).Trim().ToLower(); foreach (var state in ValidStates) { if (status.StartsWith(state.Key)) { Status = state.Value; if (Status == State.Stale) { // refs/remotes/berger/left-panel/remotes stale (use 'git remote prune' to remove) // release/2.32 tracked string staleName = string.Format("{0}{1}/", GitRef.RefsRemotesPrefix, remote.Name); if (Name.StartsWith(staleName)) {// stale remote branch starts with "refs/remotes/{0}/" Name = Name.Substring(staleName.Length); } } break; } } InternalPullConfigs = new List <PullConfig>(); Remote = remote; FullPath = string.Format( "{0}{1}{2}", remote.Name, GitModule.RefSep, Name); }
public RemoteBranch(RemoteInfo remote, string remoteBranchLine, string headBranchName) { Remote = remote; // $ git ls-remote --heads {remote} // {SHA-1} refs/heads/{branch} Sha1 = remoteBranchLine.Substring(0, Sha1Length); var temp = remoteBranchLine.Substring(Sha1Length).Trim();// remove SHA-1, then trim FullRefName = temp; Name = FullRefName.Substring(GitRef.RefsHeadsPrefix.Length);// remove "refs/heads/" IsHead = Equals(Name, headBranchName); if (IsHead) { remote.HeadBranch = this; } }
/// <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); }
/// <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); }
/// <summary>Creates a new <see cref="PullConfig"/> which rebases onto a remote.</summary> internal PullConfig(RemoteInfo remote, string line) : this(remote, line, null, true) { }
/// <summary>Reset the current remote-tracking branches and only track the specified branches.</summary> public static GitRemote TrackOnly(RemoteInfo remote, params RemoteInfo.RemoteTrackingBranch[] trackingBranches) { return(new GitRemote(remote, SetBranches.Reset, trackingBranches)); }
/// <summary>Un-track the specified remote-tracking branches.</summary> public static GitRemote UnTrack(RemoteInfo remote, params RemoteInfo.RemoteTrackingBranch[] trackingBranches) { return(new GitRemote(remote, SetBranches.UnTrack, trackingBranches)); }
/// <summary>Indicates whether a remote branch is lacking commits that are in a local branch/revision.</summary> /// <param name="aheadRevision">Local branch/revision.</param> /// <param name="remoteTrackingBranch">Remote branch to check if it's behind.</param> public bool IsRemoteBranchBehind(RemoteInfo.RemoteTrackingBranch remoteTrackingBranch, string aheadRevision) { return IsBranchBehind(remoteTrackingBranch.FullPath, aheadRevision); }
/// <summary>Gets the number of commits which appear in a remote branch that are NOT in another branch/revision. /// <remarks>Indicates how many commits the local branch is behind the remote branch; possibly for pulling.</remarks></summary> /// <param name="behindRevision">Revision/branch to check how many commits it's behind.</param> /// <param name="remoteTrackingBranch">Remote branch.</param> public int GetCommitDiffCount(string behindRevision, RemoteInfo.RemoteTrackingBranch remoteTrackingBranch) { return GetCommitDiffCount(behindRevision, remoteTrackingBranch.FullPath); }
/// <summary>Un-track the specified remote-tracking branches.</summary> public static GitRemote UnTrack(RemoteInfo remote, params RemoteInfo.RemoteTrackingBranch[] trackingBranches) { return new GitRemote(remote, SetBranches.UnTrack, trackingBranches); }
/// <summary>Reset the current remote-tracking branches and only track the specified branches.</summary> public static GitRemote TrackOnly(RemoteInfo remote, params RemoteInfo.RemoteTrackingBranch[] trackingBranches) { return new GitRemote(remote, SetBranches.Reset, trackingBranches); }
/// <summary>Creates a new <see cref="PullConfig"/> which merges onto remote(s).</summary> internal PullConfig(RemoteInfo remote, string firstLine, IEnumerable <string> proceedingLines) : this(remote, firstLine, proceedingLines, false) { }
/// <summary>Creates a new <see cref="PullConfig"/> which merges onto remote(s).</summary> internal PullConfig(RemoteInfo remote, string firstLine, IEnumerable<string> proceedingLines) : this(remote, firstLine, proceedingLines, false) { }
PullConfig(RemoteInfo remote, string line, IEnumerable<string> proceedingLines, bool isRebase) { Remote = remote; line = line.Trim(); int gapStart = line.IndexOf(" "); LocalBranch = line.Substring(0, gapStart); if (isRebase) {// {local} rebases onto remote {remoteBranch} RemoteBranches = new string[] { GetRemoteBranch(line, RebasesOntoRemote) }; Config = MergeAction.Rebase; } else { // "localBranch merges with remote remoteBranch" // and with remote remoteBranch // and with remote remoteBranch // ... const string mergeMarker = "with remote"; var remotes = new List<string> { GetRemoteBranch(line, mergeMarker) }; remotes.AddRange(from branch in proceedingLines select GetRemoteBranch(branch, mergeMarker)); RemoteBranches = remotes; Config = MergeAction.Merge; } }
/// <summary>Gets the number of commits which appear in a local branch/revision that are NOT in a remote branch. /// <remarks>Indicates how many commits the local branch is ahead of the remote branch.</remarks></summary> /// <param name="remoteTrackingBranch">Remote branch to check the number of commits it's behind.</param> /// <param name="aheadRevision">Local revision/branch.</param> public int GetCommitDiffCount(RemoteInfo.RemoteTrackingBranch remoteTrackingBranch, string aheadRevision) { return GetCommitDiffCount(remoteTrackingBranch.FullPath, aheadRevision); }
.ToDictionary(state => state.ToString().ToLower()); // e.g. "tracked" -> Tracked #endregion Fields #region Constructors // Remote branches: // LibGit2Sharp tracked // LibGit2Sharp new (next fetch will store in remotes/{remote})" // LibGit2Sharp stale (use 'git remote prune' to remove)" internal RemoteTrackingBranch(string line, RemoteInfo remote) { int gapStart = line.IndexOf(" "); Name = line.Substring(0, gapStart);// branch name ends right before first space string status = line.Substring(gapStart).Trim().ToLower(); foreach (var state in ValidStates) { if (status.StartsWith(state.Key)) { Status = state.Value; if (Status == State.Stale) { // refs/remotes/berger/left-panel/remotes stale (use 'git remote prune' to remove) // release/2.32 tracked string staleName = string.Format("{0}{1}/", GitRef.RefsRemotesPrefix, remote.Name); if (Name.StartsWith(staleName)) {// stale remote branch starts with "refs/remotes/{0}/" Name = Name.Substring(staleName.Length); } } break; } } InternalPullConfigs = new List<PullConfig>(); Remote = remote; FullPath = string.Format( "{0}{1}{2}", remote.Name, GitModule.RefSep, Name); }
/// <summary>Indicates whether a local branch/revision is behind a remote branch; possibly for pulling.</summary> /// <param name="behindRevision">Local branch/revision to check if it's behind.</param> /// <param name="remoteTrackingBranch">Remote branch.</param> public bool IsBranchBehind(string behindRevision, RemoteInfo.RemoteTrackingBranch remoteTrackingBranch) { return IsBranchBehind(behindRevision, remoteTrackingBranch.FullPath); }