ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

commit 8964e0f0e9734c676bd8419e9d8b304ef8986d20
parent c77cb8b9940f4c1bdc100e6f9eab180583ffce9d
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 16 Mar 2021 23:57:27 +0100

repository.nim: new proc isHeadDetached, cleanup
1 file changed, 9 insertions(+), 5 deletions(-)
M
nimgit/repository.nim
|
14
+++++++++-----
diff --git a/nimgit/repository.nim b/nimgit/repository.nim
@@ -1,13 +1,16 @@
 import nimgit2
 import types, free
 
-proc openGitRepository* (path: string): GitRepository =
-    let error = git_repository_open(addr result, path)
+proc openGitRepository* (path: string): GitRepository = 
+    var repository: GitRepository
+    let error = git_repository_open(addr repository, path)
 
     if error != 0:
-        free(result)
+        free(repository)
         raise newException(CatchableError, "Cannot open repository: " & $error.getResultCode)
 
+    result = repository
+
 proc getHead* (repo: GitRepository): GitReference = 
     let error = git_repository_head(addr result, repo)
 

@@ -15,7 +18,8 @@ proc getHead* (repo: GitRepository): GitReference =
         free(result)
         raise newException(CatchableError, "Cannot get HEAD: " & $error.getResultCode)
 
-proc getPath* (repo: GitRepository): string =
-    return $git_repository_path(repo)
+proc isHeadDetached* (repo: GitRepository): bool = cast[bool](git_repository_head_detached(repo))
+
+proc getPath* (repo: GitRepository): string = $git_repository_path(repo)
 
 proc `$`* (repo: GitRepository): string = repo.getPath() 
\ No newline at end of file