1. TortoiseHg
  2. TortoiseHg
  3. thg
  4. Issues
Issue #1615 resolved

repeated new branch confirmation on push of multiple heads

John Thomson
created an issue

I have recently created a new local branch of my project. In the workbench or Synchronize tool, when I go to push my changes, I get a dialog asking me to Confirm Push to remote Repository (In the synchronize too, just "Confirm new breanch"). I click Yes. The dialog appears again, and again, and again, as often as I click yes. The only escape seems to be to click No, and my work is not pushed.

I was able to do the commit using the command line (using the command from TortoiseHg and adding -f as suggested), but there seems to be no way to do it in the tool.

I'm using TortoiseHg 2.2.2 on Windows 7 64-bit.

I'm calling this a critical because it completely prevents normal workflow our team uses.

The last few lines of the output log show

% hg --repository D:\Chorus push --new-branch --new-branch http://hg.palaso.org/chorus

pushing to http://hg.palaso.org/chorus

searching for changes

abort: push creates new remote head 8d2cd842d7e8!

hint: did you forget to merge? use push -f to force

[command returned code 255 Mon Feb 13 10:08:40 2012]

% hg --repository D:\Chorus push --new-branch --new-branch --new-branch http://hg.palaso.org/chorus

pushing to http://hg.palaso.org/chorus

searching for changes

abort: push creates new remote head 8d2cd842d7e8!

hint: did you forget to merge? use push -f to force

[command returned code 255 Mon Feb 13 10:08:41 2012]

