/// <exception cref="System.IO.IOException"></exception> private void CommitNoteMap(RevWalk walk, NoteMap map, RevCommit notesCommit, ObjectInserter inserter, string msg) { // commit the note NGit.CommitBuilder builder = new NGit.CommitBuilder(); builder.TreeId = map.WriteTree(inserter); builder.Author = new PersonIdent(repo); builder.Committer = builder.Author; builder.Message = msg; if (notesCommit != null) { builder.SetParentIds(notesCommit); } ObjectId commit = inserter.Insert(builder); inserter.Flush(); RefUpdate refUpdate = repo.UpdateRef(notesRef); if (notesCommit != null) { refUpdate.SetExpectedOldObjectId(notesCommit); } else { refUpdate.SetExpectedOldObjectId(ObjectId.ZeroId); } refUpdate.SetNewObjectId(commit); refUpdate.Update(walk); }
public static ObjectId CreateCommit(NGit.Repository rep, string message, IList <ObjectId> parents, ObjectId indexTreeId, PersonIdent author, PersonIdent committer) { try { ObjectInserter odi = rep.NewObjectInserter(); try { // Create a Commit object, populate it and write it NGit.CommitBuilder commit = new NGit.CommitBuilder(); commit.Committer = committer; commit.Author = author; commit.Message = message; commit.SetParentIds(parents); commit.TreeId = indexTreeId; ObjectId commitId = odi.Insert(commit); odi.Flush(); return(commitId); } finally { odi.Release(); } } catch (UnmergedPathException) { // since UnmergedPathException is a subclass of IOException // which should not be wrapped by a JGitInternalException we // have to catch and re-throw it here throw; } catch (IOException e) { throw new JGitInternalException("Commit failed", e); } }
/// <exception cref="System.IO.IOException"></exception> private void Commit(string commitMsg, PersonIdent author, PersonIdent committer) { NGit.CommitBuilder commit = new NGit.CommitBuilder(); commit.Author = author; commit.Committer = committer; commit.Message = commitMsg; ObjectInserter inserter = db.NewObjectInserter(); ObjectId id; try { commit.TreeId = inserter.Insert(new TreeFormatter()); id = inserter.Insert(commit); inserter.Flush(); } finally { inserter.Release(); } int nl = commitMsg.IndexOf('\n'); RefUpdate ru = db.UpdateRef(Constants.HEAD); ru.SetNewObjectId(id); ru.SetRefLogMessage("commit : " + ((nl == -1) ? commitMsg : Sharpen.Runtime.Substring (commitMsg, 0, nl)), false); ru.ForceUpdate(); }
/// <exception cref="System.Exception"></exception> public virtual RevCommit Create() { if (this.self == null) { this._enclosing.Tick(this.tick); NGit.CommitBuilder c; c = new NGit.CommitBuilder(); c.SetParentIds(this.parents); this._enclosing.SetAuthorAndCommitter(c); c.Message = this.message; ObjectId commitId; try { c.TreeId = this.tree.WriteTree(this._enclosing.inserter); commitId = this._enclosing.inserter.Insert(c); this._enclosing.inserter.Flush(); } finally { this._enclosing.inserter.Release(); } this.self = this._enclosing.pool.LookupCommit(commitId); if (this.branch != null) { this.branch.Update(this.self); } } return(this.self); }
public virtual void Test023_createCommitNonAnullii() { ObjectId emptyId = InsertEmptyBlob(); Tree almostEmptyTree = new Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString ("empty"), false)); ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree); NGit.CommitBuilder commit = new NGit.CommitBuilder(); commit.TreeId = almostEmptyTreeId; commit.Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L , 60); commit.Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L , 60); commit.SetEncoding("UTF-8"); commit.Message = "\u00dcbergeeks"; ObjectId cid = InsertCommit(commit); NUnit.Framework.Assert.AreEqual("4680908112778718f37e686cbebcc912730b3154", cid.Name ); RevCommit loadedCommit = ParseCommit(cid); NUnit.Framework.Assert.AreEqual(commit.Message, loadedCommit.GetFullMessage()); }
public virtual void Test022_createCommitTag() { ObjectId emptyId = InsertEmptyBlob(); Tree almostEmptyTree = new Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString ("empty"), false)); ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree); NGit.CommitBuilder almostEmptyCommit = new NGit.CommitBuilder(); almostEmptyCommit.Author = new PersonIdent(author, 1154236443000L, -2 * 60); // not exactly the same almostEmptyCommit.Committer = new PersonIdent(author, 1154236443000L, -2 * 60); almostEmptyCommit.Message = "test022\n"; almostEmptyCommit.TreeId = almostEmptyTreeId; ObjectId almostEmptyCommitId = InsertCommit(almostEmptyCommit); TagBuilder t = new TagBuilder(); t.SetObjectId(almostEmptyCommitId, Constants.OBJ_COMMIT); t.SetTag("test022"); t.SetTagger(new PersonIdent(author, 1154236443000L, -4 * 60)); t.SetMessage("test022 tagged\n"); ObjectId actid = InsertTag(t); NUnit.Framework.Assert.AreEqual("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", actid .Name); RevTag mapTag = ParseTag(actid); NUnit.Framework.Assert.AreEqual(Constants.OBJ_COMMIT, mapTag.GetObject().Type); NUnit.Framework.Assert.AreEqual("test022 tagged\n", mapTag.GetFullMessage()); NUnit.Framework.Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.GetTaggerIdent()); NUnit.Framework.Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag .GetObject().Id.Name); }
/// <exception cref="System.IO.IOException"></exception> private RevCommit CommitNoteMap(NoteMap map) { tr.Tick(600); NGit.CommitBuilder builder = new NGit.CommitBuilder(); builder.TreeId = map.WriteTree(inserter); tr.SetAuthorAndCommitter(builder); return(tr.GetRevWalk().ParseCommit(inserter.Insert(builder))); }
/// <exception cref="System.Exception"></exception> private ObjectId Commit(ObjectInserter odi, DirCache treeB, ObjectId[] parentIds) { NGit.CommitBuilder c = new NGit.CommitBuilder(); c.TreeId = treeB.WriteTree(odi); c.Author = new PersonIdent("A U Thor", "a.u.thor", 1L, 0); c.Committer = c.Author; c.SetParentIds(parentIds); c.Message = "Tree " + c.TreeId.Name; ObjectId id = odi.Insert(c); odi.Flush(); return(id); }
private NGit.CommitBuilder CreateBuilder(ObjectId headId) { NGit.CommitBuilder builder = new NGit.CommitBuilder(); PersonIdent author = person; if (author == null) { author = new PersonIdent(repo); } builder.Author = author; builder.Committer = author; builder.SetParentId(headId); return(builder); }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="Sharpen.UnsupportedEncodingException"></exception> private ObjectId InsertCommit(NGit.CommitBuilder builder) { ObjectInserter oi = db.NewObjectInserter(); try { ObjectId id = oi.Insert(builder); oi.Flush(); return(id); } finally { oi.Release(); } }
public virtual void TestParse_PublicParseMethod() { ObjectInserter.Formatter fmt = new ObjectInserter.Formatter(); NGit.CommitBuilder src = new NGit.CommitBuilder(); src.TreeId = fmt.IdFor(Constants.OBJ_TREE, new byte[] { }); src.Author = author; src.Committer = committer; src.Message = "Test commit\n\nThis is a test.\n"; RevCommit p = RevCommit.Parse(src.Build()); NUnit.Framework.Assert.AreEqual(src.TreeId, p.Tree); NUnit.Framework.Assert.AreEqual(0, p.ParentCount); NUnit.Framework.Assert.AreEqual(author, p.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(committer, p.GetCommitterIdent()); NUnit.Framework.Assert.AreEqual("Test commit", p.GetShortMessage()); NUnit.Framework.Assert.AreEqual(src.Message, p.GetFullMessage()); }
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 Test024_createCommitNonAscii() { ObjectId emptyId = InsertEmptyBlob(); Tree almostEmptyTree = new Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString ("empty"), false)); ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree); NGit.CommitBuilder commit = new NGit.CommitBuilder(); commit.TreeId = almostEmptyTreeId; commit.Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L , 60); commit.Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L , 60); commit.SetEncoding("ISO-8859-1"); commit.Message = "\u00dcbergeeks"; ObjectId cid = InsertCommit(commit); NUnit.Framework.Assert.AreEqual("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.Name ); }
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 Test026_CreateCommitMultipleparents() { ObjectId treeId; ObjectInserter oi = db.NewObjectInserter(); try { ObjectId blobId = oi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString ("and this is the data in me\n", Constants.CHARSET.Name())); TreeFormatter fmt = new TreeFormatter(); fmt.Append("i-am-a-file", FileMode.REGULAR_FILE, blobId); treeId = oi.Insert(fmt); oi.Flush(); } finally { oi.Release(); } NUnit.Framework.Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936" ), treeId); NGit.CommitBuilder c1 = new NGit.CommitBuilder(); c1.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c1.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c1.Message = "A Commit\n"; c1.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c1.TreeId); ObjectId actid1 = InsertCommit(c1); ObjectId cmtid1 = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099"); NUnit.Framework.Assert.AreEqual(cmtid1, actid1); NGit.CommitBuilder c2 = new NGit.CommitBuilder(); c2.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c2.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c2.Message = "A Commit 2\n"; c2.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c2.TreeId); c2.SetParentIds(actid1); ObjectId actid2 = InsertCommit(c2); ObjectId cmtid2 = ObjectId.FromString("95d068687c91c5c044fb8c77c5154d5247901553"); NUnit.Framework.Assert.AreEqual(cmtid2, actid2); RevCommit rm2 = ParseCommit(cmtid2); NUnit.Framework.Assert.AreNotSame(c2, rm2); // assert the parsed objects is not from the // cache NUnit.Framework.Assert.AreEqual(c2.Author, rm2.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(actid2, rm2.Id); NUnit.Framework.Assert.AreEqual(c2.Message, rm2.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c2.TreeId, rm2.Tree.Id); NUnit.Framework.Assert.AreEqual(1, rm2.ParentCount); NUnit.Framework.Assert.AreEqual(actid1, rm2.GetParent(0)); NGit.CommitBuilder c3 = new NGit.CommitBuilder(); c3.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c3.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c3.Message = "A Commit 3\n"; c3.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c3.TreeId); c3.SetParentIds(actid1, actid2); ObjectId actid3 = InsertCommit(c3); ObjectId cmtid3 = ObjectId.FromString("ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4"); NUnit.Framework.Assert.AreEqual(cmtid3, actid3); RevCommit rm3 = ParseCommit(cmtid3); NUnit.Framework.Assert.AreNotSame(c3, rm3); // assert the parsed objects is not from the // cache NUnit.Framework.Assert.AreEqual(c3.Author, rm3.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(actid3, rm3.Id); NUnit.Framework.Assert.AreEqual(c3.Message, rm3.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c3.TreeId, rm3.Tree.Id); NUnit.Framework.Assert.AreEqual(2, rm3.ParentCount); NUnit.Framework.Assert.AreEqual(actid1, rm3.GetParent(0)); NUnit.Framework.Assert.AreEqual(actid2, rm3.GetParent(1)); NGit.CommitBuilder c4 = new NGit.CommitBuilder(); c4.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c4.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c4.Message = "A Commit 4\n"; c4.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c3.TreeId); c4.SetParentIds(actid1, actid2, actid3); ObjectId actid4 = InsertCommit(c4); ObjectId cmtid4 = ObjectId.FromString("d1fca9fe3fef54e5212eb67902c8ed3e79736e27"); NUnit.Framework.Assert.AreEqual(cmtid4, actid4); RevCommit rm4 = ParseCommit(cmtid4); NUnit.Framework.Assert.AreNotSame(c4, rm3); // assert the parsed objects is not from the // cache NUnit.Framework.Assert.AreEqual(c4.Author, rm4.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(actid4, rm4.Id); NUnit.Framework.Assert.AreEqual(c4.Message, rm4.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c4.TreeId, rm4.Tree.Id); NUnit.Framework.Assert.AreEqual(3, rm4.ParentCount); NUnit.Framework.Assert.AreEqual(actid1, rm4.GetParent(0)); NUnit.Framework.Assert.AreEqual(actid2, rm4.GetParent(1)); NUnit.Framework.Assert.AreEqual(actid3, rm4.GetParent(2)); }
/// <exception cref="System.Exception"></exception> public virtual RevCommit Create() { if (this.self == null) { this._enclosing.Tick(this.tick); NGit.CommitBuilder c; c = new NGit.CommitBuilder(); c.SetParentIds(this.parents); this._enclosing.SetAuthorAndCommitter(c); c.Message = this.message; ObjectId commitId; try { if (this.topLevelTree != null) { c.TreeId = this.topLevelTree; } else { c.TreeId = this.tree.WriteTree(this._enclosing.inserter); } commitId = this._enclosing.inserter.Insert(c); this._enclosing.inserter.Flush(); } finally { this._enclosing.inserter.Release(); } this.self = this._enclosing.pool.LookupCommit(commitId); if (this.branch != null) { this.branch.Update(this.self); } } return this.self; }
public static ObjectId CreateCommit (NGit.Repository rep, string message, IList<ObjectId> parents, ObjectId indexTreeId, PersonIdent author, PersonIdent committer) { try { ObjectInserter odi = rep.NewObjectInserter (); try { // Create a Commit object, populate it and write it NGit.CommitBuilder commit = new NGit.CommitBuilder (); commit.Committer = committer; commit.Author = author; commit.Message = message; commit.SetParentIds (parents); commit.TreeId = indexTreeId; ObjectId commitId = odi.Insert (commit); odi.Flush (); return commitId; } finally { odi.Release (); } } catch (UnmergedPathException) { // since UnmergedPathException is a subclass of IOException // which should not be wrapped by a JGitInternalException we // have to catch and re-throw it here throw; } catch (IOException e) { throw new JGitInternalException ("Commit failed", e); } }
/// <exception cref="System.Exception"></exception> private ObjectId Commit(ObjectInserter odi, DirCache treeB, ObjectId[] parentIds) { NGit.CommitBuilder c = new NGit.CommitBuilder(); c.TreeId = treeB.WriteTree(odi); c.Author = new PersonIdent("A U Thor", "a.u.thor", 1L, 0); c.Committer = c.Author; c.SetParentIds(parentIds); c.Message = "Tree " + c.TreeId.Name; ObjectId id = odi.Insert(c); odi.Flush(); return id; }
/// <summary> /// Executes the /// <code>commit</code> /// command with all the options and parameters /// collected by the setter methods of this class. Each instance of this /// class should only be used for one invocation of the command (means: one /// call to /// <see cref="Call()">Call()</see> /// ) /// </summary> /// <returns> /// a /// <see cref="NGit.Revwalk.RevCommit">NGit.Revwalk.RevCommit</see> /// object representing the successful commit. /// </returns> /// <exception cref="NGit.Api.Errors.NoHeadException">when called on a git repo without a HEAD reference /// </exception> /// <exception cref="NGit.Api.Errors.NoMessageException">when called without specifying a commit message /// </exception> /// <exception cref="NGit.Api.Errors.UnmergedPathsException">when the current index contained unmerged paths (conflicts) /// </exception> /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"> /// when HEAD or branch ref is updated concurrently by someone /// else /// </exception> /// <exception cref="NGit.Api.Errors.WrongRepositoryStateException">when repository is not in the right state for committing /// </exception> /// <exception cref="NGit.Api.Errors.GitAPIException"></exception> public override RevCommit Call() { CheckCallable(); RepositoryState state = repo.GetRepositoryState(); if (!state.CanCommit()) { throw new WrongRepositoryStateException(MessageFormat.Format(JGitText.Get().cannotCommitOnARepoWithState , state.Name())); } ProcessOptions(state); try { if (all && !repo.IsBare && repo.WorkTree != null) { Git git = new Git(repo); try { git.Add().AddFilepattern(".").SetUpdate(true).Call(); } catch (NoFilepatternException e) { // should really not happen throw new JGitInternalException(e.Message, e); } } Ref head = repo.GetRef(Constants.HEAD); if (head == null) { throw new NoHeadException(JGitText.Get().commitOnRepoWithoutHEADCurrentlyNotSupported ); } // determine the current HEAD and the commit it is referring to ObjectId headId = repo.Resolve(Constants.HEAD + "^{commit}"); if (headId == null && amend) { throw new WrongRepositoryStateException(JGitText.Get().commitAmendOnInitialNotPossible ); } if (headId != null) { if (amend) { RevCommit previousCommit = new RevWalk(repo).ParseCommit(headId); RevCommit[] p = previousCommit.Parents; for (int i = 0; i < p.Length; i++) { parents.Add(0, p[i].Id); } if (author == null) { author = previousCommit.GetAuthorIdent(); } } else { parents.Add(0, headId); } } // lock the index DirCache index = repo.LockDirCache(); try { if (!only.IsEmpty()) { index = CreateTemporaryIndex(headId, index); } ObjectInserter odi = repo.NewObjectInserter(); try { // Write the index as tree to the object database. This may // fail for example when the index contains unmerged paths // (unresolved conflicts) ObjectId indexTreeId = index.WriteTree(odi); if (insertChangeId) { InsertChangeId(indexTreeId); } // Create a Commit object, populate it and write it NGit.CommitBuilder commit = new NGit.CommitBuilder(); commit.Committer = committer; commit.Author = author; commit.Message = message; commit.SetParentIds(parents); commit.TreeId = indexTreeId; ObjectId commitId = odi.Insert(commit); odi.Flush(); RevWalk revWalk = new RevWalk(repo); try { RevCommit revCommit = revWalk.ParseCommit(commitId); RefUpdate ru = repo.UpdateRef(Constants.HEAD); ru.SetNewObjectId(commitId); if (reflogComment != null) { ru.SetRefLogMessage(reflogComment, false); } else { string prefix = amend ? "commit (amend): " : "commit: "; ru.SetRefLogMessage(prefix + revCommit.GetShortMessage(), false); } if (headId != null) { ru.SetExpectedOldObjectId(headId); } else { ru.SetExpectedOldObjectId(ObjectId.ZeroId); } RefUpdate.Result rc = ru.ForceUpdate(); switch (rc) { case RefUpdate.Result.NEW: case RefUpdate.Result.FORCED: case RefUpdate.Result.FAST_FORWARD: { SetCallable(false); if (state == RepositoryState.MERGING_RESOLVED) { // Commit was successful. Now delete the files // used for merge commits repo.WriteMergeCommitMsg(null); repo.WriteMergeHeads(null); } else { if (state == RepositoryState.CHERRY_PICKING_RESOLVED) { repo.WriteMergeCommitMsg(null); repo.WriteCherryPickHead(null); } } return(revCommit); } case RefUpdate.Result.REJECTED: case RefUpdate.Result.LOCK_FAILURE: { throw new ConcurrentRefUpdateException(JGitText.Get().couldNotLockHEAD, ru.GetRef (), rc); } default: { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().updatingRefFailed , Constants.HEAD, commitId.ToString(), rc)); } } } finally { revWalk.Release(); } } finally { odi.Release(); } } finally { index.Unlock(); } } catch (UnmergedPathException e) { throw new UnmergedPathsException(e); } catch (IOException e) { throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfCommitCommand , e); } }
/// <summary>Insert a single commit into the store, returning its unique name.</summary> /// <remarks>Insert a single commit into the store, returning its unique name.</remarks> /// <param name="builder">the builder containing the proposed commit's data.</param> /// <returns>the name of the commit object.</returns> /// <exception cref="System.IO.IOException">the object could not be stored.</exception> public ObjectId Insert(NGit.CommitBuilder builder) { return(Insert(Constants.OBJ_COMMIT, builder.Build())); }
/// <exception cref="System.IO.IOException"></exception> private RevCommit CommitNoteMap(NoteMap map) { tr.Tick(600); NGit.CommitBuilder builder = new NGit.CommitBuilder(); builder.TreeId = map.WriteTree(inserter); tr.SetAuthorAndCommitter(builder); return tr.GetRevWalk().ParseCommit(inserter.Insert(builder)); }
/// <summary> /// Stash the contents on the working directory and index in separate commits /// and reset to the current HEAD commit. /// </summary> /// <remarks> /// Stash the contents on the working directory and index in separate commits /// and reset to the current HEAD commit. /// </remarks> /// <returns>stashed commit or null if no changes to stash</returns> /// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException /// </exception> public override RevCommit Call() { CheckCallable(); Ref head = GetHead(); ObjectReader reader = repo.NewObjectReader(); try { RevCommit headCommit = ParseCommit(reader, head.GetObjectId()); DirCache cache = repo.LockDirCache(); ObjectInserter inserter = repo.NewObjectInserter(); ObjectId commitId; try { TreeWalk treeWalk = new TreeWalk(reader); treeWalk.Recursive = true; treeWalk.AddTree(headCommit.Tree); treeWalk.AddTree(new DirCacheIterator(cache)); treeWalk.AddTree(new FileTreeIterator(repo)); treeWalk.Filter = AndTreeFilter.Create(new SkipWorkTreeFilter(1), new IndexDiffFilter (1, 2)); // Return null if no local changes to stash if (!treeWalk.Next()) { return(null); } MutableObjectId id = new MutableObjectId(); IList <DirCacheEditor.PathEdit> wtEdits = new AList <DirCacheEditor.PathEdit>(); IList <string> wtDeletes = new AList <string>(); do { AbstractTreeIterator headIter = treeWalk.GetTree <AbstractTreeIterator>(0); DirCacheIterator indexIter = treeWalk.GetTree <DirCacheIterator>(1); WorkingTreeIterator wtIter = treeWalk.GetTree <WorkingTreeIterator>(2); if (headIter != null && indexIter != null && wtIter != null) { if (!indexIter.GetDirCacheEntry().IsMerged()) { throw new UnmergedPathsException(new UnmergedPathException(indexIter.GetDirCacheEntry ())); } if (wtIter.IdEqual(indexIter) || wtIter.IdEqual(headIter)) { continue; } treeWalk.GetObjectId(id, 0); DirCacheEntry entry = new DirCacheEntry(treeWalk.RawPath); entry.SetLength(wtIter.GetEntryLength()); entry.LastModified = wtIter.GetEntryLastModified(); entry.FileMode = wtIter.EntryFileMode; long contentLength = wtIter.GetEntryContentLength(); InputStream @in = wtIter.OpenEntryStream(); try { entry.SetObjectId(inserter.Insert(Constants.OBJ_BLOB, contentLength, @in)); } finally { @in.Close(); } wtEdits.AddItem(new _PathEdit_273(entry, entry)); } else { if (indexIter == null) { wtDeletes.AddItem(treeWalk.PathString); } else { if (wtIter == null && headIter != null) { wtDeletes.AddItem(treeWalk.PathString); } } } }while (treeWalk.Next()); string branch = Repository.ShortenRefName(head.GetTarget().GetName()); // Commit index changes NGit.CommitBuilder builder = CreateBuilder(headCommit); builder.TreeId = cache.WriteTree(inserter); builder.Message = MessageFormat.Format(indexMessage, branch, headCommit.Abbreviate (7).Name, headCommit.GetShortMessage()); ObjectId indexCommit = inserter.Insert(builder); // Commit working tree changes if (!wtEdits.IsEmpty() || !wtDeletes.IsEmpty()) { DirCacheEditor editor = cache.Editor(); foreach (DirCacheEditor.PathEdit edit in wtEdits) { editor.Add(edit); } foreach (string path in wtDeletes) { editor.Add(new DirCacheEditor.DeletePath(path)); } editor.Finish(); } builder.AddParentId(indexCommit); builder.Message = MessageFormat.Format(workingDirectoryMessage, branch, headCommit .Abbreviate(7).Name, headCommit.GetShortMessage()); builder.TreeId = cache.WriteTree(inserter); commitId = inserter.Insert(builder); inserter.Flush(); UpdateStashRef(commitId, builder.Author, builder.Message); } finally { inserter.Release(); cache.Unlock(); } // Hard reset to HEAD new ResetCommand(repo).SetMode(ResetCommand.ResetType.HARD).Call(); // Return stashed commit return(ParseCommit(reader, commitId)); } catch (IOException e) { throw new JGitInternalException(JGitText.Get().stashFailed, e); } finally { reader.Release(); } }