Skip to content

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

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy