diff options
author | Michael Trier <mtrier@gmail.com> | 2008-12-16 09:55:00 -0500 |
---|---|---|
committer | Michael Trier <mtrier@gmail.com> | 2008-12-16 09:55:00 -0500 |
commit | b65df78a10c3bcc40d18f3e926bb5a49821acc31 (patch) | |
tree | bca5612310925faea912572abb039b1136ddd75f | |
parent | 6ffd4b0193acf86b6a6e179f8673ed38bad3191d (diff) | |
download | gitpython-b65df78a10c3bcc40d18f3e926bb5a49821acc31.tar.gz |
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)
-rw-r--r-- | lib/git/head.py | 7 | ||||
-rw-r--r-- | test/fixtures/for_each_ref_with_path_component | bin | 0 -> 72 bytes | |||
-rw-r--r-- | test/git/test_head.py | 9 |
3 files changed, 15 insertions, 1 deletions
diff --git a/lib/git/head.py b/lib/git/head.py index 4386aa98..c56bb1fa 100644 --- a/lib/git/head.py +++ b/lib/git/head.py @@ -104,7 +104,12 @@ class Head(object): git.Head """ full_name, ids = line.split("\x00") - name = full_name.split("/")[-1] + + if full_name.startswith('refs/heads/'): + name = full_name[len('refs/heads/'):] + else: + name = full_name + c = commit.Commit(repo, id=ids) return Head(name, c) diff --git a/test/fixtures/for_each_ref_with_path_component b/test/fixtures/for_each_ref_with_path_component Binary files differnew file mode 100644 index 00000000..717c4203 --- /dev/null +++ b/test/fixtures/for_each_ref_with_path_component diff --git a/test/git/test_head.py b/test/git/test_head.py index 669665c0..b9b1ac4f 100644 --- a/test/git/test_head.py +++ b/test/git/test_head.py @@ -21,3 +21,12 @@ class TestHead(object): assert_true(git.called) assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) + + @patch_object(Git, '_call_process') + def test_ref_with_path_component(self, git): + git.return_value = fixture('for_each_ref_with_path_component') + head = self.repo.heads[0] + + assert_equal('refactoring/feature1', head.name) + assert_true(git.called) + assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) |