##// END OF EJS Templates
subrepo: lazier git push logic...
Eric Eisner -
r13029:f930032a default
parent child Browse files
Show More
@@ -665,6 +665,10 b' class gitsubrepo(object):'
665 out, code = self._gitdir(['cat-file', '-e', revision])
665 out, code = self._gitdir(['cat-file', '-e', revision])
666 return code == 0
666 return code == 0
667
667
668 def _gitisancestor(self, r1, r2):
669 base = self._gitcommand(['merge-base', r1, r2]).strip()
670 return base == r1
671
668 def _gitbranchmap(self):
672 def _gitbranchmap(self):
669 'returns the current branch and a map from git revision to branch[es]'
673 'returns the current branch and a map from git revision to branch[es]'
670 bm = {}
674 bm = {}
@@ -767,17 +771,31 b' class gitsubrepo(object):'
767 self._gitcommand(['merge', '--no-commit', revision])
771 self._gitcommand(['merge', '--no-commit', revision])
768
772
769 def push(self, force):
773 def push(self, force):
774 # if a branch in origin contains the revision, nothing to do
775 current, bm = self._gitbranchmap()
776 for revision, branches in bm.iteritems():
777 for b in branches:
778 if b.startswith('remotes/origin'):
779 if self._gitisancestor(self._state[1], revision):
780 return True
781 # otherwise, try to push the currently checked out branch
770 cmd = ['push']
782 cmd = ['push']
771 if force:
783 if force:
772 cmd.append('--force')
784 cmd.append('--force')
773 # push the currently checked out branch
774 current, bm = self._gitbranchmap()
775 if current:
785 if current:
786 # determine if the current branch is even useful
787 if not self._gitisancestor(self._state[1], current):
788 self._ui.warn(_('unrelated git branch checked out '
789 'in subrepo %s\n') % self._relpath)
790 return False
791 self._ui.status(_('pushing branch %s of subrepo %s\n') %
792 (current, self._relpath))
776 self._gitcommand(cmd + ['origin', current, '-q'])
793 self._gitcommand(cmd + ['origin', current, '-q'])
777 return True
794 return True
778 else:
795 else:
779 self._ui.warn(_('no branch checked out in subrepo %s\n'
796 self._ui.warn(_('no branch checked out in subrepo %s\n'
780 'nothing to push') % self._relpath)
797 'cannot push revision %s') %
798 (self._relpath, self._state[1]))
781 return False
799 return False
782
800
783 def remove(self):
801 def remove(self):
@@ -134,6 +134,7 b' user b push changes'
134
134
135 $ hg push
135 $ hg push
136 pushing to $TESTTMP/t
136 pushing to $TESTTMP/t
137 pushing branch testing of subrepo s
137 searching for changes
138 searching for changes
138 adding changesets
139 adding changesets
139 adding manifests
140 adding manifests
@@ -170,12 +171,44 b' user a pulls, merges, commits'
170 revision f47b465e1bce645dbf37232a00574aa1546ca8d3
171 revision f47b465e1bce645dbf37232a00574aa1546ca8d3
171 $ hg push
172 $ hg push
172 pushing to $TESTTMP/t
173 pushing to $TESTTMP/t
174 pushing branch testing of subrepo s
173 searching for changes
175 searching for changes
174 adding changesets
176 adding changesets
175 adding manifests
177 adding manifests
176 adding file changes
178 adding file changes
177 added 2 changesets with 2 changes to 1 files
179 added 2 changesets with 2 changes to 1 files
178
180
181 make upstream git changes
182
183 $ cd ..
184 $ git clone -q gitroot gitclone
185 $ cd gitclone
186 $ echo ff >> f
187 $ git commit -q -a -m ff
188 $ echo fff >> f
189 $ git commit -q -a -m fff
190 $ git push -q origin testing
191
192 make and push changes to hg without updating the subrepo
193
194 $ cd ../t
195 $ hg clone . ../td
196 updating to branch default
197 cloning subrepo s
198 checking out detached HEAD in subrepo s
199 check out a git branch if you intend to make changes
200 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
201 $ cd ../td
202 $ echo aa >> a
203 $ hg commit -m aa
204 $ hg push
205 pushing to $TESTTMP/t
206 searching for changes
207 adding changesets
208 adding manifests
209 adding file changes
210 added 1 changesets with 1 changes to 1 files
211
179 update to a revision without the subrepo, keeping the local git repository
212 update to a revision without the subrepo, keeping the local git repository
180
213
181 $ cd ../t
214 $ cd ../t
General Comments 0
You need to be logged in to leave comments. Login now