fails to check duplicate branches if leading/trailing spaces exist

Issue #2568 resolved
Steve Spencer
created an issue

We have a closed branch. We shouldn't be able to create a new branch with the same name - and the command line requires "-f" to authorise this. But workbench allows it without a prompt.

Admittedly pushing this to a central repo is typically denied due to multiple heads, but the "-f" option is there presumably because it's bad practice.

Comments (7)

  1. Angel Ezquerra

    I'm a bit confused. TortoiseHg should show you a confirmation message... Note that this does not happen when you select the branch, but when you commit, because TortoiseHg mimics mercurials branch command, which only selects the branch of the next commit...

  2. Steve Spencer reporter

    Got it. It's a trailing space from my copy and paste (when dragging back across the branch name in the changeset info). Mercurial must trim the space at some point before storing the transaction, but Tortoise doesn't when checking.

    Here's what I did:

    1. Find a closed branch, called "Feature/Xyz". Copy name.

    2. Update to default tip

    3. In working directory view, Branch: Open a new branch, paste name, enter message, and commit (no other changes in WD)

    4. Confirm new branch (no warnings about name already existing)

    5. In revision list, filter by this branch. You'll see the two heads, one closed.

    I repeated this, carefully removing the trailing space, and this time saw the warning on commit.

    Are you using the API to commit the branch? If so, as well as trimming in Tortoise, shouldn't the underlying API require some kind of force parameter (a double-check)?

  3. Steve Spencer reporter

    Note that, after seeing warning on commit, and choosing "Restart branch" (which I believe creates unpushable two heads - could do with a better warning) -

    if I "Rollback/Undo" and then commit again, I don't get the warning.

  4. Yuya Nishihara

    Mercurial must trim the space at some point before storing the transaction, but Tortoise doesn't when checking.

    Mercurial does trim it at dirstate._branch(), but not in branch command. So both Mercurial and TortoiseHg has the same issue. (In your case, probably cmd.exe would trim white-spaces.)

    % hg branch foo
    % hg ci -m 'branch foo'
    % hg ci --close-branch -m 'close branch foo'
    rejects successfully:
    % hg branch foo
    abort: a branch of the same name already exists
    (use 'hg update' to switch to it)
    oops! no error:
    % hg branch " foo "
    marked working directory as branch  foo
    (branches are permanent and global, did you want a bookmark?)
    % hg ci -m 'branch foo with space'
    but the branch name is "foo", not " foo ":
    % hg glog
    @  3 tip :0 foo 3cff75aaacbc
    |    branch foo with space
    | o  2 foo 21e8b08b9fcb
    | |    close branch foo
    | |
    | o  1 foo bf9da76edc93
    |/     branch foo
  5. Log in to comment