ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

commit b2fc1ab137ddf5da457942d018ce002037bd7b39
parent 1e0f00b7546d535d96a0126f9840424a02878486
Author: Leah (ctucx) <leah@ctu.cx>
Date: Wed, 17 Mar 2021 02:24:56 +0100

repository.nim: new procs: getHeadForWorktree, getTagList, isEmpty, isWorktree, isBare, getWorktree
1 file changed, 34 insertions(+), 0 deletions(-)
M
nimgit/repository.nim
|
34
++++++++++++++++++++++++++++++++++
diff --git a/nimgit/repository.nim b/nimgit/repository.nim
@@ -11,6 +11,14 @@ proc openGitRepository* (path: string): GitRepository =
 
     result = repository
 
+
+proc getHeadForWorktree* (repo: GitRepository, name: string): GitReference = 
+    let error = git_repository_head_for_worktree(addr result, repo, cstring(name))
+
+    if error != 0:
+        free(result)
+        raise newException(CatchableError, "Cannot get HEAD for worktree: " & $error.getResultCode)
+
 proc getHead* (repo: GitRepository): GitReference = 
     let error = git_repository_head(addr result, repo)
 

@@ -20,6 +28,32 @@ proc getHead* (repo: GitRepository): GitReference =
 
 proc isHeadDetached* (repo: GitRepository): bool = cast[bool](git_repository_head_detached(repo))
 
+
+proc getTagList* (repo: GitRepository): seq[string] =
+    var list: git_strarray
+    
+    let error = git_tag_list(addr list, repo)
+
+    if error != 0:
+        free(addr list)
+        raise newException(CatchableError, "Cannot get tagList: " & $error.getResultCode)
+    
+    if list.count == 0'u:
+        result = newSeq[string]()
+    else:
+        result = cstringArrayToSeq(cast[cstringArray](list.strings), list.count)
+
+    free(addr list)
+
+
+proc isEmpty* (repo: GitRepository): bool = cast[bool](git_repository_is_empty(repo))
+
+proc isWorktree* (repo: GitRepository): bool = cast[bool](git_repository_is_worktree(repo))
+
+proc isBare* (repo: GitRepository): bool = cast[bool](git_repository_is_bare(repo))
+
 proc getPath* (repo: GitRepository): string = $git_repository_path(repo)
 
+proc getWorkdir* (repo: GitRepository): string = $git_repository_workdir(repo)
+
 proc `$`* (repo: GitRepository): string = repo.getPath() 
\ No newline at end of file