ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

commit 0c4ecd37247855fd7e3402cd17d3ec955970684f
parent c0a59f7b495043fb63af44a2876c79d5a9072576
Author: Leah (ctucx) <leah@ctu.cx>
Date: Fri, 19 Mar 2021 14:06:45 +0100

add new example ListAllFiles
4 files changed, 40 insertions(+), 14 deletions(-)
M
.gitignore
|
5
+++--
A
listAllFiles.nim
|
36
++++++++++++++++++++++++++++++++++++
M
nimgit.nimble
|
2
+-
M
showLastCommit.nim
|
11
-----------
diff --git a/.gitignore b/.gitignore
@@ -3,4 +3,5 @@ listAllCommits
 listAllRefs
 showLastCommit
 
-listAllBranches-
\ No newline at end of file
+listAllBranches
+listAllFiles+
\ No newline at end of file
diff --git a/listAllFiles.nim b/listAllFiles.nim
@@ -0,0 +1,35 @@
+import os
+import nimgit
+
+if paramCount() == 0:
+    echo "No git-repo given."
+    quit(QuitFailure)
+
+discard git_libgit2_init()
+
+try:
+    let
+      gitRepository = openGitRepository(paramStr(1))
+      config        = gitRepository.config
+      objId         = gitRepository.lookupObjectIdByName("HEAD")
+      commit        = gitRepository.lookupCommit(objId)
+      tree          = commit.tree
+
+    echo "Tree of last commit on HEAD in repo: " & $gitRepository
+    echo "========================================================="
+    for element in tree.walk:
+      let (path, entry) = element
+
+      echo $entry.id & " " & entry.modeStr & " " & $entry.type & " " & path & entry.name
+
+      free(entry)
+
+    echo ""
+
+    free(tree)
+    free(commit)
+    free(config)
+    free(gitRepository)
+
+except:
+    echo "Error:\n", getCurrentExceptionMsg()+
\ No newline at end of file
diff --git a/nimgit.nimble b/nimgit.nimble
@@ -7,7 +7,7 @@ license       = "MIT"
 srcDir        = "./"
 installDirs   = @["nimgit"]
 installFiles  = @["nimgit.nim"]
-bin           = @["showLastCommit", "listAllCommits", "listAllRefs", "listAllBranches"]
+bin           = @["showLastCommit", "listAllCommits", "listAllRefs", "listAllBranches", "listAllFiles"]
 
 
 # Dependencies
diff --git a/showLastCommit.nim b/showLastCommit.nim
@@ -38,17 +38,6 @@ try:
 
     echo ""
 
-    echo "tree of that commit:"
-    echo "======================"
-    for element in tree.walk:
-      let (path, entry) = element
-
-      echo $entry.id & " " & entry.modeStr & " " & $entry.type & " " & path & entry.name
-
-      free(entry)
-
-    echo ""
-
     free(tree)
     free(commit)
     free(config)