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 "" if commit.hasParents: let parent = gitRepository.lookupCommit(commit.parentIds[0]) let parentTree = gitRepository.lookupTree(parent.treeId) let diffopts = initDiffOptions() diffopts.flags = cast[uint32](GIT_DIFF_DISABLE_PATHSPEC_MATCH) or cast[uint32](GIT_DIFF_IGNORE_SUBMODULES) or cast[uint32](GIT_DIFF_INCLUDE_TYPECHANGE) let findopts = GitDiffFindOptions() findopts.flags = cast[uint32](GIT_DIFF_FIND_RENAMES) or cast[uint32](GIT_DIFF_FIND_COPIES) or cast[uint32](GIT_DIFF_FIND_EXACT_MATCH_ONLY) let diff = gitRepository.diffTrees(tree, parentTree, diffopts) diff.findSimilar(findopts) free(parentTree) free(parent) echo diff.len echo diff.stats for deltaIndex, delta in diff.deltas: echo delta.statusChar & " " & $delta.old_file.path & " " & $delta.new_file.path let patch = diff.patch(deltaIndex) for hunkIndex, hunk in patch.hunks(): echo $hunk.header for lineIndex, line in patch.lines(hunkIndex): var status: string if line.old_lineno == -1: status = "+" elif line.new_lineno == -1: status = "-" else: status = " " echo status & $line.content free(patch) free(tree) free(commit) free(config) free(gitRepository) except: echo "Error:\n", getCurrentExceptionMsg()