Switch branches in colocated git repository looses uncommitted changes without warnings

Bug #1820606 reported by Fred McCann on 2019-03-18
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Jelmer Vernooij

Bug Description

Take the following example:

fmccann@hobbes ~/Desktop> bzr init --git repository
Created a standalone tree (format: git)
fmccann@hobbes ~/Desktop> cd repository/
fmccann@hobbes ~/D/repository (master)> touch file.txt
fmccann@hobbes ~/D/repository (master)> bzr add
adding file.txt
fmccann@hobbes ~/D/repository (master)> bzr commit -m"initial import"
Committing to: /Users/fmccann/Desktop/repository/
added file.txt
Committed revision 1.
fmccann@hobbes ~/D/repository (master)> echo "entered on master branch" > file.txt
fmccann@hobbes ~/D/repository (master)> bzr stat

We create a new git repository with one file. The file has an uncommitted change. Next, we switch to a new branch:

fmccann@hobbes ~/D/repository (master)> bzr switch -b other
Tree is up to date at revision 1.
Switched to branch other

There's no warning that there are uncommitted changes before the switch. Furthermore, it looks like the changes are actually lost:

fmccann@hobbes ~/D/repository (other)> cat file.txt
fmccann@hobbes ~/D/repository (other)>

Now, add a change to the file in the other branch:

fmccann@hobbes ~/D/repository (other)> echo "entered on other branch" > file.txt
fmccann@hobbes ~/D/repository (other)> bzr stat

And then switch to another branch:

fmccann@hobbes ~/D/repository (other)> bzr switch master
Tree is up to date at revision 1.
Switched to branch master
fmccann@hobbes ~/D/repository (master)> cat file.txt
entered on other branch

In this case, the uncommitted change remains. This is better than the first example where the change was lost, but this is still not ideal.

I think the best behavior is that Breezy should automatically stage and unstage uncommitted changes when switching colocated branches, and show a notice that it is doing so. This is the safest and most user friendly option.

Failing that, Breezy should at least show a warning that there are uncommitted changes in the working tree and refuse to switch branches short of using some --force option so the user is at least alerted to the issue and the tool won't do anything unsafe that would lose changes or accidentally carry changes into a new branch.

This example is on macOS 10.14.3 (18D109) using Breezy 3.0.0 installed via Homebrew.

Tags: git Edit Tag help

Related branches

Jelmer Vernooij (jelmer) on 2019-03-24
Changed in brz:
status: New → Triaged
importance: Undecided → Critical
assignee: nobody → Jelmer Vernooij (jelmer)
milestone: none → 3.0.1
Jelmer Vernooij (jelmer) wrote :

This issue is specific to the git implementation of Breezy; I can reproduce the problem you mention when I initialize with "bzr init --git repo" but not when I initialize with "bzr init --bzr repo".

tags: added: git
Jelmer Vernooij (jelmer) on 2019-04-13
Changed in brz:
status: Triaged → In Progress
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers