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