88"""
99
1010from git .utils import LazyMixin , Iterable , IterableList
11+ from objects import Commit
1112from refs import Reference , RemoteReference
1213import re
1314import os
@@ -58,24 +59,39 @@ class FetchInfo(object):
5859 info = remote.fetch()[0]
5960 info.remote_ref # Symbolic Reference or RemoteReference to the changed remote head or FETCH_HEAD
6061 info.flags # additional flags to be & with enumeration members, i.e. info.flags & info.REJECTED
61- info.note # additional notes given by git-fetch intended for the user
62+ info.note # additional notes given by git-fetch intended for the user
63+ info.commit_before_forced_update # if info.flags & info.FORCED_UPDATE, field is set to the
64+ # previous location of remote_ref, otherwise None
6265 """
63- __slots__ = ('remote_ref' , 'flags' , 'note' )
66+ __slots__ = ('remote_ref' ,'commit_before_forced_update' , 'flags' , 'note' )
67+
6468 BRANCH_UPTODATE , REJECTED , FORCED_UPDATE , FAST_FORWARD , NEW_TAG , \
6569 TAG_UPDATE , NEW_BRANCH , ERROR = [ 1 << x for x in range (1 ,9 ) ]
6670 # %c %-*s %-*s -> %s (%s)
67- re_fetch_result = re .compile ("^(.) (\[?[\w\s]+\]?)\s+(.+) -> (.+/. +)( \(.*\)?$)?" )
71+ re_fetch_result = re .compile ("^(.) (\[?[\w\s\. ]+\]?)\s+(.+) -> (.+/[\w_\.-] +)( \(.*\)?$)?" )
6872
6973 _flag_map = { '!' : ERROR , '+' : FORCED_UPDATE , '-' : TAG_UPDATE , '*' : 0 ,
7074 '=' : BRANCH_UPTODATE , ' ' : FAST_FORWARD }
7175
72- def __init__ (self , remote_ref , flags , note = '' ):
76+ def __init__ (self , remote_ref , flags , note = '' , old_commit = None ):
7377 """
7478 Initialize a new instance
7579 """
7680 self .remote_ref = remote_ref
7781 self .flags = flags
7882 self .note = note
83+ self .commit_before_forced_update = old_commit
84+
85+ def __str__ (self ):
86+ return self .name
87+
88+ @property
89+ def name (self ):
90+ """
91+ Returns
92+ Name of our remote ref
93+ """
94+ return self .remote_ref .name
7995
8096 @classmethod
8197 def _from_line (cls , repo , line ):
@@ -112,14 +128,18 @@ def _from_line(cls, repo, line):
112128 # END control char exception hanlding
113129
114130 # parse operation string for more info
131+ old_commit = None
115132 if 'rejected' in operation :
116133 flags |= cls .REJECTED
117134 if 'new tag' in operation :
118135 flags |= cls .NEW_TAG
119136 if 'new branch' in operation :
120137 flags |= cls .NEW_BRANCH
138+ if '...' in operation :
139+ old_commit = Commit (repo , operation .split ('...' )[0 ])
140+ # END handle refspec
121141
122- return cls (remote_local_ref , flags , note )
142+ return cls (remote_local_ref , flags , note , old_commit )
123143
124144 # END FetchInfo definition
125145
@@ -275,7 +295,10 @@ def update(self, **kwargs):
275295
276296 def _get_fetch_info_from_stderr (self , stderr ):
277297 # skip first line as it is some remote info we are not interested in
278- return [ self .FetchInfo ._from_line (self .repo , line ) for line in stderr .splitlines ()[1 :] ]
298+ print stderr
299+ output = IterableList ('name' )
300+ output .extend (self .FetchInfo ._from_line (self .repo , line ) for line in stderr .splitlines ()[1 :])
301+ return output
279302
280303 def fetch (self , refspec = None , ** kwargs ):
281304 """
@@ -297,7 +320,7 @@ def fetch(self, refspec=None, **kwargs):
297320 Additional arguments to be passed to git-fetch
298321
299322 Returns
300- list (FetchInfo, ...) list of FetchInfo instances providing detailed
323+ IterableList (FetchInfo, ...) list of FetchInfo instances providing detailed
301324 information about the fetch results
302325 """
303326 status , stdout , stderr = self .repo .git .fetch (self , refspec , with_extended_output = True , v = True , ** kwargs )
@@ -315,7 +338,7 @@ def pull(self, refspec=None, **kwargs):
315338 Additional arguments to be passed to git-pull
316339
317340 Returns
318- list(Fetch
341+ Please see 'fetch' method
319342 """
320343 status , stdout , stderr = self .repo .git .pull (self , refspec , v = True , with_extended_output = True , ** kwargs )
321344 return self ._get_fetch_info_from_stderr (stderr )
0 commit comments