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


C# Git.GetRepository方法代码示例

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


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

示例1: ValidateIndex

 /// <exception cref="NGit.Errors.NoWorkTreeException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 public static void ValidateIndex(Git git)
 {
     DirCache dc = git.GetRepository().LockDirCache();
     ObjectReader r = git.GetRepository().ObjectDatabase.NewReader();
     try
     {
         for (int i = 0; i < dc.GetEntryCount(); ++i)
         {
             DirCacheEntry entry = dc.GetEntry(i);
             if (entry.Length > 0)
             {
                 NUnit.Framework.Assert.AreEqual(entry.Length, r.GetObjectSize(entry.GetObjectId()
                     , ObjectReader.OBJ_ANY));
             }
         }
     }
     finally
     {
         dc.Unlock();
         r.Release();
     }
 }
开发者ID:kenji-tan,项目名称:ngit,代码行数:24,代码来源:PathCheckoutCommandTest.cs

示例2: TestFileModeMerge

 public virtual void TestFileModeMerge()
 {
     if (!FS.DETECTED.SupportsExecute())
     {
         return;
     }
     // Only Java6
     Git git = new Git(db);
     WriteTrashFile("mergeableMode", "a");
     SetExecutable(git, "mergeableMode", false);
     WriteTrashFile("conflictingModeWithBase", "a");
     SetExecutable(git, "conflictingModeWithBase", false);
     RevCommit initialCommit = AddAllAndCommit(git);
     // switch branch
     CreateBranch(initialCommit, "refs/heads/side");
     CheckoutBranch("refs/heads/side");
     SetExecutable(git, "mergeableMode", true);
     WriteTrashFile("conflictingModeNoBase", "b");
     SetExecutable(git, "conflictingModeNoBase", true);
     RevCommit sideCommit = AddAllAndCommit(git);
     // switch branch
     CreateBranch(initialCommit, "refs/heads/side2");
     CheckoutBranch("refs/heads/side2");
     SetExecutable(git, "mergeableMode", false);
     NUnit.Framework.Assert.IsFalse(new FilePath(git.GetRepository().WorkTree, "conflictingModeNoBase"
         ).Exists());
     WriteTrashFile("conflictingModeNoBase", "b");
     SetExecutable(git, "conflictingModeNoBase", false);
     AddAllAndCommit(git);
     // merge
     MergeCommandResult result = git.Merge().Include(sideCommit.Id).SetStrategy(MergeStrategy
         .RESOLVE).Call();
     NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
     NUnit.Framework.Assert.IsTrue(CanExecute(git, "mergeableMode"));
     NUnit.Framework.Assert.IsFalse(CanExecute(git, "conflictingModeNoBase"));
 }
开发者ID:OrangeCloudNetworks,项目名称:ngit,代码行数:36,代码来源:MergeCommandTest.cs

示例3: CanExecute

 private bool CanExecute(Git git, string path)
 {
     return FS.DETECTED.CanExecute(new FilePath(git.GetRepository().WorkTree, path));
 }
开发者ID:OrangeCloudNetworks,项目名称:ngit,代码行数:4,代码来源:MergeCommandTest.cs

示例4: SetExecutable

 private void SetExecutable(Git git, string path, bool executable)
 {
     FS.DETECTED.SetExecute(new FilePath(git.GetRepository().WorkTree, path), executable
         );
 }
开发者ID:OrangeCloudNetworks,项目名称:ngit,代码行数:5,代码来源:MergeCommandTest.cs

示例5: SettingHttpBufferSize

        /// <summary>
        /// httpプロトコルバッファ値を設定。
        /// この設定がないと大きなファイルをpushできない。
        /// </summary>
        /// <param name="folderPath">リポジトリパス</param>
        private void SettingHttpBufferSize(string folderPath)
        {
            FilePath path = new FilePath(folderPath, @".git");

            FileRepository db = new FileRepository(path);

            Git git = new Git(db);

            var config = git.GetRepository().GetConfig();

            config.SetString("http", null, "postBuffer", "524288000");
            config.Save();
        }
