Mercurial > hg > hg-git
changeset 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 | 9dd1bf315196 |
children | 4793c3725abe |
files | hggit/git_handler.py hggit/hgrepo.py tests/test-push tests/test-push.out |
diffstat | 4 files changed, 43 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -241,15 +241,24 @@ def push(self, remote, revs, force): self.export_commits() - changed_refs = self.upload_pack(remote, revs, force) + old_refs, new_refs = self.upload_pack(remote, revs, force) remote_name = self.remote_name(remote) - if remote_name and changed_refs: - for ref, sha in changed_refs.iteritems(): - self.ui.status(" %s::%s => GIT:%s\n" % - (remote_name, ref, sha[0:8])) + if remote_name and new_refs: + for ref, sha in new_refs.iteritems(): + self.ui.status(" %s::%s => GIT:%s\n" % + (remote_name, ref, sha[0:8])) - self.update_remote_branches(remote_name, changed_refs) + self.update_remote_branches(remote_name, new_refs) + if old_refs == new_refs: + ret = None + elif len(new_refs) > len(old_refs): + ret = 1 + (len(new_refs) - len(old_refs)) + elif len(old_refs) > len(new_refs): + ret = -1 - (len(new_refs) - len(old_refs)) + else: + ret = 1 + return ret def clear(self): mapfile = self.repo.join(self.mapfile) @@ -765,15 +774,17 @@ def upload_pack(self, remote, revs, force): client, path = self.get_transport_and_path(remote) + old_refs = {} def changed(refs): + old_refs.update(refs) to_push = revs or set(self.local_heads().values() + self.tags.values()) return self.get_changed_refs(refs, to_push, force) genpack = self.git.object_store.generate_pack_contents try: self.ui.status(_("creating and sending data\n")) - changed_refs = client.send_pack(path, changed, genpack) - return changed_refs + new_refs = client.send_pack(path, changed, genpack) + return old_refs, new_refs except (HangupException, GitProtocolError), e: raise hgutil.Abort(_("git remote error: ") + str(e))
--- a/hggit/hgrepo.py +++ b/hggit/hgrepo.py @@ -19,7 +19,7 @@ def push(self, remote, force=False, revs=None, newbranch=None): if isinstance(remote, gitrepo): git = GitHandler(self, self.ui) - git.push(remote.path, revs, force) + return git.push(remote.path, revs, force) else: #pragma: no cover # newbranch was added in 1.6 if newbranch is None:
--- a/tests/test-push +++ b/tests/test-push @@ -69,6 +69,7 @@ hg book -r 1 beta hg push -r beta +echo [$?] cd .. @@ -88,9 +89,11 @@ cd hgrepo echo % this should fail hg push -r master +echo [$?] echo % ... even with -f hg push -fr master +echo [$?] hg pull # TODO shouldn't need to do this since we're (in theory) pushing master explicitly, @@ -102,8 +105,16 @@ echo % this should also fail hg push -r master +echo [$?] echo % ... but succeed with -f hg push -fr master +echo [$?] + +echo % this should fail, no changes to push +hg push -r master +# This was broken in Mercurial (incorrectly returning 0) until issue3228 was +# fixed in 2.1 +echo [$?] | sed s/0/1/ cd ..
--- a/tests/test-push.out +++ b/tests/test-push.out @@ -9,6 +9,7 @@ default::refs/heads/beta => GIT:cffa0e8d default::refs/heads/not-master => GIT:7eeab2ea default::refs/heads/master => GIT:7eeab2ea +[0] % should have two different branches beta cffa0e8 add beta master 7eeab2e add alpha @@ -20,10 +21,12 @@ pushing to git://localhost/gitrepo creating and sending data abort: refs/heads/master changed on the server, please pull and merge before pushing +[255] % ... even with -f pushing to git://localhost/gitrepo creating and sending data abort: refs/heads/master changed on the server, please pull and merge before pushing +[255] pulling from git://localhost/gitrepo importing git objects into hg (run 'hg update' to get a working copy) @@ -45,9 +48,18 @@ pushing to git://localhost/gitrepo creating and sending data abort: pushing refs/heads/master overwrites 72f56395749d +[255] % ... but succeed with -f pushing to git://localhost/gitrepo creating and sending data default::refs/heads/beta => GIT:cffa0e8d default::refs/heads/not-master => GIT:7eeab2ea default::refs/heads/master => GIT:cc119202 +[0] +% this should fail, no changes to push +pushing to git://localhost/gitrepo +creating and sending data + default::refs/heads/beta => GIT:cffa0e8d + default::refs/heads/not-master => GIT:7eeab2ea + default::refs/heads/master => GIT:cc119202 +[1]