{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

Reprensents a git reference.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Ggit.Objects.Ref
    (

-- * Exported types
    Ref(..)                                 ,
    IsRef                                   ,
    toRef                                   ,
    noRef                                   ,


 -- * Methods
-- ** delete #method:delete#

#if ENABLE_OVERLOADING
    RefDeleteMethodInfo                     ,
#endif
    refDelete                               ,


-- ** deleteLog #method:deleteLog#

#if ENABLE_OVERLOADING
    RefDeleteLogMethodInfo                  ,
#endif
    refDeleteLog                            ,


-- ** getLog #method:getLog#

#if ENABLE_OVERLOADING
    RefGetLogMethodInfo                     ,
#endif
    refGetLog                               ,


-- ** getName #method:getName#

#if ENABLE_OVERLOADING
    RefGetNameMethodInfo                    ,
#endif
    refGetName                              ,


-- ** getOwner #method:getOwner#

#if ENABLE_OVERLOADING
    RefGetOwnerMethodInfo                   ,
#endif
    refGetOwner                             ,


-- ** getReferenceType #method:getReferenceType#

#if ENABLE_OVERLOADING
    RefGetReferenceTypeMethodInfo           ,
#endif
    refGetReferenceType                     ,


-- ** getShorthand #method:getShorthand#

#if ENABLE_OVERLOADING
    RefGetShorthandMethodInfo               ,
#endif
    refGetShorthand                         ,


-- ** getSymbolicTarget #method:getSymbolicTarget#

#if ENABLE_OVERLOADING
    RefGetSymbolicTargetMethodInfo          ,
#endif
    refGetSymbolicTarget                    ,


-- ** getTarget #method:getTarget#

#if ENABLE_OVERLOADING
    RefGetTargetMethodInfo                  ,
#endif
    refGetTarget                            ,


-- ** hasLog #method:hasLog#

#if ENABLE_OVERLOADING
    RefHasLogMethodInfo                     ,
#endif
    refHasLog                               ,


-- ** isBranch #method:isBranch#

#if ENABLE_OVERLOADING
    RefIsBranchMethodInfo                   ,
#endif
    refIsBranch                             ,


-- ** isNote #method:isNote#

#if ENABLE_OVERLOADING
    RefIsNoteMethodInfo                     ,
#endif
    refIsNote                               ,


-- ** isRemote #method:isRemote#

#if ENABLE_OVERLOADING
    RefIsRemoteMethodInfo                   ,
#endif
    refIsRemote                             ,


-- ** isTag #method:isTag#

#if ENABLE_OVERLOADING
    RefIsTagMethodInfo                      ,
#endif
    refIsTag                                ,


-- ** isValidName #method:isValidName#

    refIsValidName                          ,


-- ** lookup #method:lookup#

#if ENABLE_OVERLOADING
    RefLookupMethodInfo                     ,
#endif
    refLookup                               ,


-- ** rename #method:rename#

#if ENABLE_OVERLOADING
    RefRenameMethodInfo                     ,
#endif
    refRename                               ,


-- ** resolve #method:resolve#

#if ENABLE_OVERLOADING
    RefResolveMethodInfo                    ,
#endif
    refResolve                              ,


-- ** setSymbolicTarget #method:setSymbolicTarget#

#if ENABLE_OVERLOADING
    RefSetSymbolicTargetMethodInfo          ,
#endif
    refSetSymbolicTarget                    ,


-- ** setTarget #method:setTarget#

#if ENABLE_OVERLOADING
    RefSetTargetMethodInfo                  ,
#endif
    refSetTarget                            ,


-- ** toString #method:toString#

#if ENABLE_OVERLOADING
    RefToStringMethodInfo                   ,
#endif
    refToString                             ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Ggit.Enums as Ggit.Enums
import {-# SOURCE #-} qualified GI.Ggit.Objects.Native as Ggit.Native
import {-# SOURCE #-} qualified GI.Ggit.Objects.Object as Ggit.Object
import {-# SOURCE #-} qualified GI.Ggit.Objects.ObjectFactoryBase as Ggit.ObjectFactoryBase
import {-# SOURCE #-} qualified GI.Ggit.Objects.Repository as Ggit.Repository
import {-# SOURCE #-} qualified GI.Ggit.Structs.OId as Ggit.OId
import {-# SOURCE #-} qualified GI.Ggit.Structs.Reflog as Ggit.Reflog

-- | Memory-managed wrapper type.
newtype Ref = Ref (ManagedPtr Ref)
foreign import ccall "ggit_ref_get_type"
    c_ggit_ref_get_type :: IO GType

instance GObject Ref where
    gobjectType = c_ggit_ref_get_type


-- | Type class for types which can be safely cast to `Ref`, for instance with `toRef`.
class (GObject o, O.IsDescendantOf Ref o) => IsRef o
instance (GObject o, O.IsDescendantOf Ref o) => IsRef o

instance O.HasParentTypes Ref
type instance O.ParentTypes Ref = '[Ggit.Native.Native, Ggit.ObjectFactoryBase.ObjectFactoryBase, GObject.Object.Object]

-- | Cast to `Ref`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toRef :: (MonadIO m, IsRef o) => o -> m Ref
toRef = liftIO . unsafeCastTo Ref

-- | A convenience alias for `Nothing` :: `Maybe` `Ref`.
noRef :: Maybe Ref
noRef = Nothing

#if ENABLE_OVERLOADING
type family ResolveRefMethod (t :: Symbol) (o :: *) :: * where
    ResolveRefMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveRefMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveRefMethod "delete" o = RefDeleteMethodInfo
    ResolveRefMethod "deleteLog" o = RefDeleteLogMethodInfo
    ResolveRefMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveRefMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveRefMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveRefMethod "hasLog" o = RefHasLogMethodInfo
    ResolveRefMethod "isBranch" o = RefIsBranchMethodInfo
    ResolveRefMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveRefMethod "isNote" o = RefIsNoteMethodInfo
    ResolveRefMethod "isRemote" o = RefIsRemoteMethodInfo
    ResolveRefMethod "isTag" o = RefIsTagMethodInfo
    ResolveRefMethod "lookup" o = RefLookupMethodInfo
    ResolveRefMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveRefMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveRefMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveRefMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveRefMethod "rename" o = RefRenameMethodInfo
    ResolveRefMethod "resolve" o = RefResolveMethodInfo
    ResolveRefMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveRefMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveRefMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveRefMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveRefMethod "toString" o = RefToStringMethodInfo
    ResolveRefMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveRefMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveRefMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveRefMethod "getLog" o = RefGetLogMethodInfo
    ResolveRefMethod "getName" o = RefGetNameMethodInfo
    ResolveRefMethod "getOwner" o = RefGetOwnerMethodInfo
    ResolveRefMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveRefMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveRefMethod "getReferenceType" o = RefGetReferenceTypeMethodInfo
    ResolveRefMethod "getShorthand" o = RefGetShorthandMethodInfo
    ResolveRefMethod "getSymbolicTarget" o = RefGetSymbolicTargetMethodInfo
    ResolveRefMethod "getTarget" o = RefGetTargetMethodInfo
    ResolveRefMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveRefMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveRefMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveRefMethod "setSymbolicTarget" o = RefSetSymbolicTargetMethodInfo
    ResolveRefMethod "setTarget" o = RefSetTargetMethodInfo
    ResolveRefMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveRefMethod t Ref, O.MethodInfo info Ref p) => OL.IsLabel t (Ref -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList Ref
type instance O.AttributeList Ref = RefAttributeList
type RefAttributeList = ('[ '("native", Ggit.Native.NativeNativePropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Ref = RefSignalList
type RefSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Ref::delete
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : True
-- Skip return : False

foreign import ccall "ggit_ref_delete" ggit_ref_delete ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    Ptr (Ptr GError) ->                     -- error
    IO ()

{- |
Deletes /@ref@/.

This method works for both direct and symbolic references.

The reference will be immediately removed on disk and from
memory. The given reference pointer will no longer be valid.
-}
refDelete ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
refDelete ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    onException (do
        propagateGError $ ggit_ref_delete ref'
        touchManagedPtr ref
        return ()
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data RefDeleteMethodInfo
instance (signature ~ (m ()), MonadIO m, IsRef a) => O.MethodInfo RefDeleteMethodInfo a signature where
    overloadedMethod _ = refDelete

#endif

-- method Ref::delete_log
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : True
-- Skip return : False

foreign import ccall "ggit_ref_delete_log" ggit_ref_delete_log ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    Ptr (Ptr GError) ->                     -- error
    IO ()

{- |
Deletes the log for /@ref@/, on error /@error@/ is set.
-}
refDeleteLog ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
refDeleteLog ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    onException (do
        propagateGError $ ggit_ref_delete_log ref'
        touchManagedPtr ref
        return ()
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data RefDeleteLogMethodInfo
instance (signature ~ (m ()), MonadIO m, IsRef a) => O.MethodInfo RefDeleteLogMethodInfo a signature where
    overloadedMethod _ = refDeleteLog

#endif

-- method Ref::get_log
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Reflog"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_ref_get_log" ggit_ref_get_log ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ggit.Reflog.Reflog)

{- |
Gets the 'GI.Ggit.Structs.Reflog.Reflog' for /@ref@/. The reflog will be created if it doesn\'t exist
yet.
-}
refGetLog ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m (Maybe Ggit.Reflog.Reflog)
    {- ^ __Returns:__ the reflog or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
refGetLog ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    onException (do
        result <- propagateGError $ ggit_ref_get_log ref'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapBoxed Ggit.Reflog.Reflog) result'
            return result''
        touchManagedPtr ref
        return maybeResult
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data RefGetLogMethodInfo
instance (signature ~ (m (Maybe Ggit.Reflog.Reflog)), MonadIO m, IsRef a) => O.MethodInfo RefGetLogMethodInfo a signature where
    overloadedMethod _ = refGetLog

#endif

-- method Ref::get_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_get_name" ggit_ref_get_name ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CString

{- |
Gets the full name of /@ref@/.
-}
refGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the full name of a reference or 'Nothing'. -}
refGetName ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_get_name ref'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr ref
    return maybeResult

#if ENABLE_OVERLOADING
data RefGetNameMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsRef a) => O.MethodInfo RefGetNameMethodInfo a signature where
    overloadedMethod _ = refGetName

#endif

-- method Ref::get_owner
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Repository"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_get_owner" ggit_ref_get_owner ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO (Ptr Ggit.Repository.Repository)

{- |
Gets the repository where /@ref@/ resides.
-}
refGetOwner ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m (Maybe Ggit.Repository.Repository)
    {- ^ __Returns:__ the repository where a reference resides or 'Nothing'. -}
refGetOwner ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_get_owner ref'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Ggit.Repository.Repository) result'
        return result''
    touchManagedPtr ref
    return maybeResult

#if ENABLE_OVERLOADING
data RefGetOwnerMethodInfo
instance (signature ~ (m (Maybe Ggit.Repository.Repository)), MonadIO m, IsRef a) => O.MethodInfo RefGetOwnerMethodInfo a signature where
    overloadedMethod _ = refGetOwner

#endif

-- method Ref::get_reference_type
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "RefType"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_get_reference_type" ggit_ref_get_reference_type ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CUInt

{- |
Gets the type of /@ref@/. Either direct (@/GGIT_REF_OID/@) or
symbolic (@/GGIT_REF_SYMBOLIC/@).
-}
refGetReferenceType ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m Ggit.Enums.RefType
    {- ^ __Returns:__ the type of a reference. -}
refGetReferenceType ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_get_reference_type ref'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr ref
    return result'

#if ENABLE_OVERLOADING
data RefGetReferenceTypeMethodInfo
instance (signature ~ (m Ggit.Enums.RefType), MonadIO m, IsRef a) => O.MethodInfo RefGetReferenceTypeMethodInfo a signature where
    overloadedMethod _ = refGetReferenceType

#endif

-- method Ref::get_shorthand
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_get_shorthand" ggit_ref_get_shorthand ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CString

{- |
Gets the shorthand name of /@ref@/.
-}
refGetShorthand ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref' -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the shorthand name of a reference or 'Nothing'. -}
refGetShorthand ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_get_shorthand ref'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr ref
    return maybeResult

#if ENABLE_OVERLOADING
data RefGetShorthandMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsRef a) => O.MethodInfo RefGetShorthandMethodInfo a signature where
    overloadedMethod _ = refGetShorthand

#endif

-- method Ref::get_symbolic_target
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_get_symbolic_target" ggit_ref_get_symbolic_target ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CString

{- |
Get full name to the reference pointed to by a symbolic reference.
Only available if the reference is symbolic.
-}
refGetSymbolicTarget ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the name if available, 'Nothing' otherwise. -}
refGetSymbolicTarget ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_get_symbolic_target ref'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr ref
    return maybeResult

#if ENABLE_OVERLOADING
data RefGetSymbolicTargetMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsRef a) => O.MethodInfo RefGetSymbolicTargetMethodInfo a signature where
    overloadedMethod _ = refGetSymbolicTarget

#endif

-- method Ref::get_target
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_get_target" ggit_ref_get_target ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO (Ptr Ggit.OId.OId)

{- |
Get the OID pointed to by a direct reference.
Only available if the reference is direct (i.e. an object id reference,
not a symbolic one).
-}
refGetTarget ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m (Maybe Ggit.OId.OId)
    {- ^ __Returns:__ a new oid if available, 'Nothing' otherwise. -}
refGetTarget ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_get_target ref'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Ggit.OId.OId) result'
        return result''
    touchManagedPtr ref
    return maybeResult

#if ENABLE_OVERLOADING
data RefGetTargetMethodInfo
instance (signature ~ (m (Maybe Ggit.OId.OId)), MonadIO m, IsRef a) => O.MethodInfo RefGetTargetMethodInfo a signature where
    overloadedMethod _ = refGetTarget

#endif

-- method Ref::has_log
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_has_log" ggit_ref_has_log ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CInt

{- |
Get whether /@ref@/ has an existing log.
-}
refHasLog ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@ref@/ has a log, 'False' otherwise. -}
refHasLog ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_has_log ref'
    let result' = (/= 0) result
    touchManagedPtr ref
    return result'

#if ENABLE_OVERLOADING
data RefHasLogMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsRef a) => O.MethodInfo RefHasLogMethodInfo a signature where
    overloadedMethod _ = refHasLog

#endif

-- method Ref::is_branch
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_is_branch" ggit_ref_is_branch ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CInt

{- |
Check whether the reference is a branch.
-}
refIsBranch ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the reference is a branch, 'False' otherwise. -}
refIsBranch ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_is_branch ref'
    let result' = (/= 0) result
    touchManagedPtr ref
    return result'

#if ENABLE_OVERLOADING
data RefIsBranchMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsRef a) => O.MethodInfo RefIsBranchMethodInfo a signature where
    overloadedMethod _ = refIsBranch

#endif

-- method Ref::is_note
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_is_note" ggit_ref_is_note ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CInt

{- |
Check whether the reference is a note.
-}
refIsNote ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the reference is a note, 'False' otherwise. -}
refIsNote ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_is_note ref'
    let result' = (/= 0) result
    touchManagedPtr ref
    return result'

#if ENABLE_OVERLOADING
data RefIsNoteMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsRef a) => O.MethodInfo RefIsNoteMethodInfo a signature where
    overloadedMethod _ = refIsNote

#endif

-- method Ref::is_remote
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_is_remote" ggit_ref_is_remote ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CInt

{- |
Check whether the reference is a remote.
-}
refIsRemote ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the reference is a remote, 'False' otherwise. -}
refIsRemote ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_is_remote ref'
    let result' = (/= 0) result
    touchManagedPtr ref
    return result'

#if ENABLE_OVERLOADING
data RefIsRemoteMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsRef a) => O.MethodInfo RefIsRemoteMethodInfo a signature where
    overloadedMethod _ = refIsRemote