开发者ID:takanemu,项目名称:BluePlumGit,代码行数:18,代码来源:MainWindowModel.cs

示例6: GetCurrentBranch

 /// <summary>
 /// カレントブランチ名を取得する
 /// </summary>
 /// <param name="git">Gitクラス</param>
 /// <returns>ブランチ名</returns>
 public static string GetCurrentBranch(Git git)
 {
     return git.GetRepository().GetBranch();
 }
开发者ID:SatoKazuto,项目名称:BluePlumGit,代码行数:9,代码来源:RepositotyUtility.cs

示例7: TestPushWithoutPushRefSpec

		public virtual void TestPushWithoutPushRefSpec()
		{
			Git git = new Git(db);
			Git git2 = new Git(CreateBareRepository());
			StoredConfig config = git.GetRepository().GetConfig();
			RemoteConfig remoteConfig = new RemoteConfig(config, "test");
			URIish uri = new URIish(git2.GetRepository().Directory.ToURI().ToURL());
			remoteConfig.AddURI(uri);
			remoteConfig.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
			remoteConfig.Update(config);
			config.Save();
			WriteTrashFile("f", "content of f");
			git.Add().AddFilepattern("f").Call();
			RevCommit commit = git.Commit().SetMessage("adding f").Call();
			git.Checkout().SetName("not-pushed").SetCreateBranch(true).Call();
			git.Checkout().SetName("branchtopush").SetCreateBranch(true).Call();
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/branchtopush"
				));
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/not-pushed"
				));
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/master"
				));
			git.Push().SetRemote("test").Call();
			NUnit.Framework.Assert.AreEqual(commit.Id, git2.GetRepository().Resolve("refs/heads/branchtopush"
				));
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/not-pushed"
				));
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/master"
				));
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:30,代码来源:PushCommandTest.cs

示例8: SetUp

 public override void SetUp()
 {
     base.SetUp();
     dbTarget = CreateWorkRepository();
     source = new Git(db);
     target = new Git(dbTarget);
     // put some file in the source repo
     sourceFile = new FilePath(db.WorkTree, "SomeFile.txt");
     WriteToFile(sourceFile, "Hello world");
     // and commit it
     source.Add().AddFilepattern("SomeFile.txt").Call();
     source.Commit().SetMessage("Initial commit for source").Call();
     // configure the target repo to connect to the source via "origin"
     StoredConfig targetConfig = ((FileBasedConfig)dbTarget.GetConfig());
     targetConfig.SetString("branch", "master", "remote", "origin");
     targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
     RemoteConfig config = new RemoteConfig(targetConfig, "origin");
     config.AddURI(new URIish(source.GetRepository().WorkTree.GetPath()));
     config.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
     config.Update(targetConfig);
     targetConfig.Save();
     targetFile = new FilePath(dbTarget.WorkTree, "SomeFile.txt");
     // make sure we have the same content
     target.Pull().Call();
     target.Checkout().SetStartPoint("refs/remotes/origin/master").SetName("master").Call
         ();
     targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
     targetConfig.SetBoolean("branch", "master", "rebase", true);
     targetConfig.Save();
     AssertFileContentsEqual(targetFile, "Hello world");
 }
开发者ID:nnieslan,项目名称:ngit,代码行数:31,代码来源:PullCommandWithRebaseTest.cs

