2020 SymbolicReference ,
2121 TagReference
2222)
23-
24-
2523from git .util import (
2624 LazyMixin ,
2725 Iterable ,
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
569570 progress_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 )
573574 for pline in progress_handler (line ):
574575 if line .startswith ('fatal:' ) or line .startswith ('error:' ):
575576 raise GitCommandError (("Error when fetching: %s" % line ,), 2 )
@@ -589,11 +590,21 @@ def _get_fetch_info_from_stderr(self, proc, progress):
589590 fetch_head_info = [l .decode (defenc ) for l in fp .readlines ()]
590591 fp .close ()
591592
592- # NOTE: We assume to fetch at least enough progress lines to allow matching each fetch head line with it.
593593 l_fil = len (fetch_info_lines )
594594 l_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+
597608 output .extend (FetchInfo ._from_line (self .repo , err_line , fetch_line )
598609 for err_line , fetch_line in zip (fetch_info_lines , fetch_head_info ))
599610 return output
@@ -673,8 +684,8 @@ def fetch(self, refspec=None, progress=None, **kwargs):
673684 else :
674685 args = [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 )
678689 res = self ._get_fetch_info_from_stderr (proc , progress )
679690 if hasattr (self .repo .odb , 'update_cache' ):
680691 self .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.
693704 self ._assert_refspec ()
694705 kwargs = 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 )
696708 res = self ._get_fetch_info_from_stderr (proc , progress )
697709 if hasattr (self .repo .odb , 'update_cache' ):
698710 self .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."""
735747 kwargs = 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 )
737750 return self ._get_push_info (proc , progress )
738751
739752 @property
0 commit comments