/** * Store a tag. * If author, message or type is set make the tag an annotated tag. * * @ */ public void Save() //renamed from Tag { if (TagId != null) { throw new InvalidOperationException("exists " + TagId); } ObjectId id; if (author != null || message != null || tagType != null) { ObjectId tagid = new ObjectWriter(Repository).WriteTag(this); TagId = tagid; id = tagid; } else { id = Id; } RefUpdate ru = Repository.UpdateRef(Constants.RefsTags + TagName); ru.NewObjectId = id; ru.SetRefLogMessage("tagged " + TagName, false); if (ru.ForceUpdate() == RefUpdate.RefUpdateResult.LockFailure) { throw new ObjectWritingException("Unable to lock tag " + TagName); } }
/// <summary> /// The result of the new ref update /// </summary> /// <returns></returns> /// <exception cref="IOException"></exception> public RefResult Rename() { Ref oldRef = _oldFromDelete.Repository.getRef(Constants.HEAD); bool renameHeadToo = oldRef != null && oldRef.Name == _oldFromDelete.Name; Repository db = _oldFromDelete.Repository; RefLogWriter.renameTo(db, _oldFromDelete, _newToUpdate); _newToUpdate.SetRefLogMessage(null, false); string tmpRefName = "RENAMED-REF.." + Thread.CurrentThread.ManagedThreadId; RefUpdate tmpUpdateRef = db.UpdateRef(tmpRefName); if (renameHeadToo) { try { _oldFromDelete.Repository.Link(Constants.HEAD, tmpRefName); } catch (IOException) { RefLogWriter.renameTo(db, _newToUpdate, _oldFromDelete); return(_renameResult = RefResult.LockFailure); } } tmpUpdateRef.NewObjectId = _oldFromDelete.OldObjectId; tmpUpdateRef.IsForceUpdate = true; RefResult update = tmpUpdateRef.Update(); if (update != RefResult.Forced && update != RefResult.New && update != RefResult.NoChange) { RefLogWriter.renameTo(db, _newToUpdate, _oldFromDelete); if (renameHeadToo) { _oldFromDelete.Repository.Link(Constants.HEAD, _oldFromDelete.Name); } return(_renameResult = update); } _oldFromDelete.ExpectedOldObjectId = _oldFromDelete.OldObjectId; _oldFromDelete.IsForceUpdate = true; RefResult delete = _oldFromDelete.Delete(); if (delete != RefResult.Forced) { if (db.getRef(_oldFromDelete.Name) != null) { RefLogWriter.renameTo(db, _newToUpdate, _oldFromDelete); if (renameHeadToo) { _oldFromDelete.Repository.Link(Constants.HEAD, _oldFromDelete.Name); } } return(_renameResult = delete); } _newToUpdate.NewObjectId = tmpUpdateRef.NewObjectId; RefResult updateResult = _newToUpdate.Update(); if (updateResult != RefResult.New) { RefLogWriter.renameTo(db, _newToUpdate, _oldFromDelete); if (renameHeadToo) { _oldFromDelete.Repository.Link(Constants.HEAD, _oldFromDelete.Name); } _oldFromDelete.ExpectedOldObjectId = null; _oldFromDelete.NewObjectId = _oldFromDelete.OldObjectId; _oldFromDelete.IsForceUpdate = true; _oldFromDelete.SetRefLogMessage(null, false); RefResult undelete = _oldFromDelete.Update(); if (undelete != RefResult.New && undelete != RefResult.LockFailure) { return(_renameResult = RefResult.IOFailure); } return(_renameResult = RefResult.LockFailure); } if (renameHeadToo) { _oldFromDelete.Repository.Link(Constants.HEAD, _newToUpdate.Name); } else { db.fireRefsMaybeChanged(); } RefLogWriter.append(this, _newToUpdate.Name, "Branch: renamed " + Repository.ShortenRefName(_oldFromDelete.Name) + " to " + Repository.ShortenRefName(_newToUpdate.Name)); if (renameHeadToo) { RefLogWriter.append(this, Constants.HEAD, "Branch: renamed " + Repository.ShortenRefName(_oldFromDelete.Name) + " to " + Repository.ShortenRefName(_newToUpdate.Name)); } return(_renameResult = RefResult.Renamed); }