Bug 4223 - hg push does not fail in case of git subrepo push failure
Summary: hg push does not fail in case of git subrepo push failure
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: 2.9.2
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-11 06:55 UTC by Pavlo Shkrabliuk
Modified: 2014-07-19 14:17 UTC (History)
3 users (show)

See Also:
Python Version: ---


Attachments
test repos (62.20 KB, application/zip)
2014-04-11 06:55 UTC, Pavlo Shkrabliuk
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pavlo Shkrabliuk 2014-04-11 06:55 UTC
Created attachment 1761 [details]
test repos

Main repo push should fail if git subrepo push fails.

Now it's not so, see log below for example:
hg push
pushing to https://hg.example.com/mainrepo
...
pushing branch master of subrepo Dependencies/gitsubrepo
To https://hg.example.com/gitsubrepo.git
 ! [rejected]        master -> master (fetch first)                               <----- failure
error: failed to push some refs to 'https://hg.example.com/gitsubrepo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
...
searching for changes
remote: Repository size .hg:994.2 MB repo:255.0 MB total:1.2 GB
remote: Last revision is now r24557:76c0aae10e55                                  <----- success


To my mind, this is rather serious issue, as it leaves main repo in inconsistent state – .hgsubstate points to the commit in subrepo that is not available at remote server.
I also believe that it must fail, as it does fail if hg subrepo push fails.

To reproduce the issue, you can find test.zip in attachment. Try to push from 'loc_hg' directory.
Comment 1 Matt Mackall 2014-04-11 15:37 UTC
Try this patch, please:

diff -r c3712005cfc1 mercurial/subrepo.py
--- a/mercurial/subrepo.py	Fri Apr 04 17:50:44 2014 -0700
+++ b/mercurial/subrepo.py	Fri Apr 11 15:36:54 2014 -0400
@@ -1463,8 +1463,8 @@
                 return False
             self._ui.status(_('pushing branch %s of subrepo %s\n') %
                             (current.split('/', 2)[2], self._relpath))
-            self._gitcommand(cmd + ['origin', current])
-            return True
+            ret = self._gitdir(cmd + ['origin', current])
+            return ret[1] == 0
         else:
             self._ui.warn(_('no branch checked out in subrepo %s\n'
                             'cannot push revision %s\n') %
Comment 2 HG Bot 2014-04-11 17:00 UTC
Fixed by http://selenic.com/repo/hg/rev/70312c95f2f7
Matt Mackall <mpm@selenic.com>
subrepo: check return code for git push (issue4223)

(please test the fix)
Comment 3 Pavlo Shkrabliuk 2014-04-14 06:09 UTC
Yes, the patch does stop main repo push.

However, there is still an issue – 'hg push' exits with 0 (zero) in case of git subrepo push failure.
In case of mercurial subrepo push failure 'hg push' exits with 127.
Comment 4 Matt Mackall 2014-04-16 13:37 UTC
Please test:

changeset:   21488:693b4cb4330f
user:        Matt Mackall <mpm@selenic.com>
date:        Tue Apr 15 14:15:35 2014 -0400
files:       mercurial/commands.py
description:
subrepo: return non-zero exit code when a subrepo push doesn't succeed
Comment 5 Pavlo Shkrabliuk 2014-04-17 04:15 UTC
Works perfectly now! Thank you!