示例9: TestPushRefUpdate

		public virtual void TestPushRefUpdate()
		{
			Git git = new Git(db);
			Git git2 = new Git(CreateBareRepository());
			StoredConfig config = git.GetRepository().GetConfig();
			RemoteConfig remoteConfig = new RemoteConfig(config, "test");
			URIish uri = new URIish(git2.GetRepository().Directory.ToURI().ToURL());
			remoteConfig.AddURI(uri);
			remoteConfig.AddPushRefSpec(new RefSpec("+refs/heads/*:refs/heads/*"));
			remoteConfig.Update(config);
			config.Save();
			WriteTrashFile("f", "content of f");
			git.Add().AddFilepattern("f").Call();
			RevCommit commit = git.Commit().SetMessage("adding f").Call();
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/master"
				));
			git.Push().SetRemote("test").Call();
			NUnit.Framework.Assert.AreEqual(commit.Id, git2.GetRepository().Resolve("refs/heads/master"
				));
			git.BranchCreate().SetName("refs/heads/test").Call();
			git.Checkout().SetName("refs/heads/test").Call();
			for (int i = 0; i < 6; i++)
			{
				WriteTrashFile("f" + i, "content of f" + i);
				git.Add().AddFilepattern("f" + i).Call();
				commit = git.Commit().SetMessage("adding f" + i).Call();
				git.Push().SetRemote("test").Call();
				git2.GetRepository().GetAllRefs();
				NUnit.Framework.Assert.AreEqual(commit.Id, git2.GetRepository().Resolve("refs/heads/test"
					), "failed to update on attempt " + i);
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:32,代码来源:PushCommandTest.cs

示例10: TestDifferentStates

		public virtual void TestDifferentStates()
		{
			Git git = new Git(db);
			WriteTrashFile("a", "content of a");
			WriteTrashFile("b", "content of b");
			WriteTrashFile("c", "content of c");
			git.Add().AddFilepattern("a").AddFilepattern("b").Call();
			Status stat = git.Status().Call();
			NUnit.Framework.Assert.AreEqual(Set("a", "b"), Set (stat.GetAdded()));
			NUnit.Framework.Assert.AreEqual(0, stat.GetChanged().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetMissing().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetModified().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetRemoved().Count);
			NUnit.Framework.Assert.AreEqual(Set("c"), Set (stat.GetUntracked()));
			git.Commit().SetMessage("initial").Call();
			WriteTrashFile("a", "modified content of a");
			WriteTrashFile("b", "modified content of b");
			WriteTrashFile("d", "content of d");
			git.Add().AddFilepattern("a").AddFilepattern("d").Call();
			WriteTrashFile("a", "again modified content of a");
			stat = git.Status().Call();
			NUnit.Framework.Assert.AreEqual(Set("d"), Set (stat.GetAdded()));
			NUnit.Framework.Assert.AreEqual(Set("a"), Set (stat.GetChanged()));
			NUnit.Framework.Assert.AreEqual(0, stat.GetMissing().Count);
			NUnit.Framework.Assert.AreEqual(Set("b", "a"), Set (stat.GetModified()));
			NUnit.Framework.Assert.AreEqual(0, stat.GetRemoved().Count);
			NUnit.Framework.Assert.AreEqual(Set("c"), Set (stat.GetUntracked()));
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("second").Call();
			stat = git.Status().Call();
			NUnit.Framework.Assert.AreEqual(0, stat.GetAdded().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetChanged().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetMissing().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetModified().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetRemoved().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetUntracked().Count);
			DeleteTrashFile("a");
			NUnit.Framework.Assert.IsFalse(new FilePath(git.GetRepository().WorkTree, "a").Exists
				());
			git.Add().AddFilepattern("a").SetUpdate(true).Call();
			WriteTrashFile("a", "recreated content of a");
			stat = git.Status().Call();
			NUnit.Framework.Assert.AreEqual(0, stat.GetAdded().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetChanged().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetMissing().Count);
			NUnit.Framework.Assert.AreEqual(0, stat.GetModified().Count);
			NUnit.Framework.Assert.AreEqual(Set("a"), Set (stat.GetRemoved()));
			NUnit.Framework.Assert.AreEqual(Set("a"), Set (stat.GetUntracked()));
			git.Commit().SetMessage("t").Call();
		}
开发者ID:shoff,项目名称:ngit,代码行数:50,代码来源:StatusCommandTest.cs

示例11: TestCherryPickOverExecutableChangeOnNonExectuableFileSystem

 public virtual void TestCherryPickOverExecutableChangeOnNonExectuableFileSystem()
 {
     Git git = new Git(db);
     FilePath file = WriteTrashFile("test.txt", "a");
     NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern("test.txt").Call());
     NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("commit1").Call());
     NUnit.Framework.Assert.IsNotNull(git.Checkout().SetCreateBranch(true).SetName("a"
         ).Call());
     WriteTrashFile("test.txt", "b");
     NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern("test.txt").Call());
     RevCommit commit2 = git.Commit().SetMessage("commit2").Call();
     NUnit.Framework.Assert.IsNotNull(commit2);
     NUnit.Framework.Assert.IsNotNull(git.Checkout().SetName(Constants.MASTER).Call());
     DirCache cache = db.LockDirCache();
     cache.GetEntry("test.txt").FileMode = FileMode.EXECUTABLE_FILE;
     cache.Write();
     NUnit.Framework.Assert.IsTrue(cache.Commit());
     cache.Unlock();
     NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("commit3").Call());
     db.FileSystem.SetExecute(file, false);
     git.GetRepository().GetConfig().SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null
         , ConfigConstants.CONFIG_KEY_FILEMODE, false);
     CherryPickResult result = git.CherryPick().Include(commit2).Call();
     NUnit.Framework.Assert.IsNotNull(result);
     NUnit.Framework.Assert.AreEqual(CherryPickResult.CherryPickStatus.OK, result.GetStatus
         ());
 }
