summaryrefslogtreecommitdiffstats
path: root/showLastCommit.nim
blob: 2767111632be4d90511ee3ff654d54555c44bb66 (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os, times
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)
      author        = commit.author
      committer     = commit.committer
      parentCount   = commit.parentCount
      signature     = commit.gpgSignature
      tree          = commit.tree

    echo "Last commit on HEAD in repo: " & $gitRepository
    echo "==================="
    echo "config value of core.bare: " & $config.getBool("core.bare")
    echo "hash: " & $objId & " (" & commit.shortId & ")"
    echo "committer: " & committer.name & " <" & committer.email & ">"
    echo "author: " & author.name & " <" & author.email & ">"
    echo "when: " & $commit.time
    echo "message: " & commit.summary
    echo "tree id: " & $commit.treeId
    echo "parentCount: " & $parentCount

    for parentId in commit.parentIds:
        echo "parent: " & $parentId

    if signature[0] != "":
        echo "signature: " & $signature

    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 tree.entries

    echo ""

    free(tree)
    free(commit)
    free(config)
    free(gitRepository)

except:
    echo "Error:\n", getCurrentExceptionMsg()