53
57
class TestGitBranch(tests.TestCaseInTempDir):
55
_test_needs_features = [tests.GitCommandFeature]
57
59
def test_open_existing(self):
60
thebranch = Branch.open('.')
62
thebranch = d.create_branch()
61
63
self.assertIsInstance(thebranch, branch.GitBranch)
63
65
def test_repr(self):
65
thebranch = Branch.open('.')
66
self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
68
thebranch = d.create_branch()
69
self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
68
71
def test_last_revision_is_null(self):
71
thebranch = Branch.open('.')
73
thedir = BzrDir.open('.')
74
thebranch = thedir.create_branch()
72
75
self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
73
76
self.assertEqual((0, revision.NULL_REVISION),
74
77
thebranch.last_revision_info())
76
79
def simple_commit_a(self):
78
81
self.build_tree(['a'])
79
tests.run_git('add', 'a')
80
tests.run_git('commit', '-m', 'a')
83
return r.do_commit("a", committer="Somebody <foo@example.com>")
82
85
def test_last_revision_is_valid(self):
83
self.simple_commit_a()
84
head = tests.run_git('rev-parse', 'HEAD').strip()
86
head = self.simple_commit_a()
86
87
thebranch = Branch.open('.')
87
88
self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
88
89
thebranch.last_revision())
90
91
def test_revision_history(self):
91
self.simple_commit_a()
92
reva = tests.run_git('rev-parse', 'HEAD').strip()
92
reva = self.simple_commit_a()
93
93
self.build_tree(['b'])
94
tests.run_git('add', 'b')
95
tests.run_git('commit', '-m', 'b')
96
revb = tests.run_git('rev-parse', 'HEAD').strip()
96
revb = r.do_commit("b", committer="Somebody <foo@example.com>")
98
98
thebranch = Branch.open('.')
99
99
self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
100
thebranch.revision_history())
102
102
def test_tag_annotated(self):
103
self.simple_commit_a()
104
reva = tests.run_git('rev-parse', 'HEAD').strip()
105
tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
103
reva = self.simple_commit_a()
106
o.tagger = "Jelmer <foo@example.com>"
107
o.message = "add tag"
108
o.object = (Commit, reva)
112
r.object_store.add_object(o)
113
r['refs/tags/foo'] = o.id
106
114
thebranch = Branch.open('.')
107
115
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
108
116
thebranch.tags.get_tag_dict())
110
118
def test_tag(self):
111
self.simple_commit_a()
112
reva = tests.run_git('rev-parse', 'HEAD').strip()
113
tests.run_git('tag', '-m', 'add tag', 'foo')
119
reva = self.simple_commit_a()
121
r.refs["refs/tags/foo"] = reva
114
122
thebranch = Branch.open('.')
115
123
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
116
124
thebranch.tags.get_tag_dict())
120
128
class TestWithGitBranch(tests.TestCaseWithTransport):
123
131
tests.TestCaseWithTransport.setUp(self)
124
132
dulwich.repo.Repo.create(self.test_dir)
125
self.git_branch = Branch.open(self.test_dir)
133
d = BzrDir.open(self.test_dir)
134
self.git_branch = d.create_branch()
127
136
def test_get_parent(self):
128
137
self.assertIs(None, self.git_branch.get_parent())
130
139
def test_get_stacked_on_url(self):
131
self.assertRaises(errors.UnstackableBranchFormat,
140
self.assertRaises(errors.UnstackableBranchFormat,
132
141
self.git_branch.get_stacked_on_url)
134
143
def test_get_physical_lock_status(self):