Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 13553:dea6efdd7ec4 stable
subrepo: don't crash when git repo is missing
author | Eric Eisner <ede@mit.edu> |
---|---|
date | Mon, 07 Mar 2011 12:03:54 -0500 |
parents | 67fbe566eff1 |
children | f854b775c386 42a34c0aeddc |
comparison
equal
deleted
inserted
replaced
13552:7ab85fec60c3 | 13553:dea6efdd7ec4 |
---|---|
701 raise util.Abort('git %s error %d in %s' % | 701 raise util.Abort('git %s error %d in %s' % |
702 (command, p.returncode, self._relpath)) | 702 (command, p.returncode, self._relpath)) |
703 | 703 |
704 return retdata, p.returncode | 704 return retdata, p.returncode |
705 | 705 |
706 def _gitmissing(self): | |
707 return not os.path.exists(os.path.join(self._abspath, '.git')) | |
708 | |
706 def _gitstate(self): | 709 def _gitstate(self): |
707 return self._gitcommand(['rev-parse', 'HEAD']) | 710 return self._gitcommand(['rev-parse', 'HEAD']) |
708 | 711 |
709 def _gitcurrentbranch(self): | 712 def _gitcurrentbranch(self): |
710 current, err = self._gitdir(['symbolic-ref', 'HEAD', '--quiet']) | 713 current, err = self._gitdir(['symbolic-ref', 'HEAD', '--quiet']) |
757 def _abssource(self, source): | 760 def _abssource(self, source): |
758 self._subsource = source | 761 self._subsource = source |
759 return _abssource(self) | 762 return _abssource(self) |
760 | 763 |
761 def _fetch(self, source, revision): | 764 def _fetch(self, source, revision): |
762 if not os.path.exists(os.path.join(self._abspath, '.git')): | 765 if self._gitmissing(): |
763 self._ui.status(_('cloning subrepo %s\n') % self._relpath) | 766 self._ui.status(_('cloning subrepo %s\n') % self._relpath) |
764 self._gitnodir(['clone', self._abssource(source), self._abspath]) | 767 self._gitnodir(['clone', self._abssource(source), self._abspath]) |
765 if self._githavelocally(revision): | 768 if self._githavelocally(revision): |
766 return | 769 return |
767 self._ui.status(_('pulling subrepo %s\n') % self._relpath) | 770 self._ui.status(_('pulling subrepo %s\n') % self._relpath) |
770 if not self._githavelocally(revision): | 773 if not self._githavelocally(revision): |
771 raise util.Abort(_("revision %s does not exist in subrepo %s\n") % | 774 raise util.Abort(_("revision %s does not exist in subrepo %s\n") % |
772 (revision, self._relpath)) | 775 (revision, self._relpath)) |
773 | 776 |
774 def dirty(self, ignoreupdate=False): | 777 def dirty(self, ignoreupdate=False): |
778 if self._gitmissing(): | |
779 return True | |
775 if not ignoreupdate and self._state[1] != self._gitstate(): | 780 if not ignoreupdate and self._state[1] != self._gitstate(): |
776 # different version checked out | 781 # different version checked out |
777 return True | 782 return True |
778 # check for staged changes or modified files; ignore untracked files | 783 # check for staged changes or modified files; ignore untracked files |
779 out, code = self._gitdir(['diff-index', '--quiet', 'HEAD']) | 784 out, code = self._gitdir(['diff-index', '--quiet', 'HEAD']) |
858 else: | 863 else: |
859 # a real merge would be required, just checkout the revision | 864 # a real merge would be required, just checkout the revision |
860 rawcheckout() | 865 rawcheckout() |
861 | 866 |
862 def commit(self, text, user, date): | 867 def commit(self, text, user, date): |
868 if self._gitmissing(): | |
869 raise util.Abort(_("subrepo %s is missing") % self._relpath) | |
863 cmd = ['commit', '-a', '-m', text] | 870 cmd = ['commit', '-a', '-m', text] |
864 env = os.environ.copy() | 871 env = os.environ.copy() |
865 if user: | 872 if user: |
866 cmd += ['--author', user] | 873 cmd += ['--author', user] |
867 if date: | 874 if date: |
894 mergefunc() | 901 mergefunc() |
895 else: | 902 else: |
896 mergefunc() | 903 mergefunc() |
897 | 904 |
898 def push(self, force): | 905 def push(self, force): |
906 if self._gitmissing(): | |
907 raise util.Abort(_("subrepo %s is missing") % self._relpath) | |
899 # if a branch in origin contains the revision, nothing to do | 908 # if a branch in origin contains the revision, nothing to do |
900 branch2rev, rev2branch = self._gitbranchmap() | 909 branch2rev, rev2branch = self._gitbranchmap() |
901 if self._state[1] in rev2branch: | 910 if self._state[1] in rev2branch: |
902 for b in rev2branch[self._state[1]]: | 911 for b in rev2branch[self._state[1]]: |
903 if b.startswith('refs/remotes/origin/'): | 912 if b.startswith('refs/remotes/origin/'): |
927 'cannot push revision %s') % | 936 'cannot push revision %s') % |
928 (self._relpath, self._state[1])) | 937 (self._relpath, self._state[1])) |
929 return False | 938 return False |
930 | 939 |
931 def remove(self): | 940 def remove(self): |
941 if self._gitmissing(): | |
942 return | |
932 if self.dirty(): | 943 if self.dirty(): |
933 self._ui.warn(_('not removing repo %s because ' | 944 self._ui.warn(_('not removing repo %s because ' |
934 'it has changes.\n') % self._relpath) | 945 'it has changes.\n') % self._relpath) |
935 return | 946 return |
936 # we can't fully delete the repository as it may contain | 947 # we can't fully delete the repository as it may contain |
970 unit=_('files')) | 981 unit=_('files')) |
971 ui.progress(_('archiving (%s)') % relpath, None) | 982 ui.progress(_('archiving (%s)') % relpath, None) |
972 | 983 |
973 | 984 |
974 def status(self, rev2, **opts): | 985 def status(self, rev2, **opts): |
986 if self._gitmissing(): | |
987 # if the repo is missing, return no results | |
988 return [], [], [], [], [], [], [] | |
975 rev1 = self._state[1] | 989 rev1 = self._state[1] |
976 modified, added, removed = [], [], [] | 990 modified, added, removed = [], [], [] |
977 if rev2: | 991 if rev2: |
978 command = ['diff-tree', rev1, rev2] | 992 command = ['diff-tree', rev1, rev2] |
979 else: | 993 else: |