← 返回首页
Fixed a bug with branch names omitting path components. · gitpython-developers/GitPython@b65df78 · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Commit b65df78

Browse files
committed
Fixed a bug with branch names omitting path components.
Git allows branches to be named and organized using path components, e.g using a branch called "refactoring/feature1", which gets stored under refs/heads/refactoring/feature1. The previous code omitted everything but the last path component giving the name "feature1" instead of "refactoring/feature1" for the branch. This changeset fixes that. (cherry picked from commit dc4738bc53e580754e47037e26c7eec3047aeb69)
1 parent 6ffd4b0 commit b65df78

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎lib/git/head.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ def from_string(cls, repo, line):
104104
git.Head
105105
"""
106106
full_name, ids = line.split("\x00")
107-
name = full_name.split("/")[-1]
107+
108+
if full_name.startswith('refs/heads/'):
109+
name = full_name[len('refs/heads/'):]
110+
else:
111+
name = full_name
112+
108113
c = commit.Commit(repo, id=ids)
109114
return Head(name, c)
110115

72 Bytes
Binary file not shown.

‎test/git/test_head.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ def test_repr(self, git):
2121

2222
assert_true(git.called)
2323
assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'}))
24+
25+
@patch_object(Git, '_call_process')
26+
def test_ref_with_path_component(self, git):
27+
git.return_value = fixture('for_each_ref_with_path_component')
28+
head = self.repo.heads[0]
29+
30+
assert_equal('refactoring/feature1', head.name)
31+
assert_true(git.called)
32+
assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'}))

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.