Example #1
0
        /// <returns>
        /// the full remote-tracking branch name or <code>null</code> if it
        /// could not be determined
        /// </returns>
        public virtual string GetRemoteTrackingBranch()
        {
            string remote   = GetRemote();
            string mergeRef = GetMergeBranch();

            if (remote == null || mergeRef == null)
            {
                return(null);
            }
            RemoteConfig remoteConfig;

            try
            {
                remoteConfig = new RemoteConfig(config, remote);
            }
            catch (URISyntaxException)
            {
                return(null);
            }
            foreach (RefSpec refSpec in remoteConfig.FetchRefSpecs)
            {
                if (refSpec.MatchSource(mergeRef))
                {
                    RefSpec expanded = refSpec.ExpandFromSource(mergeRef);
                    return(expanded.GetDestination());
                }
            }
            return(null);
        }
Example #2
0
        /// <summary>Finds the tracked remote tracking branch</summary>
        /// <param name="remote">Remote name</param>
        /// <param name="mergeRef">
        /// merge Ref of the local branch tracking the remote tracking
        /// branch
        /// </param>
        /// <returns>full remote tracking branch name or null</returns>
        private string FindRemoteTrackingBranch(string remote, string mergeRef)
        {
            RemoteConfig remoteConfig;

            try
            {
                remoteConfig = new RemoteConfig(config, remote);
            }
            catch (URISyntaxException)
            {
                return(null);
            }
            foreach (RefSpec refSpec in remoteConfig.FetchRefSpecs)
            {
                if (refSpec.MatchSource(mergeRef))
                {
                    RefSpec expanded = refSpec.ExpandFromSource(mergeRef);
                    return(expanded.GetDestination());
                }
            }
            return(null);
        }