private static string TextFor(RevCommit cmit) { byte[] raw = cmit.RawBuffer; int b = RawParseUtils.author(raw, 0); if (b < 0) return string.Empty; int e = RawParseUtils.nextLF(raw, b, (byte)'>'); return Constants.CHARSET.GetString(raw, b, e); }
public static RawCharSequence textFor(RevCommit cmit) { byte[] raw = cmit.getRawBuffer(); int b = RawParseUtils.committer(raw, 0); if (b < 0) return RawCharSequence.EMPTY; int e = RawParseUtils.nextLF(raw, b, (byte)'>'); return new RawCharSequence(raw, b, e); }
private static string TextFor(RevCommit cmit) { byte[] raw = cmit.RawBuffer; int b = RawParseUtils.commitMessage(raw, 0); if (b < 0) { return string.Empty; } return Constants.CHARSET.GetString(raw, b, raw.Length); }
public void testHasFlags() { RevCommit a = parseBody(Commit()); RevCommit b = parseBody(Commit(a)); q.add(a); q.add(b); Assert.IsFalse(q.everbodyHasFlag(GitSharp.Core.RevWalk.RevWalk.UNINTERESTING)); Assert.IsFalse(q.anybodyHasFlag(GitSharp.Core.RevWalk.RevWalk.UNINTERESTING)); a.Flags |= GitSharp.Core.RevWalk.RevWalk.UNINTERESTING; Assert.IsFalse(q.everbodyHasFlag(GitSharp.Core.RevWalk.RevWalk.UNINTERESTING)); Assert.IsTrue(q.anybodyHasFlag(GitSharp.Core.RevWalk.RevWalk.UNINTERESTING)); b.Flags |= GitSharp.Core.RevWalk.RevWalk.UNINTERESTING; Assert.IsTrue(q.everbodyHasFlag(GitSharp.Core.RevWalk.RevWalk.UNINTERESTING)); Assert.IsTrue(q.anybodyHasFlag(GitSharp.Core.RevWalk.RevWalk.UNINTERESTING)); }
public virtual void RefLogIncludesCommitMessage() { PersonIdent who = new PersonIdent("user", "*****@*****.**"); DeleteTrashFile("file.txt"); RevCommit stashed = git.StashCreate().SetPerson(who).Call(); NUnit.Framework.Assert.IsNotNull(stashed); NUnit.Framework.Assert.AreEqual("content", Read(committedFile)); ValidateStashedCommit(stashed); ReflogReader reader = new ReflogReader(git.GetRepository(), Constants.R_STASH); ReflogEntry entry = reader.GetLastEntry(); NUnit.Framework.Assert.IsNotNull(entry); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entry.GetOldId()); NUnit.Framework.Assert.AreEqual(stashed, entry.GetNewId()); NUnit.Framework.Assert.AreEqual(who, entry.GetWho()); NUnit.Framework.Assert.AreEqual(stashed.GetFullMessage(), entry.GetComment()); }
public virtual void TestLinear() { RevCommit a = Commit(); RevCommit b = Commit(a); RevCommit c = Commit(b); PlotWalk pw = new PlotWalk(db); pw.MarkStart(pw.LookupCommit(c.Id)); PlotCommitList <PlotLane> pcl = new PlotCommitList <PlotLane>(); pcl.Source(pw); pcl.FillTo(int.MaxValue); PlotCommitListTest.CommitListAssert test = new PlotCommitListTest.CommitListAssert (this, pcl); test.Commit(c).LanePos(0).Parents(b); test.Commit(b).LanePos(0).Parents(a); test.Commit(a).LanePos(0).Parents(); test.NoMoreCommits(); }
public virtual void TestLeafSplitsWhenFull() { RevBlob data1 = tr.Blob("data1"); MutableObjectId idBuf = new MutableObjectId(); RevCommit r = tr.Commit().Add(data1.Name, data1).Create(); // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); for (int i = 0; i < 254; i++) { idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i); map.Set(idBuf, data1); } RevCommit n = CommitNoteMap(map); TreeWalk tw = new TreeWalk(reader); tw.Reset(n.Tree); while (tw.Next()) { NUnit.Framework.Assert.IsFalse(tw.IsSubtree, "no fan-out subtree"); } for (int i_1 = 254; i_1 < 256; i_1++) { idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i_1); map.Set(idBuf, data1); } idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 2, 1); map.Set(idBuf, data1); n = CommitNoteMap(map); // The 00 bucket is fully split. string path = Fanout(38, idBuf.Name); tw = TreeWalk.ForPath(reader, path, n.Tree); NUnit.Framework.Assert.IsNotNull(tw, "has " + path); // The other bucket is not. path = Fanout(2, data1.Name); tw = TreeWalk.ForPath(reader, path, n.Tree); NUnit.Framework.Assert.IsNotNull(tw, "has " + path); }
public virtual void TestBoundLineDelete() { Git git = new Git(db); string[] content1 = new string[] { "first", "second" }; WriteTrashFile("file.txt", Join(content1)); git.Add().AddFilepattern("file.txt").Call(); RevCommit c1 = git.Commit().SetMessage("create file").Call(); string[] content2 = new string[] { "third", "first", "second" }; WriteTrashFile("file.txt", Join(content2)); git.Add().AddFilepattern("file.txt").Call(); RevCommit c2 = git.Commit().SetMessage("create file").Call(); BlameGenerator generator = new BlameGenerator(db, "file.txt"); try { generator.Push(null, db.Resolve(Constants.HEAD)); NUnit.Framework.Assert.AreEqual(3, generator.GetResultContents().Size()); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(c2, generator.GetSourceCommit()); NUnit.Framework.Assert.AreEqual(1, generator.GetRegionLength()); NUnit.Framework.Assert.AreEqual(0, generator.GetResultStart()); NUnit.Framework.Assert.AreEqual(1, generator.GetResultEnd()); NUnit.Framework.Assert.AreEqual(0, generator.GetSourceStart()); NUnit.Framework.Assert.AreEqual(1, generator.GetSourceEnd()); NUnit.Framework.Assert.AreEqual("file.txt", generator.GetSourcePath()); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(c1, generator.GetSourceCommit()); NUnit.Framework.Assert.AreEqual(2, generator.GetRegionLength()); NUnit.Framework.Assert.AreEqual(1, generator.GetResultStart()); NUnit.Framework.Assert.AreEqual(3, generator.GetResultEnd()); NUnit.Framework.Assert.AreEqual(0, generator.GetSourceStart()); NUnit.Framework.Assert.AreEqual(2, generator.GetSourceEnd()); NUnit.Framework.Assert.AreEqual("file.txt", generator.GetSourcePath()); NUnit.Framework.Assert.IsFalse(generator.Next()); } finally { generator.Release(); } }
public virtual void TestResetHard() { Git git = new Git(db); WriteTrashFile("f", "f()"); WriteTrashFile("D/g", "g()"); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("inital").Call(); AssertIndex(Mkmap("f", "f()", "D/g", "g()")); git.BranchCreate().SetName("topic").Call(); WriteTrashFile("f", "f()\nmaster"); WriteTrashFile("D/g", "g()\ng2()"); WriteTrashFile("E/h", "h()"); git.Add().AddFilepattern(".").Call(); RevCommit master = git.Commit().SetMessage("master-1").Call(); AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()")); CheckoutBranch("refs/heads/topic"); AssertIndex(Mkmap("f", "f()", "D/g", "g()")); WriteTrashFile("f", "f()\nside"); NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "D/g").Delete()); WriteTrashFile("G/i", "i()"); git.Add().AddFilepattern(".").Call(); git.Add().AddFilepattern(".").SetUpdate(true).Call(); RevCommit topic = git.Commit().SetMessage("topic-1").Call(); AssertIndex(Mkmap("f", "f()\nside", "G/i", "i()")); WriteTrashFile("untracked", "untracked"); ResetHard(master); AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()")); ResetHard(topic); AssertIndex(Mkmap("f", "f()\nside", "G/i", "i()")); AssertWorkDir(Mkmap("f", "f()\nside", "G/i", "i()", "untracked", "untracked")); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, git.Merge().Include(master ).Call().GetMergeStatus()); NUnit.Framework.Assert.AreEqual("[E/h, mode:100644][G/i, mode:100644][f, mode:100644, stage:1][f, mode:100644, stage:2][f, mode:100644, stage:3]" , IndexState(0)); ResetHard(master); AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()")); AssertWorkDir(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()", "untracked" , "untracked")); }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception> /// <exception cref="NGit.Api.Errors.GitAPIException"></exception> public virtual void SetupRepository() { // create initial commit git = new Git(db); initialCommit = git.Commit().SetMessage("initial commit").Call(); // create nested file FilePath dir = new FilePath(db.WorkTree, "dir"); FileUtils.Mkdir(dir); FilePath nestedFile = new FilePath(dir, "b.txt"); FileUtils.CreateNewFile(nestedFile); PrintWriter nesterFileWriter = new PrintWriter(nestedFile); nesterFileWriter.Write("content"); nesterFileWriter.Flush(); // create file indexFile = new FilePath(db.WorkTree, "a.txt"); FileUtils.CreateNewFile(indexFile); PrintWriter writer = new PrintWriter(indexFile); writer.Write("content"); writer.Flush(); // add file and commit it git.Add().AddFilepattern("dir").AddFilepattern("a.txt").Call(); secondCommit = git.Commit().SetMessage("adding a.txt and dir/b.txt").Call(); prestage = DirCache.Read(db.GetIndexFile(), db.FileSystem).GetEntry(indexFile.GetName ()); // modify file and add to index writer.Write("new content"); writer.Close(); nesterFileWriter.Write("new content"); nesterFileWriter.Close(); git.Add().AddFilepattern("a.txt").AddFilepattern("dir").Call(); // create a file not added to the index untrackedFile = new FilePath(db.WorkTree, "notAddedToIndex.txt"); FileUtils.CreateNewFile(untrackedFile); PrintWriter writer2 = new PrintWriter(untrackedFile); writer2.Write("content"); writer2.Close(); }
public virtual void TestPackCommitsAndLooseOneNoReflog() { BranchBuilder bb = tr.Branch("refs/heads/master"); RevCommit first = bb.Commit().Add("A", "A").Add("B", "B").Create(); bb.Commit().Add("A", "A2").Add("B", "B2").Create(); tr.Update("refs/heads/master", first); stats = gc.GetStatistics(); NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects); NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects); FileUtils.Delete(new FilePath(repo.Directory, "logs/HEAD"), FileUtils.RETRY | FileUtils .SKIP_MISSING); FileUtils.Delete(new FilePath(repo.Directory, "logs/refs/heads/master"), FileUtils .RETRY | FileUtils.SKIP_MISSING); gc.Gc(); stats = gc.GetStatistics(); NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects); NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects); NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles); }
public override void SetUp() { base.SetUp(); git = new Git(db); // checkout master git.Commit().SetMessage("initial commit").Call(); // commit something WriteTrashFile("Test.txt", "Hello world"); git.Add().AddFilepattern("Test.txt").Call(); initialCommit = git.Commit().SetMessage("Initial commit").Call(); WriteTrashFile("Test.txt", "Some change"); git.Add().AddFilepattern("Test.txt").Call(); secondCommit = git.Commit().SetMessage("Second commit").Call(); // create a master branch RefUpdate rup = db.UpdateRef("refs/heads/master"); rup.SetNewObjectId(initialCommit.Id); rup.SetForceUpdate(true); rup.Update(); }
public void testSort_TOPO_REVERSE() { // c1 is back dated before its parent. // RevCommit a = Commit(); RevCommit b = Commit(a); RevCommit c1 = Commit(-5, b); RevCommit c2 = Commit(10, b); RevCommit d = Commit(c1, c2); rw.sort(RevSort.TOPO); rw.sort(RevSort.REVERSE, true); MarkStart(d); AssertCommit(a, rw.next()); AssertCommit(b, rw.next()); AssertCommit(c1, rw.next()); AssertCommit(c2, rw.next()); AssertCommit(d, rw.next()); Assert.IsNull(rw.next()); }
public virtual void WorkingDirectoryContentConflict() { WriteTrashFile(PATH, "content2"); RevCommit stashed = git.StashCreate().Call(); NUnit.Framework.Assert.IsNotNull(stashed); NUnit.Framework.Assert.AreEqual("content", Read(committedFile)); NUnit.Framework.Assert.IsTrue(git.Status().Call().IsClean()); WriteTrashFile(PATH, "content3"); try { git.StashApply().Call(); NUnit.Framework.Assert.Fail("Exception not thrown"); } catch (JGitInternalException e) { NUnit.Framework.Assert.IsTrue(e.InnerException is NGit.Errors.CheckoutConflictException ); } }
public void testCrissCross() { // See http://marc.info/?l=git&m=111463358500362&w=2 for a nice // description of what this test is creating. We don't have a // clean merge base for d,e as they each merged the parents b,c // in different orders. // RevCommit a = Commit(); RevCommit b = Commit(a); RevCommit c = Commit(a); RevCommit d = Commit(b, c); RevCommit e = Commit(c, b); rw.setRevFilter(RevFilter.MERGE_BASE); MarkStart(d); MarkStart(e); AssertCommit(c, rw.next()); AssertCommit(b, rw.next()); Assert.IsNull(rw.next()); }
/// <summary> /// Create a new sorter and completely spin the generator. /// <para /> /// When the constructor completes the supplied generator will have no /// commits remaining, as all of the commits will be held inside of this /// generator's internal buffer. /// </summary> /// <param name="s"> /// Generator to pull all commits out of, and into this buffer. /// </param> public TopoSortGenerator(Generator s) { _pending = new FIFORevQueue(); _outputType = s.OutputType | GeneratorOutputType.SortTopo; s.shareFreeList(_pending); while (true) { RevCommit c = s.next(); if (c == null) { break; } foreach (RevCommit p in c.Parents) { p.InDegree++; } _pending.add(c); } }
private bool WantSatisfied(RevCommit want) { _walk.resetRetain(SAVE); _walk.markStart(want); while (true) { RevCommit c = _walk.next(); if (c == null) { break; } if (c.has(PEER_HAS)) { AddCommonBase(c); return(true); } } return(false); }
public virtual void TestConflicting() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); // create side branch with two modifications CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); WriteTrashFile("a", "1\na(side)\n3\n"); WriteTrashFile("b", "1\nb\n3\n(side)"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); // update a on master to generate conflict CheckoutBranch("refs/heads/master"); WriteTrashFile("a", "1\na(main)\n3\n"); git.Add().AddFilepattern("a").Call(); git.Commit().SetMessage("main").Call(); // merge side with master MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus()); FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); diff.Diff(); NUnit.Framework.CollectionAssert.AreEqual("[b]", new TreeSet <string>(diff.GetChanged()).ToString ()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetAdded()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetRemoved()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetMissing()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetModified()); NUnit.Framework.Assert.AreEqual("a", diff.GetConflicting().First()); NUnit.Framework.Assert.AreEqual(1, diff.GetConflicting().Count()); NUnit.Framework.CollectionAssert.IsEmpty(diff.GetUntrackedFolders()); }
/// <exception cref="NGit.Errors.MissingObjectException"></exception> /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception> /// <exception cref="System.IO.IOException"></exception> /// <exception cref="NGit.Api.Errors.GitAPIException"></exception> private void Checkout(Repository clonedRepo, FetchResult result) { Ref head = result.GetAdvertisedRef(branch); if (branch.Equals(Constants.HEAD)) { Ref foundBranch = FindBranchToCheckout(result); if (foundBranch != null) { head = foundBranch; } } if (head == null || head.GetObjectId() == null) { return; } // throw exception? if (head.GetName().StartsWith(Constants.R_HEADS)) { RefUpdate newHead = clonedRepo.UpdateRef(Constants.HEAD); newHead.DisableRefLog(); newHead.Link(head.GetName()); AddMergeConfig(clonedRepo, head); } RevCommit commit = ParseCommit(clonedRepo, head); bool detached = !head.GetName().StartsWith(Constants.R_HEADS); RefUpdate u = clonedRepo.UpdateRef(Constants.HEAD, detached); u.SetNewObjectId(commit.Id); u.ForceUpdate(); if (!bare) { DirCache dc = clonedRepo.LockDirCache(); DirCacheCheckout co = new DirCacheCheckout(clonedRepo, dc, commit.Tree); co.Checkout(); if (cloneSubmodules) { CloneSubmodules(clonedRepo); } } }
public virtual void WorkingDirectoryModifyInSubfolder() { string path = "d1/d2/f.txt"; FilePath subfolderFile = WriteTrashFile(path, "content"); git.Add().AddFilepattern(path).Call(); head = git.Commit().SetMessage("add file").Call(); WriteTrashFile(path, "content2"); RevCommit stashed = Git.Wrap(db).StashCreate().Call(); NUnit.Framework.Assert.IsNotNull(stashed); NUnit.Framework.Assert.AreEqual("content", Read(subfolderFile)); ValidateStashedCommit(stashed); NUnit.Framework.Assert.AreEqual(head.Tree, stashed.GetParent(1).Tree); IList <DiffEntry> diffs = DiffWorkingAgainstHead(stashed); NUnit.Framework.Assert.AreEqual(1, diffs.Count); NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, diffs[0].GetChangeType ()); NUnit.Framework.Assert.AreEqual(path, diffs[0].GetNewPath()); }
static int SetBlameLines(NGit.Repository repo, RevCommit[] lines, RevCommit commit, RawText curText, RawText ancestorText) { int lineCount = 0; IEnumerable <Hunk> diffHunks = GetDiffHunks(curText, ancestorText); foreach (Hunk e in diffHunks) { int basePosition = e.InsertStart - 1; for (int i = 0; i < e.Inserted; i++) { int lineNum = basePosition + i; if (lines [lineNum] == null) { lines [lineNum] = commit; lineCount++; } } } return(lineCount); }
public void testSort_COMMIT_TIME_DESC_OutOfOrder1() { // Despite being out of order time-wise, a strand-of-pearls must // still maintain topological order. // RevCommit a = Commit(); RevCommit b = Commit(a); RevCommit c = Commit(-5, b); RevCommit d = Commit(10, c); Assert.IsTrue(parseBody(a).CommitTime < parseBody(d).CommitTime); Assert.IsTrue(parseBody(c).CommitTime < parseBody(b).CommitTime); rw.sort(RevSort.COMMIT_TIME_DESC); MarkStart(d); AssertCommit(d, rw.next()); AssertCommit(c, rw.next()); AssertCommit(b, rw.next()); AssertCommit(a, rw.next()); Assert.IsNull(rw.next()); }
public virtual void TestSingleRevision() { Git git = new Git(db); string[] content = new string[] { "first", "second", "third" }; WriteTrashFile("file.txt", Join(content)); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit = git.Commit().SetMessage("create file").Call(); BlameCommand command = new BlameCommand(db); command.SetFilePath("file.txt"); BlameResult lines = command.Call(); NUnit.Framework.Assert.IsNotNull(lines); NUnit.Framework.Assert.AreEqual(3, lines.GetResultContents().Size()); for (int i = 0; i < 3; i++) { NUnit.Framework.Assert.AreEqual(commit, lines.GetSourceCommit(i)); NUnit.Framework.Assert.AreEqual(i, lines.GetSourceLine(i)); } }
/// <exception cref="System.IO.IOException"></exception> private RebaseResult Stop(RevCommit commitToPick) { PersonIdent author = commitToPick.GetAuthorIdent(); string authorScript = ToAuthorScript(author); CreateFile(rebaseDir, AUTHOR_SCRIPT, authorScript); CreateFile(rebaseDir, MESSAGE, commitToPick.GetFullMessage()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DiffFormatter df = new DiffFormatter(bos); df.SetRepository(repo); df.Format(commitToPick.GetParent(0), commitToPick); CreateFile(rebaseDir, PATCH, Sharpen.Runtime.GetStringForBytes(bos.ToByteArray(), Constants.CHARACTER_ENCODING)); CreateFile(rebaseDir, STOPPED_SHA, repo.NewObjectReader().Abbreviate(commitToPick ).Name); // Remove cherry pick state file created by CherryPickCommand, it's not // needed for rebase repo.WriteCherryPickHead(null); return(new RebaseResult(commitToPick)); }
private void ResetIndexForPaths(RevCommit commit) { DirCache dc = null; try { dc = repo.LockDirCache(); DirCacheBuilder builder = dc.Builder(); TreeWalk tw = new TreeWalk(repo); tw.AddTree(new DirCacheBuildIterator(builder)); tw.AddTree(commit.Tree); tw.Filter = PathFilterGroup.CreateFromStrings(filepaths); tw.Recursive = true; while (tw.Next()) { CanonicalTreeParser tree = tw.GetTree <CanonicalTreeParser>(1); // only keep file in index if it's in the commit if (tree != null) { // revert index to commit DirCacheEntry entry = new DirCacheEntry(tw.RawPath); entry.FileMode = tree.EntryFileMode; entry.SetObjectId(tree.EntryObjectId); builder.Add(entry); } } builder.Commit(); } catch (IOException e) { throw new RuntimeException(e); } finally { if (dc != null) { dc.Unlock(); } } }
/// <exception cref="System.IO.IOException"></exception> private void UpdateHead(string headName, RevCommit newHead) { // point the previous head (if any) to the new commit if (headName.StartsWith(Constants.R_REFS)) { RefUpdate rup = repo.UpdateRef(headName); rup.SetNewObjectId(newHead); RefUpdate.Result res = rup.ForceUpdate(); switch (res) { case RefUpdate.Result.FAST_FORWARD: case RefUpdate.Result.FORCED: case RefUpdate.Result.NO_CHANGE: { break; } default: { throw new JGitInternalException("Updating HEAD failed"); } } rup = repo.UpdateRef(Constants.HEAD); res = rup.Link(headName); switch (res) { case RefUpdate.Result.FAST_FORWARD: case RefUpdate.Result.FORCED: case RefUpdate.Result.NO_CHANGE: { break; } default: { throw new JGitInternalException("Updating HEAD failed"); } } } }
public virtual void TestDeletionAndConflict() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); WriteTrashFile("d", "1\nd\n3\n"); WriteTrashFile("c/c/c", "1\nc\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").AddFilepattern("c/c/c").AddFilepattern ("d").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "b").Delete()); WriteTrashFile("a", "1\na\n3(side)\n"); git.Add().AddFilepattern("b").SetUpdate(true).Call(); git.Add().AddFilepattern("a").SetUpdate(true).Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists()); CheckoutBranch("refs/heads/master"); NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "b").Exists()); WriteTrashFile("a", "1\na\n3(main)\n"); WriteTrashFile("c/c/c", "1\nc(main)\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("c/c/c").Call(); git.Commit().SetMessage("main").Call(); // We are merging a deletion into our branch MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus()); NUnit.Framework.Assert.AreEqual("1\na\n<<<<<<< HEAD\n3(main)\n=======\n3(side)\n>>>>>>> 54ffed45d62d252715fc20e41da92d44c48fb0ff\n" , Read(new FilePath(db.WorkTree, "a"))); NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists()); NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree, "c/c/c"))); NUnit.Framework.Assert.AreEqual("1\nd\n3\n", Read(new FilePath(db.WorkTree, "d")) ); }
public virtual void Test009_CreateCommitOldFormat() { ObjectId treeId = InsertTree(new TreeFormatter()); NGit.CommitBuilder c = new NGit.CommitBuilder(); c.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c.Message = "A Commit\n"; c.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c.TreeId); ObjectId actid = InsertCommit(c); ObjectId cmtid = ObjectId.FromString("9208b2459ea6609a5af68627cc031796d0d9329b"); NUnit.Framework.Assert.AreEqual(cmtid, actid); // Verify the commit we just wrote is in the correct format. ObjectDatabase odb = ((ObjectDirectory)db.ObjectDatabase); NUnit.Framework.Assert.IsTrue(odb is ObjectDirectory, "is ObjectDirectory"); XInputStream xis = new XInputStream(new FileInputStream(((ObjectDirectory)odb).FileFor (cmtid))); try { NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x78)), xis.ReadUInt8()); NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x9c)), xis.ReadUInt8()); NUnit.Framework.Assert.IsTrue(unchecked ((int)(0x789c)) % 31 == 0); } finally { xis.Close(); } // Verify we can read it. RevCommit c2 = ParseCommit(actid); NUnit.Framework.Assert.IsNotNull(c2); NUnit.Framework.Assert.AreEqual(c.Message, c2.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c.TreeId, c2.Tree); NUnit.Framework.Assert.AreEqual(c.Author, c2.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(c.Committer, c2.GetCommitterIdent()); }
public virtual void TestContentMerge() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); WriteTrashFile("c/c/c", "1\nc\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").AddFilepattern("c/c/c").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); WriteTrashFile("a", "1\na(side)\n3\n"); WriteTrashFile("b", "1\nb(side)\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree, "b"))); CheckoutBranch("refs/heads/master"); NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b")) ); WriteTrashFile("a", "1\na(main)\n3\n"); WriteTrashFile("c/c/c", "1\nc(main)\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("c/c/c").Call(); git.Commit().SetMessage("main").Call(); MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus()); NUnit.Framework.Assert.AreEqual("1\n<<<<<<< HEAD\na(main)\n=======\na(side)\n>>>>>>> 86503e7e397465588cc267b65d778538bffccb83\n3\n" , Read(new FilePath(db.WorkTree, "a"))); NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree, "b"))); NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree, "c/c/c"))); NUnit.Framework.Assert.AreEqual(1, result.GetConflicts().Count); NUnit.Framework.Assert.AreEqual(3, result.GetConflicts().Get("a")[0].Length); NUnit.Framework.Assert.AreEqual(RepositoryState.MERGING, db.GetRepositoryState()); }
public static void HardReset(NGit.Repository repo, ObjectId newHead) { DirCache dc = null; try { // Reset head to upstream RefUpdate ru = repo.UpdateRef(Constants.HEAD); ru.SetNewObjectId(newHead); ru.SetForceUpdate(true); RefUpdate.Result rc = ru.Update(); switch (rc) { case RefUpdate.Result.NO_CHANGE: case RefUpdate.Result.NEW: case RefUpdate.Result.FAST_FORWARD: case RefUpdate.Result.FORCED: break; case RefUpdate.Result.REJECTED: case RefUpdate.Result.LOCK_FAILURE: throw new ConcurrentRefUpdateException(JGitText.Get().couldNotLockHEAD, ru.GetRef(), rc); default: throw new JGitInternalException("Reference update failed: " + rc); } dc = repo.LockDirCache(); RevWalk rw = new RevWalk(repo); RevCommit c = rw.ParseCommit(newHead); DirCacheCheckout checkout = new DirCacheCheckout(repo, null, dc, c.Tree); checkout.Checkout(); } catch { if (dc != null) { dc.Unlock(); } throw; } }
public virtual void TestEditFanout2_38() { RevBlob a = tr.Blob("a"); RevBlob b = tr.Blob("b"); RevBlob data1 = tr.Blob("data1"); RevBlob data2 = tr.Blob("data2"); RevCommit r = tr.Commit().Add(Fanout(2, a.Name), data1).Add(Fanout(2, b.Name), data2 ).Add(".gitignore", string.Empty).Add("zoo-animals.txt", b).Create(); // // // // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); map.Set(a, data2); map.Set(b, null); map.Set(data1, b); map.Set(data2, null); NUnit.Framework.Assert.AreEqual(data2, map.Get(a)); NUnit.Framework.Assert.AreEqual(b, map.Get(data1)); NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b"); NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2"); RevCommit n = CommitNoteMap(map); map.Set(a, null); map.Set(data1, null); NUnit.Framework.Assert.IsFalse(map.Contains(a), "no a"); NUnit.Framework.Assert.IsFalse(map.Contains(data1), "no data1"); map = NoteMap.Read(reader, n); NUnit.Framework.Assert.AreEqual(data2, map.Get(a)); NUnit.Framework.Assert.AreEqual(b, map.Get(data1)); NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b"); NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2"); NUnit.Framework.Assert.AreEqual(b, TreeWalk.ForPath(reader, "zoo-animals.txt", n. Tree).GetObjectId(0)); }
public virtual void TestReadFlatTwoNotes() { RevBlob a = tr.Blob("a"); RevBlob b = tr.Blob("b"); RevBlob data1 = tr.Blob("data1"); RevBlob data2 = tr.Blob("data2"); RevCommit r = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Create(); // // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); NUnit.Framework.Assert.IsNotNull(map, "have map"); NUnit.Framework.Assert.IsTrue(map.Contains(a), "has note for a"); NUnit.Framework.Assert.IsTrue(map.Contains(b), "has note for b"); NUnit.Framework.Assert.AreEqual(data1, map.Get(a)); NUnit.Framework.Assert.AreEqual(data2, map.Get(b)); NUnit.Framework.Assert.IsFalse(map.Contains(data1), "no note for data1"); NUnit.Framework.Assert.IsNull(map.Get(data1), "no note for data1"); }
public virtual void TestEditAllLines() { Git git = new Git(db); string[] content1 = new string[] { "a", "1" }; string[] content2 = new string[] { "b", "2" }; WriteTrashFile("file.txt", Join(content1)); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("edit file").Call(); WriteTrashFile("file.txt", Join(content2)); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit2 = git.Commit().SetMessage("create file").Call(); BlameCommand command = new BlameCommand(db); command.SetFilePath("file.txt"); BlameResult lines = command.Call(); NUnit.Framework.Assert.AreEqual(content2.Length, lines.GetResultContents().Size() ); NUnit.Framework.Assert.AreEqual(commit2, lines.GetSourceCommit(0)); NUnit.Framework.Assert.AreEqual(commit2, lines.GetSourceCommit(1)); }
public void unpop(RevCommit c) { _commits[--HeadIndex] = c; }
public override bool include(RevWalk walker, RevCommit c) { return true; }
public override bool include(RevWalk walker, RevCommit cmit) { return cmit.ParentCount < 2; }
public override bool include(RevWalk walker, RevCommit c) { return a.include(walker, c) && b.include(walker, c); }
public override bool include(RevWalk walker, RevCommit cmit) { return cmit.CommitTime <= _until && cmit.CommitTime >= _when; }
private RevCommit[] cleanup(RevCommit[] oldList) { // Remove any duplicate parents caused due to rewrites (e.g. a merge // with two sides that both simplified back into the merge base). // We also may have deleted a parent by marking it null. // int newCnt = 0; for (int o = 0; o < oldList.Length; o++) { RevCommit p = oldList[o]; if (p == null) continue; if ((p.flags & DUPLICATE) != 0) { oldList[o] = null; continue; } p.flags |= DUPLICATE; newCnt++; } if (newCnt == oldList.Length) { foreach (RevCommit p in oldList) p.flags &= ~DUPLICATE; return oldList; } RevCommit[] newList = new RevCommit[newCnt]; newCnt = 0; foreach (RevCommit p in oldList) { if (p != null) { newList[newCnt++] = p; p.flags &= ~DUPLICATE; } } return newList; }
/** * Obtain the raw text to match against. * * @param cmit * current commit being evaluated. * @return sequence for the commit's content that we need to match on. */ internal abstract string text(RevCommit cmit);
public void add(RevCommit c) { _commits[TailIndex++] = c; }
public void add(RevCommit c) { commits[tailIndex++] = c; }
/** * Determine if the supplied commit should be included in results. * * @param walker * the active walker this filter is being invoked from within. * @param cmit * the commit currently being tested. The commit has been parsed * and its body is available for inspection. * @return true to include this commit in the results; false to have this * commit be omitted entirely from the results. * @throws StopWalkException * the filter knows for certain that no additional commits can * ever match, and the current commit doesn't match either. The * walk is halted and no more results are provided. * @throws MissingObjectException * an object the filter needs to consult to determine its answer * does not exist in the Git repository the walker is operating * on. Filtering this commit is impossible without the object. * @throws IncorrectObjectTypeException * an object the filter needed to consult was not of the * expected object type. This usually indicates a corrupt * repository, as an object link is referencing the wrong type. * @ * a loose object or pack file could not be read to obtain data * necessary for the filter to make its decision. */ public abstract bool include(RevWalk walker, RevCommit cmit);
public override bool include(RevWalk walker, RevCommit c) { throw new InvalidOperationException("Cannot be combined."); }
public void unpop(RevCommit c) { commits[--headIndex] = c; }
public override bool include(RevWalk walker, RevCommit c) { return c.hasAny(flags); }
public override bool include(RevWalk walker, RevCommit cmit) { return false; }
internal override string text(RevCommit cmit) { return textFor(cmit).ToString(); }
public override bool include(RevWalk walker, RevCommit cmit) { // Since the walker sorts commits by commit time we can be // reasonably certain there is nothing remaining worth our // scanning if this commit is before the point in question. // if (cmit.CommitTime < _when) { throw StopWalkException.INSTANCE; } return true; }
public override bool include(RevWalk walker, RevCommit cmit) { return _compiledPattern.IsMatch(text(cmit)); }
static RawCharSequence textFor(RevCommit cmit) { byte[] raw = cmit.getRawBuffer(); int b = RawParseUtils.commitMessage(raw, 0); if (b < 0) return RawCharSequence.EMPTY; return new RawCharSequence(raw, b, raw.Length); }
/// <summary> /// Obtain the raw text to match against. /// </summary> /// <param name="cmit">Current commit being evaluated.</param> /// <returns> /// Sequence for the commit's content that we need to match on. /// </returns> protected abstract string text(RevCommit cmit);
private RevCommit rewrite(RevCommit p) { for (; ; ) { RevCommit[] pList = p.parents; if (pList.Length > 1) { // This parent is a merge, so keep it. // return p; } if ((p.flags & RevWalk.UNINTERESTING) != 0) { // Retain uninteresting parents. They show where the // DAG was cut off because it wasn't interesting. // return p; } if ((p.flags & REWRITE) == 0) { // This parent was not eligible for rewriting. We // need to keep it in the DAG. // return p; } if (pList.Length == 0) { // We can't go back any further, other than to // just delete the parent entirely. // return null; } p = pList[0]; } }
internal override RawCharSequence text(RevCommit cmit) { return textFor(cmit); }
public override bool include(RevWalk walker, RevCommit cmit) { return _pattern.IsMatch(Text(cmit)); }
public override bool include(RevWalk walker, RevCommit cmit) { return cmit.hasAll(_flags); }
public override bool include(RevWalk walker, RevCommit c) { foreach (RevFilter f in subfilters) { if (!f.include(walker, c)) return false; } return true; }
public override bool include(RevWalk walker, RevCommit c) { return c.getParentCount() < 2; }
protected override string Text(RevCommit cmit) { return TextFor(cmit); }
public override bool include(RevWalk walker, RevCommit cmit) { return !_a.include(walker, cmit); }