ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
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()