switch --force on lightweight checkout connects to original remote branch

Bug #285055 reported by Justyn Butler
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Confirmed
Medium
Unassigned

Bug Description

When switching a lightweight checkout from referencing one remote branch to another (remote or local) branch, bzr attempts to connect to the original branch despite using --force.

This means that if you have a lightweight checkout from a branch on a server that goes down and wish to switch to the branch on the backup server, bzr switch --force will fail.

To recreate:
Create a lightweight checkout from a remote branch over sftp (that you do not have public key authentication for), ie:
    bzr checkout --lightweight sftp://server/path/to/branch

Create a copy of the branch somewhere not on the server (can be local or remote).

Attempt to switch --force to copy of branch
    bzr switch --force sftp://adifferentserver/path/to/branch

Bzr will ask for sftp login for branch you are trying to switch *from* (it will do this after first asking for the sftp login for the branch you are switching to, if it is also remote).

Tested with bzr 1.6.1 and 1.9~bzr8.10-3782-1.

Tags: switch
Revision history for this message
Justyn Butler (justyn) wrote :

It looks like this is the problem, in bzrlib/switch.py.

In the function _check_pending_merges:

    try:
        tree = control.open_workingtree()
    except errors.NotBranchError, ex:
        # Lightweight checkout and branch is no longer there
        if force:
            return
        else:
            raise ex

It always attempts to open the working tree to check for pending merges. If it finds the branch has disappeared and this is a lightweight checkout, it either raises an exception or if --force is used, just ignores it.

The problem is that if the working tree is remote and the server is no longer there/whatever, it fails at the connecting stage. ie with:
"ERROR: Unable to connect to SSH host XXX.XXX.XXX.XXX"

Revision history for this message
Andrew Bennetts (spiv) wrote :

Justyn Butler submitted a patch to the mailing list: <http://bundlebuggy.aaronbentley.com/project/bzr/request/%3Ca6af4cea0810201215p39e72a39h5bbef1977d76dcfc%40mail.gmail.com%3E>

It breaks some tests, so it's not ready for merging yet... but this bug is definitely In Progress.

In the meantime, a workaround for anyone experiencing this would be to manually edit the .bzr/branch/location file.

Changed in bzr:
importance: Undecided → Medium
status: New → In Progress
Revision history for this message
Andrew Bennetts (spiv) wrote :

There's an updated patch at <http://bundlebuggy.aaronbentley.com/project/bzr/request/%3Ca6af4cea0810211117r58da1e68sed434f412f86ab13%40mail.gmail.com%3E>. It still needs more tests, but doesn't seem to break existing tests so this bug is now Fix Committed (using the criteria at <http://bazaar-vcs.org/BugGuidelines>).

Changed in bzr:
status: In Progress → Fix Committed
Revision history for this message
Alexander Belchenko (bialix) wrote :

It seems like this bug completely breaks switch --force if master branch is gone! https://bugs.launchpad.net/bzr/+bug/308798

Connecting twice is not total evil, but inability to switch at all -- is.

Revision history for this message
Alexander Belchenko (bialix) wrote :

The patch from Andrew Bennetts went to resubmit queue. I don't think "Fix Committed" is true anymore.

Changed in bzr:
status: Fix Committed → Confirmed
Jelmer Vernooij (jelmer)
tags: added: switch
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.