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


C# Git.Checkout方法代码示例

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


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

示例1: FailingPathsShouldNotResultInOKReturnValue

 public virtual void FailingPathsShouldNotResultInOKReturnValue()
 {
     FilePath folder1 = new FilePath(db.WorkTree, "folder1");
     FileUtils.Mkdir(folder1);
     FilePath file = new FilePath(folder1, "file1.txt");
     Write(file, "folder1--file1.txt");
     file = new FilePath(folder1, "file2.txt");
     Write(file, "folder1--file2.txt");
     Git git = new Git(db);
     git.Add().AddFilepattern(folder1.GetName()).Call();
     RevCommit @base = git.Commit().SetMessage("adding folder").Call();
     RecursiveDelete(folder1);
     git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
         Call();
     RevCommit other = git.Commit().SetMessage("removing folders on 'other'").Call();
     git.Checkout().SetName(@base.Name).Call();
     file = new FilePath(db.WorkTree, "unrelated.txt");
     Write(file, "unrelated");
     git.Add().AddFilepattern("unrelated").Call();
     RevCommit head = git.Commit().SetMessage("Adding another file").Call();
     // Untracked file to cause failing path for delete() of folder1
     file = new FilePath(folder1, "file3.txt");
     Write(file, "folder1--file3.txt");
     ResolveMerger merger = new ResolveMerger(db, false);
     merger.SetCommitNames(new string[] { "BASE", "HEAD", "other" });
     merger.SetWorkingTreeIterator(new FileTreeIterator(db));
     bool ok = merger.Merge(head.Id, other.Id);
     NUnit.Framework.Assert.IsFalse(merger.GetFailingPaths().IsEmpty());
     NUnit.Framework.Assert.IsFalse(ok);
 }
开发者ID:dprothero,项目名称:ngit,代码行数:30,代码来源:ResolveMergerTest.cs

