 
 deriving instance Show GitError
 
+
+
+retEither :: CInt -> IO (Either GitError a) -> IO (Either GitError a)
+retEither res f | res == 0  = f
+                | otherwise = return . Left . toEnum . fromIntegral $ res
+
+
+retMaybeRes :: CInt -> IO (Maybe GitError)
+retMaybeRes res | res == 0  = return Nothing
+                | otherwise = return $ Just . toEnum . fromIntegral $ res
+
+
 -------------------------------------------------------------------------------
 -- BEGIN: blob.h
 -------------------------------------------------------------------------------

  res  <- {#call git_repository_init#} pprepo pstr (fromBool isBare)
  retEither res $ fmap (Right . Repository) $ peek pprepo

retEither :: CInt -> IO (Either GitError a) -> IO (Either GitError a)
retEither res f | res == 0  = f
                | otherwise = return . Left . toEnum . fromIntegral $ res

isHeadDetached :: Repository -> IO Bool
isHeadDetached = repoIs {#call git_repository_head_detached#}


  res <- {#call git_commit_parent#} parent c (fromIntegral n)
  retEither res $ fmap (Right . Commit) $ peek parent

parentObjID :: Commit -> Int -> IO (Maybe ObjID)
parentObjID (Commit c) n = do
  res <- {#call git_commit_parent_oid#} c (fromIntegral n)
  if res == nullPtr
    then return Nothing
    else return . Just . ObjID $ res

{-
/**
 * Create a new commit in the repository using `git_object`
 * instances as parameters.
