Mercurial > hg
changeset 20415:e4d7cbc94219 stable
merge: don't overwrite file untracked after remove, abort with 'untracked files'
Merge could overwrite untracked files and cause data loss.
Instead we now handle the 'local side removed file and has untracked file
instead' case as the 'other side added file that local has untracked' case:
FILE: untracked file exists
abort: untracked files in working directory differ from files in requested revision
It could perhaps make sense to create .orig files when overwriting, either
instead of aborting or when overwriting anyway because of force ... but for now
we stay consistent with similar cases.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 10 Feb 2014 00:43:54 +0100 |
parents | 6863d42eb59a |
children | 98eadbfffa0e aac87f70f38e |
files | mercurial/merge.py tests/test-merge-remove.t |
diffstat | 2 files changed, 33 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/merge.py Wed Feb 05 17:23:35 2014 -0600 +++ b/mercurial/merge.py Mon Feb 10 00:43:54 2014 +0100 @@ -343,7 +343,12 @@ else: actions.append((f, "g", (fl2,), "remote created")) elif n2 and n2 != ma[f]: - prompts.append((f, "dc")) # prompt deleted/changed + different = _checkunknownfile(repo, wctx, p2, f) + if not force and different: + aborts.append((f, "ud")) + else: + # if different: old untracked f may be overwritten and lost + prompts.append((f, "dc")) # prompt deleted/changed for f, m in sorted(aborts): if m == "ud":
--- a/tests/test-merge-remove.t Wed Feb 05 17:23:35 2014 -0600 +++ b/tests/test-merge-remove.t Mon Feb 10 00:43:54 2014 +0100 @@ -85,3 +85,30 @@ $ hg diff +Merge should not overwrite local file that is untracked after remove + + $ rm * + $ hg up -qC + $ hg rm bar + $ hg ci -m 'remove bar' + $ echo 'memories of buried pirate treasure' > bar + $ hg merge + bar: untracked file differs + abort: untracked files in working directory differ from files in requested revision + [255] + $ cat bar + memories of buried pirate treasure + +Those who use force will lose + + $ hg merge -f + remote changed bar which local deleted + use (c)hanged version or leave (d)eleted? c + merging foo1 and foo to foo1 + 1 files updated, 1 files merged, 0 files removed, 0 files unresolved + (branch merge, don't forget to commit) + $ cat bar + bleh + $ hg st + M bar + M foo1