comparison mercurial/subrepo.py @ 13324:e5617047c926

subrepo: make update -C clean the working directory for git subrepos This makes 'hg update --clean' behave the same way for all three kinds of subrepositories [hg, svn, git]. Before git subrepos did not take the clean parameter into account, but just updated to the given revision and merged uncommitted changes into that.
author Erik Zielke <ez@aragost.com>
date Mon, 31 Jan 2011 13:40:05 +0100
parents d8d478f9ee0f
children 7ebdfa37842e
comparison
equal deleted inserted replaced
13323:d8d478f9ee0f 13324:e5617047c926
759 self._gitcommand(['config', 'core.bare', 'false']) 759 self._gitcommand(['config', 'core.bare', 'false'])
760 if self._gitstate() == revision: 760 if self._gitstate() == revision:
761 self._gitcommand(['reset', '--hard', 'HEAD']) 761 self._gitcommand(['reset', '--hard', 'HEAD'])
762 return 762 return
763 elif self._gitstate() == revision: 763 elif self._gitstate() == revision:
764 if overwrite:
765 # first reset the index to unmark new files for commit, because
766 # reset --hard will otherwise throw away files added for commit,
767 # not just unmark them.
768 self._gitcommand(['reset', 'HEAD'])
769 self._gitcommand(['reset', '--hard', 'HEAD'])
764 return 770 return
765 branch2rev, rev2branch = self._gitbranchmap() 771 branch2rev, rev2branch = self._gitbranchmap()
772
773 def checkout(args):
774 cmd = ['checkout']
775 if overwrite:
776 # first reset the index to unmark new files for commit, because
777 # the -f option will otherwise throw away files added for
778 # commit, not just unmark them.
779 self._gitcommand(['reset', 'HEAD'])
780 cmd.append('-f')
781 self._gitcommand(cmd + args)
766 782
767 def rawcheckout(): 783 def rawcheckout():
768 # no branch to checkout, check it out with no branch 784 # no branch to checkout, check it out with no branch
769 self._ui.warn(_('checking out detached HEAD in subrepo %s\n') % 785 self._ui.warn(_('checking out detached HEAD in subrepo %s\n') %
770 self._relpath) 786 self._relpath)
771 self._ui.warn(_('check out a git branch if you intend ' 787 self._ui.warn(_('check out a git branch if you intend '
772 'to make changes\n')) 788 'to make changes\n'))
773 self._gitcommand(['checkout', '-q', revision]) 789 checkout(['-q', revision])
774 790
775 if revision not in rev2branch: 791 if revision not in rev2branch:
776 rawcheckout() 792 rawcheckout()
777 return 793 return
778 branches = rev2branch[revision] 794 branches = rev2branch[revision]
779 firstlocalbranch = None 795 firstlocalbranch = None
780 for b in branches: 796 for b in branches:
781 if b == 'refs/heads/master': 797 if b == 'refs/heads/master':
782 # master trumps all other branches 798 # master trumps all other branches
783 self._gitcommand(['checkout', 'refs/heads/master']) 799 checkout(['refs/heads/master'])
784 return 800 return
785 if not firstlocalbranch and not b.startswith('refs/remotes/'): 801 if not firstlocalbranch and not b.startswith('refs/remotes/'):
786 firstlocalbranch = b 802 firstlocalbranch = b
787 if firstlocalbranch: 803 if firstlocalbranch:
788 self._gitcommand(['checkout', firstlocalbranch]) 804 checkout([firstlocalbranch])
789 return 805 return
790 806
791 tracking = self._gittracking(branch2rev.keys()) 807 tracking = self._gittracking(branch2rev.keys())
792 # choose a remote branch already tracked if possible 808 # choose a remote branch already tracked if possible
793 remote = branches[0] 809 remote = branches[0]
798 break 814 break
799 815
800 if remote not in tracking: 816 if remote not in tracking:
801 # create a new local tracking branch 817 # create a new local tracking branch
802 local = remote.split('/', 2)[2] 818 local = remote.split('/', 2)[2]
803 self._gitcommand(['checkout', '-b', local, remote]) 819 checkout(['-b', local, remote])
804 elif self._gitisancestor(branch2rev[tracking[remote]], remote): 820 elif self._gitisancestor(branch2rev[tracking[remote]], remote):
805 # When updating to a tracked remote branch, 821 # When updating to a tracked remote branch,
806 # if the local tracking branch is downstream of it, 822 # if the local tracking branch is downstream of it,
807 # a normal `git pull` would have performed a "fast-forward merge" 823 # a normal `git pull` would have performed a "fast-forward merge"
808 # which is equivalent to updating the local branch to the remote. 824 # which is equivalent to updating the local branch to the remote.
809 # Since we are only looking at branching at update, we need to 825 # Since we are only looking at branching at update, we need to
810 # detect this situation and perform this action lazily. 826 # detect this situation and perform this action lazily.
811 if tracking[remote] != self._gitcurrentbranch(): 827 if tracking[remote] != self._gitcurrentbranch():
812 self._gitcommand(['checkout', tracking[remote]]) 828 checkout([tracking[remote]])
813 self._gitcommand(['merge', '--ff', remote]) 829 self._gitcommand(['merge', '--ff', remote])
814 else: 830 else:
815 # a real merge would be required, just checkout the revision 831 # a real merge would be required, just checkout the revision
816 rawcheckout() 832 rawcheckout()
817 833