コード例 #1
0
ファイル: TagCommandTest.cs プロジェクト: LunarLanding/ngit
		public virtual void TestTaggingOnHead()
		{
			Git git = new Git(db);
			RevCommit commit = git.Commit().SetMessage("initial commit").Call();
			Ref tagRef = git.Tag().SetName("tag").Call();
			NUnit.Framework.Assert.AreEqual(commit.Id, db.Peel(tagRef).GetPeeledObjectId());
			RevWalk walk = new RevWalk(db);
			NUnit.Framework.Assert.AreEqual("tag", walk.ParseTag(tagRef.GetObjectId()).GetTagName
				());
		}
コード例 #2
0
        public virtual void TestTaggingOnHead()
        {
            Git       git    = new Git(db);
            RevCommit commit = git.Commit().SetMessage("initial commit").Call();
            Ref       tagRef = git.Tag().SetName("tag").Call();

            NUnit.Framework.Assert.AreEqual(commit.Id, db.Peel(tagRef).GetPeeledObjectId());
            RevWalk walk = new RevWalk(db);

            NUnit.Framework.Assert.AreEqual("tag", walk.ParseTag(tagRef.GetObjectId()).GetTagName
                                                ());
        }
コード例 #3
0
ファイル: T0003_BasicTest.cs プロジェクト: shoff/ngit
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private RevTag ParseTag(AnyObjectId id)
        {
            RevWalk rw = new RevWalk(db);

            try
            {
                return(rw.ParseTag(id));
            }
            finally
            {
                rw.Release();
            }
        }
コード例 #4
0
ファイル: T0003_BasicTest.cs プロジェクト: JamesChan/ngit
 /// <exception cref="NGit.Errors.MissingObjectException"></exception>
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 private RevTag ParseTag(AnyObjectId id)
 {
     RevWalk rw = new RevWalk(db);
     try
     {
         return rw.ParseTag(id);
     }
     finally
     {
         rw.Release();
     }
 }
コード例 #5
0
ファイル: TagCommand.cs プロジェクト: shoff/ngit
        /// <summary>
        /// Executes the
        /// <code>tag</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.RevTag">NGit.Revwalk.RevTag</see>
        /// object representing the successful tag
        /// </returns>
        /// <exception cref="NGit.Api.Errors.NoHeadException">when called on a git repo without a HEAD reference
        ///     </exception>
        /// <exception cref="NGit.Api.Errors.JGitInternalException">
        /// a low-level exception of JGit has occurred. The original
        /// exception can be retrieved by calling
        /// <see cref="System.Exception.InnerException()">System.Exception.InnerException()</see>
        /// . Expect only
        /// <code>IOException's</code>
        /// to be wrapped.
        /// </exception>
        /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"></exception>
        /// <exception cref="NGit.Api.Errors.InvalidTagNameException"></exception>
        public override RevTag Call()
        {
            CheckCallable();
            RepositoryState state = repo.GetRepositoryState();

            ProcessOptions(state);
            try
            {
                // create the tag object
                TagBuilder newTag = new TagBuilder();
                newTag.SetTag(name);
                newTag.SetMessage(message);
                newTag.SetTagger(tagger);
                // if no id is set, we should attempt to use HEAD
                if (id == null)
                {
                    ObjectId objectId = repo.Resolve(Constants.HEAD + "^{commit}");
                    if (objectId == null)
                    {
                        throw new NoHeadException(JGitText.Get().tagOnRepoWithoutHEADCurrentlyNotSupported
                                                  );
                    }
                    newTag.SetObjectId(objectId, Constants.OBJ_COMMIT);
                }
                else
                {
                    newTag.SetObjectId(id);
                }
                // write the tag object
                ObjectInserter inserter = repo.NewObjectInserter();
                try
                {
                    ObjectId tagId = inserter.Insert(newTag);
                    inserter.Flush();
                    RevWalk revWalk = new RevWalk(repo);
                    try
                    {
                        RevTag    revTag  = revWalk.ParseTag(tagId);
                        string    refName = Constants.R_TAGS + newTag.GetTag();
                        RefUpdate tagRef  = repo.UpdateRef(refName);
                        tagRef.SetNewObjectId(tagId);
                        tagRef.SetForceUpdate(forceUpdate);
                        tagRef.SetRefLogMessage("tagged " + name, false);
                        RefUpdate.Result updateResult = tagRef.Update(revWalk);
                        switch (updateResult)
                        {
                        case RefUpdate.Result.NEW:
                        case RefUpdate.Result.FORCED:
                        {
                            return(revTag);
                        }

                        case RefUpdate.Result.LOCK_FAILURE:
                        {
                            throw new ConcurrentRefUpdateException(JGitText.Get().couldNotLockHEAD, tagRef.GetRef
                                                                       (), updateResult);
                        }

                        default:
                        {
                            throw new JGitInternalException(MessageFormat.Format(JGitText.Get().updatingRefFailed
                                                                                 , refName, newTag.ToString(), updateResult));
                        }
                        }
                    }
                    finally
                    {
                        revWalk.Release();
                    }
                }
                finally
                {
                    inserter.Release();
                }
            }
            catch (IOException e)
            {
                throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfTagCommand
                                                , e);
            }
        }