예제 #1
0
		public virtual void GetRemoteTrackingBranchShouldReturnNullWithoutFetchSpec()
		{
			Config c = Parse(string.Empty + "[remote \"origin\"]\n" + "  fetch = +refs/heads/onlyone:refs/remotes/origin/onlyone\n"
				 + "[branch \"master\"]\n" + "  remote = origin\n" + "  merge = refs/heads/master\n"
				);
			//
			BranchConfig branchConfig = new BranchConfig(c, "master");
			NUnit.Framework.Assert.IsNull(branchConfig.GetRemoteTrackingBranch());
		}
예제 #2
0
        public virtual void GetRemoteTrackingBranchShouldReturnNullWithoutMergeBranch()
        {
            Config c = Parse(string.Empty + "[remote \"origin\"]\n" + "  fetch = +refs/heads/onlyone:refs/remotes/origin/onlyone\n"
                             + "[branch \"master\"]\n" + "  remote = origin\n");
            //
            BranchConfig branchConfig = new BranchConfig(c, "master");

            NUnit.Framework.Assert.IsNull(branchConfig.GetRemoteTrackingBranch());
        }
예제 #3
0
		public virtual void GetRemoteTrackingBranchShouldHandleNormalCase()
		{
			Config c = Parse(string.Empty + "[remote \"origin\"]\n" + "  fetch = +refs/heads/*:refs/remotes/origin/*\n"
				 + "[branch \"master\"]\n" + "  remote = origin\n" + "  merge = refs/heads/master\n"
				);
			//
			BranchConfig branchConfig = new BranchConfig(c, "master");
			NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", branchConfig.GetRemoteTrackingBranch
				());
		}
예제 #4
0
        public virtual void GetRemoteTrackingBranchShouldHandleNormalCase()
        {
            Config c = Parse(string.Empty + "[remote \"origin\"]\n" + "  fetch = +refs/heads/*:refs/remotes/origin/*\n"
                             + "[branch \"master\"]\n" + "  remote = origin\n" + "  merge = refs/heads/master\n"
                             );
            //
            BranchConfig branchConfig = new BranchConfig(c, "master");

            NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", branchConfig.GetRemoteTrackingBranch
                                                ());
        }
예제 #5
0
		public virtual void GetRemoteTrackingBranchShouldHandleOtherMapping()
		{
			Config c = Parse(string.Empty + "[remote \"test\"]\n" + "  fetch = +refs/foo/*:refs/remotes/origin/foo/*\n"
				 + "  fetch = +refs/heads/*:refs/remotes/origin/*\n" + "  fetch = +refs/other/*:refs/remotes/origin/other/*\n"
				 + "[branch \"master\"]\n" + "  remote = test\n" + "  merge = refs/foo/master\n"
				 + "\n");
			//
			BranchConfig branchConfig = new BranchConfig(c, "master");
			NUnit.Framework.Assert.AreEqual("refs/remotes/origin/foo/master", branchConfig.GetRemoteTrackingBranch
				());
		}
예제 #6
0
        public virtual void GetRemoteTrackingBranchShouldHandleOtherMapping()
        {
            Config c = Parse(string.Empty + "[remote \"test\"]\n" + "  fetch = +refs/foo/*:refs/remotes/origin/foo/*\n"
                             + "  fetch = +refs/heads/*:refs/remotes/origin/*\n" + "  fetch = +refs/other/*:refs/remotes/origin/other/*\n"
                             + "[branch \"master\"]\n" + "  remote = test\n" + "  merge = refs/foo/master\n"
                             + "\n");
            //
            BranchConfig branchConfig = new BranchConfig(c, "master");

            NUnit.Framework.Assert.AreEqual("refs/remotes/origin/foo/master", branchConfig.GetRemoteTrackingBranch
                                                ());
        }
        /// <summary>
        /// Compute the tracking status for the <code>branchName</code> in
        /// <code>repository</code>.
        /// </summary>
        /// <remarks>
        /// Compute the tracking status for the <code>branchName</code> in
        /// <code>repository</code>.
        /// </remarks>
        /// <param name="repository">the git repository to compute the status from</param>
        /// <param name="branchName">the local branch</param>
        /// <returns>the tracking status, or null if it is not known</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public static NGit.BranchTrackingStatus Of(Repository repository, string branchName
                                                   )
        {
            BranchConfig branchConfig         = new BranchConfig(repository.GetConfig(), branchName);
            string       remoteTrackingBranch = branchConfig.GetRemoteTrackingBranch();

            if (remoteTrackingBranch == null)
            {
                return(null);
            }
            Ref tracking = repository.GetRef(remoteTrackingBranch);

            if (tracking == null)
            {
                return(null);
            }
            Ref local = repository.GetRef(branchName);

            if (local == null)
            {
                return(null);
            }
            RevWalk   walk           = new RevWalk(repository);
            RevCommit localCommit    = walk.ParseCommit(local.GetObjectId());
            RevCommit trackingCommit = walk.ParseCommit(tracking.GetObjectId());

            walk.SetRevFilter(RevFilter.MERGE_BASE);
            walk.MarkStart(localCommit);
            walk.MarkStart(trackingCommit);
            RevCommit mergeBase = walk.Next();

            walk.Reset();
            walk.SetRevFilter(RevFilter.ALL);
            int aheadCount  = RevWalkUtils.Count(walk, localCommit, mergeBase);
            int behindCount = RevWalkUtils.Count(walk, trackingCommit, mergeBase);

            return(new NGit.BranchTrackingStatus(remoteTrackingBranch, aheadCount, behindCount
                                                 ));
        }