#endif

-- method Ref::is_tag
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_is_tag" ggit_ref_is_tag ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CInt

{- |
Check whether the reference is a tag.
-}
refIsTag ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the reference is a tag, 'False' otherwise. -}
refIsTag ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_is_tag ref'
    let result' = (/= 0) result
    touchManagedPtr ref
    return result'

#if ENABLE_OVERLOADING
data RefIsTagMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsRef a) => O.MethodInfo RefIsTagMethodInfo a signature where
    overloadedMethod _ = refIsTag

#endif

-- method Ref::lookup
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Object"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_ref_lookup" ggit_ref_lookup ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ggit.Object.Object)

{- |
Convenient method to resolve a reference to an object.
-}
refLookup ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m (Maybe Ggit.Object.Object)
    {- ^ __Returns:__ a 'GI.Ggit.Objects.Object.Object' or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
refLookup ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    onException (do
        result <- propagateGError $ ggit_ref_lookup ref'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapObject Ggit.Object.Object) result'
            return result''
        touchManagedPtr ref
        return maybeResult
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data RefLookupMethodInfo
instance (signature ~ (m (Maybe Ggit.Object.Object)), MonadIO m, IsRef a) => O.MethodInfo RefLookupMethodInfo a signature where
    overloadedMethod _ = refLookup

#endif

-- method Ref::rename
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "new_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new name.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "force", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "%TRUE to force the renaming.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "log_message", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The one line long message to be appended to the reflog.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Ref"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_ref_rename" ggit_ref_rename ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    CString ->                              -- new_name : TBasicType TUTF8
    CInt ->                                 -- force : TBasicType TBoolean
    CString ->                              -- log_message : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ref)

{- |
Rename an existing reference.

This method works for both direct and symbolic references.

The new name will be checked for validity.
See @ggit_ref_create_symbolic()@ for rules about valid names.

If not error, /@ref@/ will be deleted from disk and a
new 'GI.Ggit.Objects.Ref.Ref' will be returned.

The reference will be immediately renamed in-memory and on disk.

If the @force@ flag is not enabled, and there\'s already
a reference with the given name, the renaming will fail.

IMPORTANT:
The user needs to write a proper reflog entry if the
reflog is enabled for the repository. We only rename
the reflog if it exists.
-}
refRename ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> T.Text
    {- ^ /@newName@/: the new name. -}
    -> Bool
    {- ^ /@force@/: 'True' to force the renaming. -}
    -> T.Text
    {- ^ /@logMessage@/: The one line long message to be appended to the reflog. -}
    -> m (Maybe Ref)
    {- ^ __Returns:__ a newly created 'GI.Ggit.Objects.Ref.Ref' or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
refRename ref newName force logMessage = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    newName' <- textToCString newName
    let force' = (fromIntegral . fromEnum) force
    logMessage' <- textToCString logMessage
    onException (do
        result <- propagateGError $ ggit_ref_rename ref' newName' force' logMessage'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapObject Ref) result'
            return result''
        touchManagedPtr ref
        freeMem newName'
        freeMem logMessage'
        return maybeResult
     ) (do
        freeMem newName'
        freeMem logMessage'
     )

#if ENABLE_OVERLOADING
data RefRenameMethodInfo
instance (signature ~ (T.Text -> Bool -> T.Text -> m (Maybe Ref)), MonadIO m, IsRef a) => O.MethodInfo RefRenameMethodInfo a signature where
    overloadedMethod _ = refRename

#endif

-- method Ref::resolve
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Ref"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_ref_resolve" ggit_ref_resolve ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ref)