开发者ID:stinos,项目名称:ngit,代码行数:27,代码来源:CherryPickCommandTest.cs

示例12: CommitFile

		/// <summary>
		/// Commit a file with the specified contents on the specified branch,
		/// creating the branch if it didn't exist before.
		/// </summary>
		/// <remarks>
		/// Commit a file with the specified contents on the specified branch,
		/// creating the branch if it didn't exist before.
		/// <p>
		/// It switches back to the original branch after the commit if there was
		/// one.
		/// </remarks>
		/// <param name="filename"></param>
		/// <param name="contents"></param>
		/// <param name="branch"></param>
		/// <returns>the created commit</returns>
		protected internal virtual RevCommit CommitFile(string filename, string contents, 
			string branch)
		{
			try
			{
				Git git = new Git(db);
				string originalBranch = git.GetRepository().GetFullBranch();
				if (git.GetRepository().GetRef(branch) == null)
				{
					git.BranchCreate().SetName(branch).Call();
				}
				git.Checkout().SetName(branch).Call();
				WriteTrashFile(filename, contents);
				git.Add().AddFilepattern(filename).Call();
				RevCommit commit = git.Commit().SetMessage(branch + ": " + filename).Call();
				if (originalBranch != null)
				{
					git.Checkout().SetName(originalBranch).Call();
				}
				return commit;
			}
			catch (IOException e)
			{
				throw new RuntimeException(e);
			}
			catch (GitAPIException e)
			{
				throw new RuntimeException(e);
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:45,代码来源:RepositoryTestCase.cs

示例13: GetHead

		/// <exception cref="System.Exception"></exception>
		private string GetHead(Git git, string path)
		{
			try
			{
				Repository repo = git.GetRepository();
				ObjectId headId = repo.Resolve(Constants.HEAD + "^{commit}");
				TreeWalk tw = TreeWalk.ForPath(repo, path, new RevWalk(repo).ParseTree(headId));
				return Sharpen.Runtime.GetStringForBytes(tw.ObjectReader.Open(tw.GetObjectId(0)).
					GetBytes());
			}
			catch (Exception)
			{
				return string.Empty;
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:16,代码来源:CommitOnlyTest.cs


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