/// <summary> /// Get the upstream remote and merge branch name from a Canonical branch name. /// This will return the remote name (or ".") if a local branch for the remote name. /// </summary> /// <param name="canonicalName">The canonical branch name to parse.</param> /// <param name="remoteName">The name of the corresponding remote the branch belongs to /// or "." if it is a local branch.</param> /// <param name="mergeBranchName">The name of the upstream branch to merge into.</param> private void GetUpstreamInformation(string canonicalName, out string remoteName, out string mergeBranchName) { remoteName = null; mergeBranchName = null; const string localPrefix = "refs/heads/"; const string remotePrefix = "refs/remotes/"; if (canonicalName.StartsWith(localPrefix, StringComparison.Ordinal)) { remoteName = "."; mergeBranchName = canonicalName; } else if (canonicalName.StartsWith(remotePrefix, StringComparison.Ordinal)) { remoteName = Proxy.git_branch_remote_name(repo.Handle, canonicalName); Remote remote = repo.Network.Remotes.RemoteForName(remoteName); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repo.Handle, remote.Name, true)) { GitFetchSpecHandle fetchSpecPtr = Proxy.git_remote_fetchspec(remoteHandle); mergeBranchName = Proxy.git_fetchspec_rtransform(fetchSpecPtr, canonicalName); } } else { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "'{0}' does not look like a valid canonical branch name.", canonicalName)); } }
internal static extern int git_refspec_rtransform( byte[] target, UIntPtr outlen, GitFetchSpecHandle refSpec, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name);