Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Provide feedback

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

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbeb76ab

Browse files
committed
repo.active_branch now returns a Head object, not a string
1 parentaf9e37c commitbeb76ab

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

‎CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ objects Package
2929
Repo
3030
----
3131
* Moved blame method from Blob to repo as it appeared to belong there much more.
32+
* active_branch method now returns a Head object instead of a string with the name
33+
of the active branch.
34+
* tree method now requires a Ref instance as input and defaults to the active_branche
35+
instead of master
3236

3337
Diff
3438
----

‎lib/git/repo.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,23 @@ def commit_count(self, start='master', path=''):
277277
"""
278278
returnCommit.count(self,start,path)
279279

280-
defcommit(self,id,path=''):
280+
defcommit(self,id=None,path=''):
281281
"""
282282
The Commit object for the specified id
283283
284284
``id``
285-
is the SHA1 identifier of the commit
285+
is the SHA1 identifier of the commit or a ref or a ref name
286+
if None, it defaults to the active branch
287+
286288
287289
``path``
288290
is an optional path, if set the returned commit must contain the path.
289291
290292
Returns
291293
``git.Commit``
292294
"""
295+
ifidisNone:
296+
id=self.active_branch
293297
options= {'max_count':1}
294298

295299
commits=Commit.find_all(self,id,path,**options)
@@ -311,22 +315,34 @@ def commit_deltas_from(self, other_repo, ref='master', other_ref='master'):
311315
diff_refs=list(set(other_repo_refs)-set(repo_refs))
312316
returnmap(lambdaref:Commit.find_all(other_repo,ref,max_count=1)[0],diff_refs)
313317

314-
deftree(self,treeish='master'):
318+
deftree(self,treeish=None):
315319
"""
316320
The Tree object for the given treeish reference
317321
318322
``treeish``
319-
is thereference (default 'master')
323+
isa Ref instance defaulting totheactive_branch if None.
320324
321325
Examples::
322326
323-
repo.tree('master')
324-
327+
repo.tree(repo.heads[0])
325328
326329
Returns
327330
``git.Tree``
331+
332+
NOTE
333+
A ref is requried here to assure you point to a commit or tag. Otherwise
334+
it is not garantueed that you point to the root-level tree.
335+
336+
If you need a non-root level tree, find it by iterating the root tree.
328337
"""
329-
returnTree(self,id=treeish)
338+
iftreeishisNone:
339+
treeish=self.active_branch
340+
ifnotisinstance(treeish,Ref):
341+
raiseValueError("Treeish reference required, got %r"%treeish )
342+
343+
# we should also check whether the ref has a valid commit ... but lets n
344+
# not be over-critical
345+
returnTree(self,treeish)
330346

331347
defblob(self,id):
332348
"""
@@ -588,13 +604,9 @@ def active_branch(self):
588604
The name of the currently active branch.
589605
590606
Returns
591-
str (thebranch name)
607+
Head totheactive branch
592608
"""
593-
branch=self.git.symbolic_ref('HEAD').strip()
594-
ifbranch.startswith('refs/heads/'):
595-
branch=branch[len('refs/heads/'):]
596-
597-
returnbranch
609+
returnHead(self,self.git.symbolic_ref('HEAD').strip() )
598610

599611
def__repr__(self):
600612
return'<git.Repo "%s">'%self.path

‎test/git/test_repo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ def test_commit(self, git):
9191
deftest_tree(self,git):
9292
git.return_value=fixture('ls_tree_a')
9393

94-
tree=self.repo.tree('master')
94+
tree=self.repo.tree(Head(self.repo,'master'))
9595

9696
assert_equal(4,len([cforcintree.values()ifisinstance(c,Blob)]))
9797
assert_equal(3,len([cforcintree.values()ifisinstance(c,Tree)]))
9898

9999
assert_true(git.called)
100-
assert_equal(git.call_args, (('ls_tree','master'), {}))
101100

102101
@patch_object(Git,'_call_process')
103102
deftest_blob(self,git):
@@ -255,7 +254,7 @@ def test_is_dirty_with_dirty_working_dir(self, git):
255254
@patch_object(Git,'_call_process')
256255
deftest_active_branch(self,git):
257256
git.return_value='refs/heads/major-refactoring'
258-
assert_equal(self.repo.active_branch,'major-refactoring')
257+
assert_equal(self.repo.active_branch.name,'major-refactoring')
259258
assert_equal(git.call_args, (('symbolic_ref','HEAD'), {}))
260259

261260
@patch_object(Git,'_call_process')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp