1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# test_refs.py
# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
from mock import *
from test.testlib import *
from git import *
import git.refs as refs
from git.objects.tag import TagObject
from itertools import chain
class TestRefs(TestBase):
def test_tag_base(self):
tag_object_refs = list()
for tag in self.rorepo.tags:
assert "refs/tags" in tag.path
assert tag.name
assert isinstance( tag.commit, Commit )
if tag.tag is not None:
tag_object_refs.append( tag )
tagobj = tag.tag
assert isinstance( tagobj, TagObject )
assert tagobj.tag == tag.name
assert isinstance( tagobj.tagger, Actor )
assert isinstance( tagobj.tagged_date, int )
assert tagobj.message
# END if we have a tag object
# END for tag in repo-tags
assert tag_object_refs
assert isinstance(self.rorepo.tags['0.1.5'], TagReference)
@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.rorepo.heads[0]
assert_equal('refactoring/feature1', head.name)
assert_true(git.called)
def test_tags(self):
# tag refs can point to tag objects or to commits
s = set()
ref_count = 0
for ref in chain(self.rorepo.tags, self.rorepo.heads):
ref_count += 1
assert isinstance(ref, refs.Reference)
assert str(ref) == ref.name
assert repr(ref)
assert ref == ref
assert not ref != ref
s.add(ref)
# END for each ref
assert len(s) == ref_count
assert len(s|s) == ref_count
def test_heads(self):
for head in self.rorepo.heads:
assert head.name
assert head.path
assert "refs/heads" in head.path
prev_object = head.object
cur_object = head.object
assert prev_object == cur_object # represent the same git object
assert prev_object is not cur_object # but are different instances
# END for each head
@with_rw_repo('0.1.6')
def test_head_reset(self, rw_repo):
cur_head = rw_repo.head
new_head_commit = cur_head.ref.commit.parents[0]
cur_head.reset(new_head_commit, index=True) # index only
assert cur_head.reference.commit == new_head_commit
self.failUnlessRaises(ValueError, cur_head.reset, new_head_commit, index=False, working_tree=True)
new_head_commit = new_head_commit.parents[0]
cur_head.reset(new_head_commit, index=True, working_tree=True) # index + wt
assert cur_head.reference.commit == new_head_commit
# paths
cur_head.reset(new_head_commit, paths = "lib")
# now that we have a write write repo, change the HEAD reference - its
# like git-reset --soft
heads = rw_repo.heads
assert heads
for head in heads:
cur_head.reference = head
assert cur_head.reference == head
assert cur_head.commit == head.commit
assert not cur_head.is_detached
# END for each head
# detach
cur_head.reference = heads[0].commit
assert cur_head.commit == heads[0].commit
assert cur_head.is_detached
self.failUnlessRaises(TypeError, getattr, cur_head, "reference")
some_tag = rw_repo.tags[0]
cur_head.reference = some_tag
assert cur_head.is_detached
assert cur_head.commit == some_tag.commit
# type check
self.failUnlessRaises(ValueError, setattr, cur_head, "reference", "that")
|