summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-19 14:06:45 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-19 14:06:45 +0100
commit0c4ecd37247855fd7e3402cd17d3ec955970684f (patch)
tree88ba8f1ac72871fd86f9c9a682af0556005070a7
parentc0a59f7b495043fb63af44a2876c79d5a9072576 (diff)
downloadnimgit-0c4ecd37247855fd7e3402cd17d3ec955970684f.tar.gz
nimgit-0c4ecd37247855fd7e3402cd17d3ec955970684f.tar.bz2
nimgit-0c4ecd37247855fd7e3402cd17d3ec955970684f.zip
add new example ListAllFiles
-rw-r--r--.gitignore3
-rw-r--r--listAllFiles.nim35
-rw-r--r--nimgit.nimble2
-rw-r--r--showLastCommit.nim11
4 files changed, 38 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index 9fcb5bb..e1ea908 100644
--- 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
new file mode 100644
index 0000000..73b1d43
--- /dev/null
+++ 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
index bf377e7..936536f 100644
--- 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
index 8f60be3..64804e2 100644
--- 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)