commit 662df89660a3dc094fcaefb9e335f10c31f9d9eb
parent 6a6514b2b1ba7de1ef7977f69d34869545b754a7
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 16 Mar 2021 16:29:52 +0100
parent 6a6514b2b1ba7de1ef7977f69d34869545b754a7
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 16 Mar 2021 16:29:52 +0100
reference.nim: new proc getBranchName
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/listAllBranches.nim b/listAllBranches.nim @@ -12,10 +12,10 @@ try: for branch in gitRepository.branches(branchAll): if branch.isLocalBranch(): - echo "local: " & $branch + echo "local: " & branch.getBranchName() if branch.isRemoteBranch(): - echo "remote: " & $branch + echo "remote: " & branch.getBranchName() free(branch)
diff --git a/nimgit/commit.nim b/nimgit/commit.nim @@ -1,7 +1,7 @@ import nimgit2 import types, free, utils -proc lookupCommit* (repo: GitRepository, oid: ptr git_oid): GitCommit = +proc lookupCommit* (repo: GitRepository, oid: GitObjectId): GitCommit = let error = git_commit_lookup(addr result, repo, oid) if error != 0:
diff --git a/nimgit/reference.nim b/nimgit/reference.nim @@ -9,6 +9,17 @@ proc getShorthand* (reference: GitReference): string = reference.getShortName() proc `$`* (reference: GitReference): string = reference.getName() +proc getBranchName* (reference: GitReference): string = + var name: cstring + let error = git_branch_name(addr name, reference).getResultCode + + if error != grcOk: + if error == grcInvalid: + raise newException(ValueError, "Not a symbolic reference!") + else: + raise newException(CatchableError, "Cannot get branch name: " & $error) + + result = $name proc isLocalBranch* (reference: GitReference): bool = cast[bool](git_reference_is_branch(reference))