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()); 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 ()); }
public virtual void LogAllCommits() { IList <RevCommit> commits = new AList <RevCommit>(); Git git = Git.Wrap(db); WriteTrashFile("Test.txt", "Hello world"); git.Add().AddFilepattern("Test.txt").Call(); commits.AddItem(git.Commit().SetMessage("initial commit").Call()); git.BranchCreate().SetName("branch1").Call(); Ref checkedOut = git.Checkout().SetName("branch1").Call(); NUnit.Framework.Assert.AreEqual("refs/heads/branch1", checkedOut.GetName()); WriteTrashFile("Test1.txt", "Hello world!"); git.Add().AddFilepattern("Test1.txt").Call(); commits.AddItem(git.Commit().SetMessage("branch1 commit").Call()); checkedOut = git.Checkout().SetName("master").Call(); NUnit.Framework.Assert.AreEqual("refs/heads/master", checkedOut.GetName()); WriteTrashFile("Test2.txt", "Hello world!!"); git.Add().AddFilepattern("Test2.txt").Call(); commits.AddItem(git.Commit().SetMessage("branch1 commit").Call()); Iterator <RevCommit> log = git.Log().All().Call().Iterator(); NUnit.Framework.Assert.IsTrue(log.HasNext()); NUnit.Framework.Assert.IsTrue(commits.Contains(log.Next())); NUnit.Framework.Assert.IsTrue(log.HasNext()); NUnit.Framework.Assert.IsTrue(commits.Contains(log.Next())); NUnit.Framework.Assert.IsTrue(log.HasNext()); NUnit.Framework.Assert.IsTrue(commits.Contains(log.Next())); NUnit.Framework.Assert.IsFalse(log.HasNext()); }
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" )); }
public virtual void TestUpdateWorkingDirectory() { CheckoutCommand co = git.Checkout(); FilePath written = WriteTrashFile(FILE1, string.Empty); NUnit.Framework.Assert.AreEqual(string.Empty, Read(written)); co.AddPath(FILE1).Call(); NUnit.Framework.Assert.AreEqual("3", Read(written)); NUnit.Framework.Assert.AreEqual("c", Read(new FilePath(db.WorkTree, FILE2))); }
public virtual void TestSimpleCheckout() { try { git.Checkout().SetName("test").Call(); } catch (Exception e) { NUnit.Framework.Assert.Fail(e.Message); } }
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); } }
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); }
public virtual void StashChangeInANewSubdirectory() { string subdir = "subdir"; string fname = "file2.txt"; string path = subdir + "/" + fname; string otherBranch = "otherbranch"; WriteTrashFile(subdir, fname, "content2"); git.Add().AddFilepattern(path).Call(); RevCommit stashed = git.StashCreate().Call(); NUnit.Framework.Assert.IsNotNull(stashed); NUnit.Framework.Assert.IsTrue(git.Status().Call().IsClean()); git.BranchCreate().SetName(otherBranch).Call(); git.Checkout().SetName(otherBranch).Call(); ObjectId unstashed = git.StashApply().Call(); NUnit.Framework.Assert.AreEqual(stashed, unstashed); Status status = git.Status().Call(); NUnit.Framework.Assert.IsTrue(status.GetChanged().IsEmpty()); NUnit.Framework.Assert.IsTrue(status.GetConflicting().IsEmpty()); NUnit.Framework.Assert.IsTrue(status.GetMissing().IsEmpty()); NUnit.Framework.Assert.IsTrue(status.GetRemoved().IsEmpty()); NUnit.Framework.Assert.IsTrue(status.GetModified().IsEmpty()); NUnit.Framework.Assert.IsTrue(status.GetUntracked().IsEmpty()); NUnit.Framework.Assert.AreEqual(1, status.GetAdded().Count); NUnit.Framework.Assert.IsTrue(status.GetAdded().Contains(path)); }
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("master@{0}")); NUnit.Framework.Assert.AreEqual(c1, db.Resolve("master@{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}")); }
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"); }
public virtual void TestCheckoutRemoteTrackingWithoutLocalBranch() { try { // 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)); } catch (Exception e) { NUnit.Framework.Assert.Fail(e.Message); } }
public virtual void TestCloneRepositoryWithMultipleHeadBranches() { git.Checkout().SetName(Constants.MASTER).Call(); git.BranchCreate().SetName("a").Call(); FilePath directory = CreateTempDirectory("testCloneRepositoryWithMultipleHeadBranches" ); CloneCommand clone = Git.CloneRepository(); clone.SetDirectory(directory); clone.SetURI("file://" + git.GetRepository().WorkTree.GetPath()); Git git2 = clone.Call(); AddRepoToClose(git2.GetRepository()); NUnit.Framework.Assert.IsNotNull(git2); NUnit.Framework.Assert.AreEqual(Constants.MASTER, git2.GetRepository().GetBranch( )); }
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(); }
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(); }
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(); } }
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); } }
/// <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); } }
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!" ); }
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()); }
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(); } }
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"); }
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 ()); }
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" )); }
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); } }
public virtual void TestSimpleCheckout() { git.Checkout().SetName("test").Call(); }
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()); }
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)); }