This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 198237 - Prevent accidental branch merges
Summary: Prevent accidental branch merges
Status: STARTED
Alias: None
Product: www
Classification: Unclassified
Component: Builds & Repositories (show other bugs)
Version: 7.0.1
Hardware: All All
: P2 normal (vote)
Assignee: pgebauer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-02 08:24 UTC by Jesse Glick
Modified: 2011-05-02 09:50 UTC (History)
5 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2011-05-02 08:24:32 UTC
Occasionally a Mercurial branch is merged unintentionally, due to some mistake in command-line usage. This happened recently with the post70 branch in a08b791f2301 (reason unknown; Hg 1.4.3), and with the html5parser branch in Jul 2010 (apparently due to use of very old Hg 1.0). phejl suggested the following local hook after the html5parser problem:

def precommit_branch_merge(ui, repo, parent1=None, parent2=None, **kwargs):
    if not parent2:
        # Not merging: nothing more to check.
        return False
    # Check for backwards merge. Source branch must be the default one.
    if repo[parent2].branch() != "default":
        ui.warn('merge from non default branch %r to %r\n'
                % (repo[parent2].branch(), repo[parent1].branch()))
        return True
    return False

though this is only a warning and only useful when the developer has set this up locally, which does nothing to prevent other people with push access from making the mistake.

The simplest server hook I can think of is one which rejects a new head for 'default' which contains a file '.do-not-merge-yet' (at top level). Then, when creating an experimental branch (or sometime thereafter in the branch, as soon as you think of it), just commit a file with this name - it could be empty, or give some explanation. This will prevent anyone from accidentally pushing a merge of your branch into trunk. If and when you decide the branch is really stable and ready to merge, simply delete the file (in the branch before the merge, or in trunk after) and the server will accept it. If you forget to delete the file and your push is rejected, just delete it now, commit, and try to push again.

Something similar may be useful to ensure that no one accidentally merges default into a release branch. Perhaps a file .hgforbidden could be created in trunk with the text contents "release70\n" (at least), indicating that it is forbidden to merge default into release70. When creating a dev branch, just append "default\n" to the file, and remove that when merging it.

I can try to write a hook that would do this.
Comment 1 Jesse Glick 2011-05-02 09:50:09 UTC
nb-hooks #dbd11cd86646 adds forbidmerge.py which should accomplish this. Tested on dummy repositories and seems to work as expected. Once the hook is registered for all pushable repos on hg.netbeans.org, I can create .hgforbidmerge files in appropriate branches. http://mercurial.selenic.com/wiki/PublishingExtensions may be a good idea if the hook proves its value.