示例2: ResolveUnnamedCurrentBranchCommits

		public virtual void ResolveUnnamedCurrentBranchCommits()
		{
			Git git = new Git(db);
			WriteTrashFile("file.txt", "content");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit c1 = git.Commit().SetMessage("create file").Call();
			WriteTrashFile("file.txt", "content2");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit c2 = git.Commit().SetMessage("edit file").Call();
			NUnit.Framework.Assert.AreEqual(c2, db.Resolve("[email protected]{0}"));
			NUnit.Framework.Assert.AreEqual(c1, db.Resolve("[email protected]{1}"));
			git.Checkout().SetCreateBranch(true).SetName("newbranch").SetStartPoint(c1).Call(
				);
			// same as current branch, e.g. master
			NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{0}"));
			try
			{
				NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{1}"));
				NUnit.Framework.Assert.Fail();
			}
			catch (RevisionSyntaxException e)
			{
				// Looking at wrong ref, e.g HEAD
				NUnit.Framework.Assert.IsNotNull(e);
			}
			// detached head, read HEAD reflog
			git.Checkout().SetName(c2.GetName()).Call();
			NUnit.Framework.Assert.AreEqual(c2, db.Resolve("@{0}"));
			NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{1}"));
			NUnit.Framework.Assert.AreEqual(c2, db.Resolve("@{2}"));
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:31,代码来源:ReflogResolveTest.cs

示例3: SetUp

		public override void SetUp()
		{
			base.SetUp();
			git = new Git(db);
			// commit something
			WriteTrashFile(FILE, "Hello world");
			git.Add().AddFilepattern(FILE).Call();
			commit1 = git.Commit().SetMessage("Initial commit").Call();
			git.Checkout().SetCreateBranch(true).SetName("b1").Call();
			git.Rm().AddFilepattern(FILE).Call();
			commit2 = git.Commit().SetMessage("Removed file").Call();
			git.NotesAdd().SetObjectId(commit1).SetMessage("data").Call();
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:13,代码来源:ReflogCommandTest.cs

示例4: LockFailedExceptionRecovery

		public virtual void LockFailedExceptionRecovery()
		{
			Git git = new Git(db);
			WriteTrashFile("file.txt", "content");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit commit1 = git.Commit().SetMessage("create file").Call();
			NUnit.Framework.Assert.IsNotNull(commit1);
			WriteTrashFile("file.txt", "content2");
			git.Add().AddFilepattern("file.txt").Call();
			NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("edit file").Call());
			LockFile lf = new LockFile(db.GetIndexFile(), db.FileSystem);
			NUnit.Framework.Assert.IsTrue(lf.Lock());
			try
			{
				git.Checkout().SetName(commit1.Name).Call();
				NUnit.Framework.Assert.Fail("JGitInternalException not thrown");
			}
			catch (JGitInternalException e)
			{
				NUnit.Framework.Assert.IsTrue(e.InnerException is LockFailedException);
				lf.Unlock();
				git.Checkout().SetName(commit1.Name).Call();
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:24,代码来源:LockFileTest.cs

示例5: btnOK_Click

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Git git = new Git(this.repository);
                
                git.Checkout().SetName(radioButton1.IsChecked == true ? 
                        comboBranches.SelectedValue.ToString() : txtNewBranch.Text)
                    .SetCreateBranch(radioButton2.IsChecked == true)
                    .Call();

                window.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
开发者ID:Frrank1,项目名称:Git-Source-Control-Provider,代码行数:18,代码来源:BranchPicker.xaml.cs

示例6: TestModify

		public virtual void TestModify()
		{
			Git git = new Git(db);
			string path = "file";
			WriteTrashFile(path, "content");
			git.Add().AddFilepattern(path).Call();
			git.Commit().SetMessage("commit").Call();
			DirCache dc = db.ReadDirCache();
			DirCacheEntry entry = dc.GetEntry(path);
			long masterLastMod = entry.LastModified;
			git.Checkout().SetCreateBranch(true).SetName("side").Call();
			Sharpen.Thread.Sleep(10);
			string path2 = "file2";
			WriteTrashFile(path2, "side content");
			git.Add().AddFilepattern(path2).Call();
			git.Commit().SetMessage("commit").Call();
			dc = db.ReadDirCache();
			entry = dc.GetEntry(path);
			long sideLastMode = entry.LastModified;
			Sharpen.Thread.Sleep(2000);
			WriteTrashFile(path, "uncommitted content");
			git.Checkout().SetName("master").Call();
			dc = db.ReadDirCache();
			entry = dc.GetEntry(path);
			NUnit.Framework.Assert.IsTrue(masterLastMod == sideLastMode, "shall have equal mod time!"
				);
			NUnit.Framework.Assert.IsTrue(entry.LastModified == masterLastMod, "shall not equal master timestamp!"
				);
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:29,代码来源:IndexModificationTimesTest.cs

示例7: TestMergeRemovingFoldersWithoutFastForward

 public virtual void TestMergeRemovingFoldersWithoutFastForward()
 {
     FilePath folder1 = new FilePath(db.WorkTree, "folder1");
     FilePath folder2 = new FilePath(db.WorkTree, "folder2");
     FileUtils.Mkdir(folder1);
     FileUtils.Mkdir(folder2);
     FilePath file = new FilePath(folder1, "file1.txt");
     Write(file, "folder1--file1.txt");
     file = new FilePath(folder1, "file2.txt");
     Write(file, "folder1--file2.txt");
     file = new FilePath(folder2, "file1.txt");
     Write(file, "folder--file1.txt");
     file = new FilePath(folder2, "file2.txt");
     Write(file, "folder2--file2.txt");
     Git git = new Git(db);
     git.Add().AddFilepattern(folder1.GetName()).AddFilepattern(folder2.GetName()).Call
         ();
     RevCommit @base = git.Commit().SetMessage("adding folders").Call();
     RecursiveDelete(folder1);
     RecursiveDelete(folder2);
     git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
         AddFilepattern("folder2/file1.txt").AddFilepattern("folder2/file2.txt").Call();
     RevCommit other = git.Commit().SetMessage("removing folders on 'branch'").Call();
     git.Checkout().SetName(@base.Name).Call();
     file = new FilePath(folder2, "file3.txt");
     Write(file, "folder2--file3.txt");
     git.Add().AddFilepattern(folder2.GetName()).Call();
     git.Commit().SetMessage("adding another file").Call();
     MergeCommandResult result = git.Merge().Include(other.Id).SetStrategy(MergeStrategy
         .RESOLVE).Call();
     NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
     NUnit.Framework.Assert.IsFalse(folder1.Exists());
 }
开发者ID:OrangeCloudNetworks,项目名称:ngit,代码行数:33,代码来源:MergeCommandTest.cs

示例8: CheckOutBranch

        public void CheckOutBranch(string branch, bool createNew = false)
        {
            if (!this.HasGitRepository) return;
            if (GitBash.Exists)
            {
                try
                {
                    var result = GitBash.Run(string.Format("checkout {0} {1}", (createNew ? "-b" : ""), branch), this.GitWorkingDirectory);
                    if (result.HasError || result.Output.Contains("fatal:"))
                        throw new Exception(result.Output);
                }
                catch (Exception ex)
                {
                    if (!ex.Message.StartsWith("Switched to a new branch")) throw;
                }
            }
            else
            {
                Git git = new Git(this.repository);

                git.Checkout().SetName(branch)
                    .SetCreateBranch(createNew)
                    .Call();
            }
        }
开发者ID:b4shailen,项目名称:Git-Source-Control-Provider,代码行数:25,代码来源:GitFileStatusTracker.cs

示例9: 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

示例10: 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

示例11: 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

示例12: TestCheckoutRemoteTrackingWithoutLocalBranch

		public virtual void TestCheckoutRemoteTrackingWithoutLocalBranch()
		{
			// create second repository
			Repository db2 = CreateWorkRepository();
			Git git2 = new Git(db2);
			// setup the second repository to fetch from the first repository
			StoredConfig config = db2.GetConfig();
			RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
			URIish uri = new URIish(db.Directory.ToURI().ToURL());
			remoteConfig.AddURI(uri);
			remoteConfig.Update(config);
			config.Save();
			// fetch from first repository
			RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
			git2.Fetch().SetRemote("origin").SetRefSpecs(spec).Call();
			// checkout remote tracking branch in second repository
			// (no local branches exist yet in second repository)
			git2.Checkout().SetName("remotes/origin/test").Call();
			NUnit.Framework.Assert.AreEqual("[Test.txt, mode:100644, content:Some change]", IndexState
				(db2, CONTENT));
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:21,代码来源:CheckoutCommandTest.cs

示例13: 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

示例14: ResolvePreviousBranch

		public virtual void ResolvePreviousBranch()
		{
			Git git = new Git(db);
			WriteTrashFile("file.txt", "content");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit c1 = git.Commit().SetMessage("create file").Call();
			WriteTrashFile("file.txt", "content2");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit c2 = git.Commit().SetMessage("edit file").Call();
			git.Checkout().SetCreateBranch(true).SetName("newbranch").SetStartPoint(c1).Call(
				);
			git.Checkout().SetName(c1.GetName()).Call();
			git.Checkout().SetName("master").Call();
			NUnit.Framework.Assert.AreEqual(c1.GetName(), db.Simplify("@{-1}"));
			NUnit.Framework.Assert.AreEqual("newbranch", db.Simplify("@{-2}"));
			NUnit.Framework.Assert.AreEqual("master", db.Simplify("@{-3}"));
			// chained expression
			try
			{
				// Cannot refer to reflog of detached head
				db.Resolve("@{-1}@{0}");
				NUnit.Framework.Assert.Fail();
			}
			catch (RevisionSyntaxException)
			{
			}
			// good
			NUnit.Framework.Assert.AreEqual(c1.GetName(), db.Resolve("@{-2}@{0}").GetName());
			NUnit.Framework.Assert.AreEqual(c2.GetName(), db.Resolve("@{-3}@{0}").GetName());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:30,代码来源:ReflogResolveTest.cs

示例15: 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


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