summaryrefslogtreecommitdiffstats
path: root/nimgit/treeEntry.nim
diff options
context:
space:
mode:
Diffstat (limited to 'nimgit/treeEntry.nim')
-rw-r--r--nimgit/treeEntry.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/nimgit/treeEntry.nim b/nimgit/treeEntry.nim
new file mode 100644
index 0000000..8dd30e2
--- /dev/null
+++ b/nimgit/treeEntry.nim
@@ -0,0 +1,17 @@
+import nimgit2
+import types, free, utils
+
+proc type* (entry: GitTreeEntry): GitObjectKind = GitObjectKind(git_tree_entry_type(entry) - GIT_OBJECT_ANY)
+
+proc id* (entry: GitTreeEntry): GitObjectId = git_tree_entry_id(entry)
+
+proc name* (entry: GitTreeEntry): string = $git_tree_entry_name(entry)
+
+proc mode* (entry: GitTreeEntry): int = cast[int](git_tree_entry_filemode(entry))
+
+proc getObject* (repo: GitRepository, entry: GitTreeEntry): GitObject =
+ let error = git_tree_entry_to_object(addr result, repo, entry)
+
+ if error != 0:
+ free(result)
+ raise newException(CatchableError, "Cannot convert tree-entry into object: " & $error.getResultCode)