 init path isBare = alloca $ \pprepo -> do
   pstr <- newCString path
   res  <- {#call git_repository_init#} pprepo pstr (fromBool isBare)
-  if res == 0
-    then fmap (Right . Repository) $ peek pprepo
-    else return . Left . toEnum . fromIntegral $ res
+  retEither res $ fmap (Right . Repository) $ peek pprepo
+
+-- TODO: Add tysig
+retEither res f | res == 0  = f
+                | otherwise = return . Left . toEnum . fromIntegral $ res
 
 isHeadDetached :: Repository -> IO Bool
 isHeadDetached = repoIs {#call git_repository_head_detached#}

openRepo path = alloca $ \pprepo -> do
  pstr <- newCString path
  res  <- {#call git_repository_open#} pprepo pstr
  if res == 0
    then fmap (Right . Repository) $ peek pprepo
    else return . Left . toEnum . fromIntegral $ res

openRepoObjDir :: String -> String -> String -> String -> IO (Either GitError Repository)
openRepoObjDir dir objDir idxFile workTree = alloca $ \pprepo -> do

index :: Repository -> IO (Either GitError Index)
index (Repository r) = alloca $ \idx -> do
  res  <- {#call git_repository_index#} idx r
  retEither res $ fmap (Right . Index) $ peek idx

free :: Repository -> IO ()
free (Repository r) = {#call git_repository_free#} r
