comparison hggit/git_handler.py @ 487:68e5dddc7a20

push: return 1 if no changes found, 0 if success While working on some other tests, I noticed that the push command was returning exit code 1 on success. This changeset makes hgrepo.push use the same return code contract as localrepo.push, which makes the exit codes behave as expected.
author David M. Carr <david@carrclan.us>
date Wed, 05 Sep 2012 23:27:31 -0400
parents 03d8e33bf776
children 4793c3725abe
comparison
equal deleted inserted replaced
486:9dd1bf315196 487:68e5dddc7a20
239 except (HangupException, GitProtocolError), e: 239 except (HangupException, GitProtocolError), e:
240 raise hgutil.Abort(_("git remote error: ") + str(e)) 240 raise hgutil.Abort(_("git remote error: ") + str(e))
241 241
242 def push(self, remote, revs, force): 242 def push(self, remote, revs, force):
243 self.export_commits() 243 self.export_commits()
244 changed_refs = self.upload_pack(remote, revs, force) 244 old_refs, new_refs = self.upload_pack(remote, revs, force)
245 remote_name = self.remote_name(remote) 245 remote_name = self.remote_name(remote)
246 246
247 if remote_name and changed_refs: 247 if remote_name and new_refs:
248 for ref, sha in changed_refs.iteritems(): 248 for ref, sha in new_refs.iteritems():
249 self.ui.status(" %s::%s => GIT:%s\n" % 249 self.ui.status(" %s::%s => GIT:%s\n" %
250 (remote_name, ref, sha[0:8])) 250 (remote_name, ref, sha[0:8]))
251 251
252 self.update_remote_branches(remote_name, changed_refs) 252 self.update_remote_branches(remote_name, new_refs)
253 if old_refs == new_refs:
254 ret = None
255 elif len(new_refs) > len(old_refs):
256 ret = 1 + (len(new_refs) - len(old_refs))
257 elif len(old_refs) > len(new_refs):
258 ret = -1 - (len(new_refs) - len(old_refs))
259 else:
260 ret = 1
261 return ret
253 262
254 def clear(self): 263 def clear(self):
255 mapfile = self.repo.join(self.mapfile) 264 mapfile = self.repo.join(self.mapfile)
256 if os.path.exists(self.gitdir): 265 if os.path.exists(self.gitdir):
257 for root, dirs, files in os.walk(self.gitdir, topdown=False): 266 for root, dirs, files in os.walk(self.gitdir, topdown=False):
763 772
764 ## PACK UPLOADING AND FETCHING 773 ## PACK UPLOADING AND FETCHING
765 774
766 def upload_pack(self, remote, revs, force): 775 def upload_pack(self, remote, revs, force):
767 client, path = self.get_transport_and_path(remote) 776 client, path = self.get_transport_and_path(remote)
777 old_refs = {}
768 def changed(refs): 778 def changed(refs):
779 old_refs.update(refs)
769 to_push = revs or set(self.local_heads().values() + self.tags.values()) 780 to_push = revs or set(self.local_heads().values() + self.tags.values())
770 return self.get_changed_refs(refs, to_push, force) 781 return self.get_changed_refs(refs, to_push, force)
771 782
772 genpack = self.git.object_store.generate_pack_contents 783 genpack = self.git.object_store.generate_pack_contents
773 try: 784 try:
774 self.ui.status(_("creating and sending data\n")) 785 self.ui.status(_("creating and sending data\n"))
775 changed_refs = client.send_pack(path, changed, genpack) 786 new_refs = client.send_pack(path, changed, genpack)
776 return changed_refs 787 return old_refs, new_refs
777 except (HangupException, GitProtocolError), e: 788 except (HangupException, GitProtocolError), e:
778 raise hgutil.Abort(_("git remote error: ") + str(e)) 789 raise hgutil.Abort(_("git remote error: ") + str(e))
779 790
780 def get_changed_refs(self, refs, revs, force): 791 def get_changed_refs(self, refs, revs, force):
781 new_refs = refs.copy() 792 new_refs = refs.copy()