Comments (15)

  1. Yuya Nishihara
    • changed status to open

    I was able to do the commit using the command line (using the command from TortoiseHg and adding -f as suggested), but there seems to be no way to do it in the tool.

    Maybe what you want is "Force push or pull (override safety checks, --force)" check box in "sync options" dialog?

    FWIW, do you have multiple heads except for named branches?

  2. John Thomson reporter

    That might have worked; certainly doing the push using -f on the command line seemed to fix things.

    I was not aware at the time of having multiple un-named heads, but I'm a beginner using Mercurial, and may have had a couple by accident. I'm sorry, I don't have a backup of the project in the exact state where this happened.

    In any case, I think the tool should be improved. If there is a multiple-head problem and that prevents the push of the new branch, it should tell me so, not keep asking me repeatedly to confirm that I want to push a new branch.

  3. Yuya Nishihara

    If there is a multiple-head problem and that prevents the push of the new branch, it should tell me so, not keep asking me repeatedly to confirm that I want to push a new branch.

    I agree, there's room for improvement, a better message, pointer to multiple heads, etc., maybe.

  4. Anonymous

    I walked around in the code a little and created the following patch that would fix the issue:

    --- a/tortoisehg/hgqt/sync.py
    +++ b/tortoisehg/hgqt/sync.py
    @@ -964,7 +964,9 @@
                                                    'repository?'), parent=self)
                         if r:
                             cmdline = self.lastcmdline
    -                        cmdline.extend(['--new-branch'])
    +                       if '--new-branch' not in cmdline:
    +                            cmdline.extend(['--new-branch'])
    +                        cmdline.extend(['--force'])
                             self.run(cmdline, validopts)
                             return
                 self.pushCompleted.emit()
    

    But here, (at least) three questions remain:

    • Is it ok to just set the --force option? Does that have side effects?
    • Shouldn't we let the user choose if she really wants to use the --force. But if there is a choice, we would have to extend the workflow, saying "Ok, you decided not to do force, now nothing will happen"?
    • Shouldn't we change the workflow instead of using the simple "If not --new-branch, only then add the option"?

    I'm new to the Tortoise code and internals, so this is just a suggestion. I would be glad to create a more elaborate patch, maybe with a little help ;-)

  5. Yuya Nishihara

    It isn't good idea to append --force automatically, because it will create multiple heads in remote repository. Instead I prefer to have sync operation fail.

    Expert user can add --force option from options dialog.

  6. Anonymous

    Hello, I reworked my patches. I changed the first patch so it only fixes the repeated appending of the '--new-branch' option:

    # HG changeset patch
    # User schueler <nikolaus.schueler@lantiq.com>
    # Date 1341566836 -7200
    # Branch lantiq
    # Node ID b4042d8c81ac7928b2a9ac3603c71d0fb863daa4
    # Parent  44bbf8918ca8c915754c8b372c69a123cf764dce
    imported patch HGSUP-663.patch
    
    diff --git a/tortoisehg/hgqt/sync.py b/tortoisehg/hgqt/sync.py
    --- a/tortoisehg/hgqt/sync.py
    +++ b/tortoisehg/hgqt/sync.py
    @@ -964,7 +964,10 @@
                                                    'repository?'), parent=self)
                         if r:
                             cmdline = self.lastcmdline
    -                        cmdline.extend(['--new-branch'])
    +                        # We may come here several times, so only add
    +                        # '--new-branch' the first time
    +                        if '--new-branch' not in cmdline:
    +                            cmdline.extend(['--new-branch'])
                             self.run(cmdline, validopts)
                             return
                 self.pushCompleted.emit()
    

    The second patch shows a popup that hints at what to do to fix the problem. If the basic idea is ok for you, I could refine the patch. In the moment it just copies the message from the error console, the title of the windows is just a fixed string. If the patch would be accepted, we should change the QMessageBox to take the message from the i18n files.

    # HG changeset patch
    # User schueler <nikolaus.schueler@lantiq.com>
    # Date 1341580561 -7200
    # Branch lantiq
    # Node ID 76fee99038d0ad48ea0df4d19d65ebef9b53643a
    # Parent  b4042d8c81ac7928b2a9ac3603c71d0fb863daa4
    [mq]: messagebox.patch
    
    diff --git a/tortoisehg/hgqt/sync.py b/tortoisehg/hgqt/sync.py
    --- a/tortoisehg/hgqt/sync.py
    +++ b/tortoisehg/hgqt/sync.py
    @@ -728,6 +728,14 @@
         def outputHook(self, msg, label):
             if '\'hg push --new-branch\'' in msg:
                 self.needNewBranch = True
    +
    +        if 'hint: you should pull and merge' in msg:
    +            self.needPullAndMerge = True
    +            self.needPullAndMergeMessage = msg
    +
    +        if 'hint: did you forget to merge?' in msg:
    +            self.needPullAndMerge = True
    +            self.needPullAndMergeMessage = msg
    
         ##
         ## Workbench toolbar buttons
    @@ -955,6 +963,10 @@
                     self.showMessage.emit(_('Push to %s completed') % urlu)
                 else:
                     self.showMessage.emit(_('Push to %s aborted, ret %d') % (urlu,
    ret))
    +                if self.needPullAndMerge:
    +                    r = qtlib.QMessageBox.warning(self, _('Pull and Merge'),
    +                                             self.needPullAndMergeMessage)
    +                    return
                     if self.needNewBranch:
                         r = qtlib.QuestionMsgBox(_('Confirm New Branch'),
                                                  _('One or more of the changesets t
    hat you '
    @@ -996,6 +1008,7 @@
             if branch:
                 cmdline.extend(['--branch', branch])
             self.needNewBranch = False
    +        self.needPullAndMerge = False
             self.run(cmdline, validopts)
    
         def postpullclicked(self):
    
  7. Yuya Nishihara
    --- a/tortoisehg/hgqt/sync.py
    +++ b/tortoisehg/hgqt/sync.py
    @@ -964,7 +964,10 @@
                                                    'repository?'), parent=self)
                         if r:
                             cmdline = self.lastcmdline
    -                        cmdline.extend(['--new-branch'])
    +                        # We may come here several times, so only add
    +                        # '--new-branch' the first time
    +                        if '--new-branch' not in cmdline:
    +                            cmdline.extend(['--new-branch'])
    

    I guess "new branch" confirmation isn't necessary if cmdline already contains --new-branch. So I'm going to add and '--new-branch' not in self.lastcmdline to if self.needNewBranch instead.

    Do you have any other idea?


    @@ -728,6 +728,14 @@
         def outputHook(self, msg, label):
             if '\'hg push --new-branch\'' in msg:
                 self.needNewBranch = True
    +
    +        if 'hint: you should pull and merge' in msg:
    +            self.needPullAndMerge = True
    +            self.needPullAndMergeMessage = msg
    +
    +        if 'hint: did you forget to merge?' in msg:
    +            self.needPullAndMerge = True
    +            self.needPullAndMergeMessage = msg
    

    It's nice to show hint, but it doesn't work if the message is translated. Also, the same message should be displayed in red information bar.

  8. Anonymous

    Hi,

    "So I'm going to add and '--new-branch' not in self.lastcmdline to if self.needNewBranch instead. Do you have any other idea?"

    No, I think that's fine.

    About the hint: You're right that it fails when the message is translated. I will think about another way to find out when the hint is needed. And I will show it in the red information bar too.

    So, we could already use the '--new-branch' part and add the hint in a second change, ok?

  9. Yuya Nishihara

    I will think about another way to find out when the hint is needed. And I will show it in the red information bar too.

    Do you mean you want to hide some "hint" message comes from Mercurial? or show additional hints?

  10. Anonymous

    I don't want to hide the hint message. I would like to show an additional popup that advises the user at the situation and tells him what to do.

  11. Yuya Nishihara

    I would like to show an additional popup that advises the user at the situation and tells him what to do.

    If that advice is not long, it may be easier to refine "hint" message of Mercurial core.

  12. Anonymous

    Hello Yuya,

    I talked back to the user that originally reported the problem at our company and he is ok with the current solution. His main concern was that you end up in an infinite loop and this is fixed now. So I would see we can leave it as it is.

    Thanks a lot for your support.

    Nik

  13. Log in to comment