Пример #1
0
		/// <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 trackingBranch = branchConfig.GetTrackingBranch();
			if (trackingBranch == null)
			{
				return null;
			}
			Ref tracking = repository.GetRef(trackingBranch);
			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(trackingBranch, aheadCount, behindCount);
		}
Пример #2
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());
		}
Пример #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 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
				());
		}