当前位置: 首页>>代码示例>>C#>>正文


C# GitHubClient.GetLatestCommitId方法代码示例

本文整理汇总了C#中GitHubClient.GetLatestCommitId方法的典型用法代码示例。如果您正苦于以下问题:C# GitHubClient.GetLatestCommitId方法的具体用法?C# GitHubClient.GetLatestCommitId怎么用?C# GitHubClient.GetLatestCommitId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GitHubClient的用法示例。


在下文中一共展示了GitHubClient.GetLatestCommitId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsLocalRepositorySynchronizedToRemote

		/// <summary>
		/// Checks if the local repository is clean and if at least one remote branch tip 
		/// is set to the latest known commit of a tracked remote repository.
		/// Note that this method can still return true if the local repository head is
		/// behind an up-to-date remote-tracking branch.
		/// </summary>
		/// <param name="localRepositoryPath">A path to the base directory of a repository on the local machine.</param>
		/// <param name="remoteOwner">The remote repository owner name.</param>
		/// <param name="remoteRepository">The remote repository name.</param>
		/// <param name="remoteBranch">The remote branch name of the repository.</param>
		/// <returns>True if the local repository is in sync, false if not.</returns>
		public static bool IsLocalRepositorySynchronizedToRemote(string localRepositoryPath, string remoteOwner, string remoteRepository, string remoteBranch)
		{
			GitHubClient client = new GitHubClient(new Uri("http://git/api/v3/"));
			string latestCommitId = client.GetLatestCommitId(remoteOwner, remoteRepository, remoteBranch);

			// HACK: it appears that LibGit2Sharp (or perhaps LibGit2) has trouble with submodules
			//   where the .git file points to the parent repo's modules folder. Force the working
			//   directory to be the specified path.
			using (Repository repo = new Repository(localRepositoryPath, new RepositoryOptions {WorkingDirectoryPath = localRepositoryPath}))
			{
				RepositoryStatus status = repo.Index.RetrieveStatus();

				bool inSync = true;
				if (status.IsDirty)
				{
					bool isDirty = true;

					// HACK: handle an untracked .git file, in the case of a submodule (see above)
					if (status.CountIsExactly(1))
					{
						StatusEntry entry = status.Single();
						if (entry.State == FileStatus.Untracked && entry.FilePath == ".git")
							isDirty = false;
					}

					if (isDirty)
					{
						Log.Error("Git repository is dirty!");
						foreach (StatusEntry entry in status)
							Log.Debug("{0}: {1}", entry.State, entry.FilePath);
						inSync = false;
					}
				}
				else
				{
					Log.Info("Git repository is clean.");
				}

				var remoteBranches = repo.Branches.Where(x => x.IsRemote).ToList();
				if (!remoteBranches.Any(x => x.Tip.Sha == repo.Head.Tip.Sha))
					Log.Warn("Repository HEAD ({0}) does not match tip of any branch; local repository is behind.", repo.Head.Tip.Sha);

				if (!remoteBranches.Any(x => x.Tip.Sha == latestCommitId))
				{
					Log.Error("No remote branch tip is set to latest remote commit '{0}'.", latestCommitId);
					inSync = false;
				}

				return inSync;
			}
		}
开发者ID:etihwddot,项目名称:Logos.Git,代码行数:62,代码来源:GitUtility.cs


注:本文中的GitHubClient.GetLatestCommitId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。