Switch branches in colocated git repository looses uncommitted changes without warnings
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Breezy |
Fix Released
|
Critical
|
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/
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
modified:
file.txt
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
modified:
file.txt
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.
Related branches
- Jelmer Vernooij: Approve
-
Diff: 341 lines (+127/-32)9 files modifiedbreezy/builtins.py (+11/-8)
breezy/bzr/bzrdir.py (+10/-2)
breezy/controldir.py (+4/-4)
breezy/git/dir.py (+13/-0)
breezy/git/tests/test_blackbox.py (+25/-0)
breezy/git/workingtree.py (+19/-12)
breezy/switch.py (+2/-5)
breezy/tests/per_controldir_colo/test_supported.py (+38/-1)
doc/en/release-notes/brz-3.0.txt (+5/-0)
- Breezy developers: Pending requested
-
Diff: 260 lines (+104/-32)8 files modifiedbreezy/bzr/bzrdir.py (+3/-2)
breezy/controldir.py (+4/-4)
breezy/git/dir.py (+13/-0)
breezy/git/tests/test_blackbox.py (+25/-0)
breezy/git/workingtree.py (+19/-12)
breezy/switch.py (+1/-4)
breezy/tests/per_controldir_colo/test_supported.py (+38/-1)
setup.py (+1/-9)
Changed in brz: | |
status: | New → Triaged |
importance: | Undecided → Critical |
assignee: | nobody → Jelmer Vernooij (jelmer) |
milestone: | none → 3.0.1 |
Changed in brz: | |
status: | Triaged → In Progress |
status: | In Progress → Fix Committed |
Changed in brz: | |
status: | Fix Committed → Fix Released |
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".