##// END OF EJS Templates
subrepo: defer determination of git's current branch
Eric Eisner -
r13152:70d80907 default
parent child Browse files
Show More
@@ -660,6 +660,12 b' class gitsubrepo(abstractsubrepo):'
660 660 def _gitstate(self):
661 661 return self._gitcommand(['rev-parse', 'HEAD'])
662 662
663 def _gitcurrentbranch(self):
664 current, err = self._gitdir(['symbolic-ref', 'HEAD', '--quiet'])
665 if err:
666 current = None
667 return current
668
663 669 def _githavelocally(self, revision):
664 670 out, code = self._gitdir(['cat-file', '-e', revision])
665 671 return code == 0
@@ -670,16 +676,12 b' class gitsubrepo(abstractsubrepo):'
670 676
671 677 def _gitbranchmap(self):
672 678 '''returns 3 things:
673 the current branch,
674 679 a map from git branch to revision
675 a map from revision to branches'''
680 a map from revision to branches
681 a map from remote branch to local tracking branch'''
676 682 branch2rev = {}
677 683 rev2branch = {}
678 684 tracking = {}
679 current, err = self._gitdir(['symbolic-ref', 'HEAD', '--quiet'])
680 if err:
681 current = None
682
683 685 out = self._gitcommand(['for-each-ref', '--format',
684 686 '%(objectname) %(refname) %(upstream) end'])
685 687 for line in out.split('\n'):
@@ -693,7 +695,7 b' class gitsubrepo(abstractsubrepo):'
693 695 if upstream:
694 696 # assumes no more than one local tracking branch for a remote
695 697 tracking[upstream] = ref
696 return current, branch2rev, rev2branch, tracking
698 return branch2rev, rev2branch, tracking
697 699
698 700 def _fetch(self, source, revision):
699 701 if not os.path.exists('%s/.git' % self._path):
@@ -731,7 +733,7 b' class gitsubrepo(abstractsubrepo):'
731 733 return
732 734 elif self._gitstate() == revision:
733 735 return
734 current, branch2rev, rev2branch, tracking = self._gitbranchmap()
736 branch2rev, rev2branch, tracking = self._gitbranchmap()
735 737
736 738 def rawcheckout():
737 739 # no branch to checkout, check it out with no branch
@@ -776,7 +778,7 b' class gitsubrepo(abstractsubrepo):'
776 778 # which is equivalent to updating the local branch to the remote.
777 779 # Since we are only looking at branching at update, we need to
778 780 # detect this situation and perform this action lazily.
779 if tracking[remote] != current:
781 if tracking[remote] != self._gitcurrentbranch():
780 782 self._gitcommand(['checkout', tracking[remote]])
781 783 self._gitcommand(['merge', '--ff', remote])
782 784 else:
@@ -809,7 +811,7 b' class gitsubrepo(abstractsubrepo):'
809 811
810 812 def push(self, force):
811 813 # if a branch in origin contains the revision, nothing to do
812 current, branch2rev, rev2branch, tracking = self._gitbranchmap()
814 branch2rev, rev2branch, tracking = self._gitbranchmap()
813 815 if self._state[1] in rev2branch:
814 816 for b in rev2branch[self._state[1]]:
815 817 if b.startswith('refs/remotes/origin/'):
@@ -822,6 +824,8 b' class gitsubrepo(abstractsubrepo):'
822 824 cmd = ['push']
823 825 if force:
824 826 cmd.append('--force')
827
828 current = self._gitcurrentbranch()
825 829 if current:
826 830 # determine if the current branch is even useful
827 831 if not self._gitisancestor(self._state[1], current):
General Comments 0
You need to be logged in to leave comments. Login now