20
20
SymbolicReference ,
21
21
TagReference
22
22
)
23
-
24
-
25
23
from git .util import (
26
24
LazyMixin ,
27
25
Iterable ,
34
32
)
35
33
from git .cmd import handle_process_output
36
34
from 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' )
38
39
39
40
40
41
__all__ = ('RemoteProgress' , 'PushInfo' , 'FetchInfo' , 'Remote' )
@@ -568,8 +569,8 @@ def _get_fetch_info_from_stderr(self, proc, progress):
568
569
569
570
progress_handler = progress .new_message_handler ()
570
571
571
- for line in proc .stderr . readlines () :
572
- line = line . decode ( defenc )
572
+ for line in proc .stderr :
573
+ line = force_text ( line )
573
574
for pline in progress_handler (line ):
574
575
if line .startswith ('fatal:' ) or line .startswith ('error:' ):
575
576
raise GitCommandError (("Error when fetching: %s" % line ,), 2 )
@@ -589,11 +590,21 @@ def _get_fetch_info_from_stderr(self, proc, progress):
589
590
fetch_head_info = [l .decode (defenc ) for l in fp .readlines ()]
590
591
fp .close ()
591
592
592
- # NOTE: We assume to fetch at least enough progress lines to allow matching each fetch head line with it.
593
593
l_fil = len (fetch_info_lines )
594
594
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
+
597
608
output .extend (FetchInfo ._from_line (self .repo , err_line , fetch_line )
598
609
for err_line , fetch_line in zip (fetch_info_lines , fetch_head_info ))
599
610
return output
@@ -673,8 +684,8 @@ def fetch(self, refspec=None, progress=None, **kwargs):
673
684
else :
674
685
args = [refspec ]
675
686
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 )
678
689
res = self ._get_fetch_info_from_stderr (proc , progress )
679
690
if hasattr (self .repo .odb , 'update_cache' ):
680
691
self .repo .odb .update_cache ()
@@ -692,7 +703,8 @@ def pull(self, refspec=None, progress=None, **kwargs):
692
703
# No argument refspec, then ensure the repo's config has a fetch refspec.
693
704
self ._assert_refspec ()
694
705
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 )
696
708
res = self ._get_fetch_info_from_stderr (proc , progress )
697
709
if hasattr (self .repo .odb , 'update_cache' ):
698
710
self .repo .odb .update_cache ()
@@ -733,7 +745,8 @@ def push(self, refspec=None, progress=None, **kwargs):
733
745
If the operation fails completely, the length of the returned IterableList will
734
746
be null."""
735
747
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 )
737
750
return self ._get_push_info (proc , progress )
738
751
739
752
@property
0 commit comments