{- |
Resolves a symbolic reference.

This method iteratively peels a symbolic reference
until it resolves to a direct reference to an OID.

If a direct reference is passed as an argument,
that reference is returned immediately.
-}
refResolve ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m (Maybe Ref)
    {- ^ __Returns:__ the resolved reference to the peeled one or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
refResolve ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    onException (do
        result <- propagateGError $ ggit_ref_resolve ref'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapObject Ref) result'
            return result''
        touchManagedPtr ref
        return maybeResult
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data RefResolveMethodInfo
instance (signature ~ (m (Maybe Ref)), MonadIO m, IsRef a) => O.MethodInfo RefResolveMethodInfo a signature where
    overloadedMethod _ = refResolve

#endif

-- method Ref::set_symbolic_target
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "target", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The new target for the reference.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "log_message", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The one line long message to be appended to the reflog.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Ref"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_ref_set_symbolic_target" ggit_ref_set_symbolic_target ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    CString ->                              -- target : TBasicType TUTF8
    CString ->                              -- log_message : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ref)

{- |
Create a new reference with the same name as the given reference but a
different symbolic target. The reference must be a symbolic reference,
otherwise this will fail.

The new reference will be written to disk, overwriting the given reference.

The target name will be checked for validity.
See @ggit_ref_create_symbolic()@ for rules about valid names.
-}
refSetSymbolicTarget ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> T.Text
    {- ^ /@target@/: The new target for the reference. -}
    -> T.Text
    {- ^ /@logMessage@/: The one line long message to be appended to the reflog. -}
    -> m (Maybe Ref)
    {- ^ __Returns:__ the newly created 'GI.Ggit.Objects.Ref.Ref' or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
refSetSymbolicTarget ref target logMessage = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    target' <- textToCString target
    logMessage' <- textToCString logMessage
    onException (do
        result <- propagateGError $ ggit_ref_set_symbolic_target ref' target' logMessage'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapObject Ref) result'
            return result''
        touchManagedPtr ref
        freeMem target'
        freeMem logMessage'
        return maybeResult
     ) (do
        freeMem target'
        freeMem logMessage'
     )

#if ENABLE_OVERLOADING
data RefSetSymbolicTargetMethodInfo
instance (signature ~ (T.Text -> T.Text -> m (Maybe Ref)), MonadIO m, IsRef a) => O.MethodInfo RefSetSymbolicTargetMethodInfo a signature where
    overloadedMethod _ = refSetSymbolicTarget

#endif

-- method Ref::set_target
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "log_message", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The one line long message to be appended to the reflog.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Ref"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_ref_set_target" ggit_ref_set_target ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    Ptr Ggit.OId.OId ->                     -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
    CString ->                              -- log_message : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ref)

{- |
Create a new reference with the same name as the given reference but a
different OID target. The reference must be a direct reference, otherwise
this will fail.

The new reference will be written to disk, overwriting the given reference.
-}
refSetTarget ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> Ggit.OId.OId
    {- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> T.Text
    {- ^ /@logMessage@/: The one line long message to be appended to the reflog. -}
    -> m (Maybe Ref)
    {- ^ __Returns:__ the newly created 'GI.Ggit.Objects.Ref.Ref' or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
refSetTarget ref oid logMessage = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    oid' <- unsafeManagedPtrGetPtr oid
    logMessage' <- textToCString logMessage
    onException (do
        result <- propagateGError $ ggit_ref_set_target ref' oid' logMessage'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapObject Ref) result'
            return result''
        touchManagedPtr ref
        touchManagedPtr oid
        freeMem logMessage'
        return maybeResult
     ) (do
        freeMem logMessage'
     )

#if ENABLE_OVERLOADING
data RefSetTargetMethodInfo
instance (signature ~ (Ggit.OId.OId -> T.Text -> m (Maybe Ref)), MonadIO m, IsRef a) => O.MethodInfo RefSetTargetMethodInfo a signature where
    overloadedMethod _ = refSetTarget

#endif

-- method Ref::to_string
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRef.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_to_string" ggit_ref_to_string ::
    Ptr Ref ->                              -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    IO CString

{- |
Get a string representation of the ref.
-}
refToString ::
    (B.CallStack.HasCallStack, MonadIO m, IsRef a) =>
    a
    {- ^ /@ref@/: a 'GI.Ggit.Objects.Ref.Ref'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ a string representation of the ref or 'Nothing'. -}
refToString ref = liftIO $ do
    ref' <- unsafeManagedPtrCastPtr ref
    result <- ggit_ref_to_string ref'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr ref
    return maybeResult

#if ENABLE_OVERLOADING
data RefToStringMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsRef a) => O.MethodInfo RefToStringMethodInfo a signature where
    overloadedMethod _ = refToString

#endif

-- method Ref::is_valid_name
-- method type : MemberFunction
-- Args : [Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name to validate.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_is_valid_name" ggit_ref_is_valid_name ::
    CString ->                              -- name : TBasicType TUTF8
    IO CInt

{- |
Check if the given /@name@/ is a valid name for a reference. Note that /@name@/
should be the full ref name (including prefixes).

Valid toplevel names can contain only capital letters and underscores
and must start and end with a letter (e.g. HEAD, ORIG_HEAD).

Valid refs\/ names may contain any characters, except \'~\', \'^\', \':\', \'\\\', \'?\',
\'[\', \'*\', \"..\" and \"\@{\", because they are interpreted by revparse.
-}
refIsValidName ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@name@/: the name to validate. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@name@/ is valid, 'False' otherwise. -}
refIsValidName name = liftIO $ do
    name' <- textToCString name
    result <- ggit_ref_is_valid_name name'
    let result' = (/= 0) result
    freeMem name'
    return result'

#if ENABLE_OVERLOADING
#endif