2020SymbolicReference ,
2121TagReference
2222)
23-
24-
2523from git .util import (
2624LazyMixin ,
2725Iterable ,
3432)
3533from git .cmd import handle_process_output
3634from gitdb .util import join
37- from git .compat import defenc
35+ from git .compat import (defenc ,force_text )
36+ import logging
37+
38+ log = logging .getLogger ('git.remote' )
3839
3940
4041__all__ = ('RemoteProgress' ,'PushInfo' ,'FetchInfo' ,'Remote' )
@@ -568,8 +569,8 @@ def _get_fetch_info_from_stderr(self, proc, progress):
568569
569570progress_handler = progress .new_message_handler ()
570571
571- for line in proc .stderr . readlines () :
572- line = line . decode ( defenc )
572+ for line in proc .stderr :
573+ line = force_text ( line )
573574for pline in progress_handler (line ):
574575if line .startswith ('fatal:' )or line .startswith ('error:' ):
575576raise GitCommandError (("Error when fetching: %s" % line ,),2 )
@@ -589,11 +590,21 @@ def _get_fetch_info_from_stderr(self, proc, progress):
589590fetch_head_info = [l .decode (defenc )for l in fp .readlines ()]
590591fp .close ()
591592
592- # NOTE: We assume to fetch at least enough progress lines to allow matching each fetch head line with it.
593593l_fil = len (fetch_info_lines )
594594l_fhi = len (fetch_head_info )
595- assert l_fil >= l_fhi ,"len(%s) <= len(%s)" % (l_fil ,l_fhi )
596-
595+ if l_fil != l_fhi :
596+ msg = "Fetch head lines do not match lines provided via progress information\n "
597+ msg += "length of progress lines %i should be equal to lines in FETCH_HEAD file %i\n "
598+ msg += "Will ignore extra progress lines or fetch head lines."
599+ msg %= (l_fil ,l_fhi )
600+ log .debug (msg )
601+ if l_fil < l_fhi :
602+ fetch_head_info = fetch_head_info [:l_fil ]
603+ else :
604+ fetch_info_lines = fetch_info_lines [:l_fhi ]
605+ # end truncate correct list
606+ # end sanity check + sanitization
607+
597608output .extend (FetchInfo ._from_line (self .repo ,err_line ,fetch_line )
598609for err_line ,fetch_line in zip (fetch_info_lines ,fetch_head_info ))
599610return output
@@ -673,8 +684,8 @@ def fetch(self, refspec=None, progress=None, **kwargs):
673684else :
674685args = [refspec ]
675686
676- proc = self .repo .git .fetch (self ,* args ,as_process = True ,with_stdout = False ,v = True ,
677- ** kwargs )
687+ proc = self .repo .git .fetch (self ,* args ,as_process = True ,with_stdout = False ,
688+ universal_newlines = True , v = True , ** kwargs )
678689res = self ._get_fetch_info_from_stderr (proc ,progress )
679690if hasattr (self .repo .odb ,'update_cache' ):
680691self .repo .odb .update_cache ()
@@ -692,7 +703,8 @@ def pull(self, refspec=None, progress=None, **kwargs):
692703# No argument refspec, then ensure the repo's config has a fetch refspec.
693704self ._assert_refspec ()
694705kwargs = add_progress (kwargs ,self .repo .git ,progress )
695- proc = self .repo .git .pull (self ,refspec ,with_stdout = False ,as_process = True ,v = True ,** kwargs )
706+ proc = self .repo .git .pull (self ,refspec ,with_stdout = False ,as_process = True ,
707+ universal_newlines = True ,v = True ,** kwargs )
696708res = self ._get_fetch_info_from_stderr (proc ,progress )
697709if hasattr (self .repo .odb ,'update_cache' ):
698710self .repo .odb .update_cache ()
@@ -733,7 +745,8 @@ def push(self, refspec=None, progress=None, **kwargs):
733745 If the operation fails completely, the length of the returned IterableList will
734746 be null."""
735747kwargs = add_progress (kwargs ,self .repo .git ,progress )
736- proc = self .repo .git .push (self ,refspec ,porcelain = True ,as_process = True ,** kwargs )
748+ proc = self .repo .git .push (self ,refspec ,porcelain = True ,as_process = True ,
749+ universal_newlines = True ,** kwargs )
737750return self ._get_push_info (proc ,progress )
738751
739752@property