libgit2 / libgit2/pygit2

ValueError `repo.branches.get('branch_no_exist/')` trailing slashes in branch names

Open
#832 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.7k
Forks
408
Avg merge
2d 57m
Merged PRs (30d)
7

Description

if i have a repo and call

>> 'branch_no_exist' in repo.branches
False

as expected, but

>> 'branch_no_exist/' in repo.branches
Traceback (most recent call last):

  pygit2/repository.py", line 1156, in get
    return self[key]
 pygit2/repository.py", line 1144, in __getitem__
    branch = self._repository.lookup_branch(name, GIT_BRANCH_LOCAL)
ValueError: cannot locate local branch 'branch_no_exist/'

Given branch names Shouldn't end in a slash, but the error is not complaining about this.

should repository.lookup_branch be returning None in this case?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pygit2/repository.py at the get method and getitem path shown in the traceback, then reproduce lookups for a nonexistent branch with and without a trailing slash. Check the existing branch lookup tests and define completion as consistent handling of the trailing-slash case, covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.