Mercurial > hg
comparison tests/test-rename-dir-merge.t @ 46634:ad30b29bc23d
copies: choose target directory based on longest match
If one side of a merge renames `dir1/` to `dir2/` and the subdirectory
`dir1/subdir1/` to `dir2/subdir2/`, and the other side of the merge
adds a file in `dir1/subdir1/`, we should clearly move that into
`dir2/subdir2/`. We already detect the directories correctly before
this patch, but we iterate over them in arbitrary order. That results
in the new file sometimes ending up in `dir2/subdir1/` instead. This
patch fixes it by iterating over the source directories by visiting
subdirectories first. That's achieved by simply iterating over them in
reverse lexicographical order.
Without the fix, the test case still passes on Python 2 but fails on
Python 3. It depends on the iteration order of the dict. I did not
look into how it's built up and why it behaved differently before the
fix. I could probably have gotten it to fail on Python 2 as well by
choosing different directory names.
Differential Revision: https://phab.mercurial-scm.org/D10115
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 04 Mar 2021 16:06:55 -0800 |
parents | dc00324e80f4 |
children | b7fde9237c92 |
comparison
equal
deleted
inserted
replaced
46633:7015b0232c5e | 46634:ad30b29bc23d |
---|---|
292 $ hg st --copies | 292 $ hg st --copies |
293 M s/s | 293 M s/s |
294 M t/t | 294 M t/t |
295 R a/s | 295 R a/s |
296 R a/t | 296 R a/t |
297 | |
298 $ cd .. | |
299 | |
300 | |
301 Test that files are moved to a new directory based on the path prefix that | |
302 matches the most. dir1/ below gets renamed to dir2/, and dir1/subdir1/ gets | |
303 renamed to dir2/subdir2/. We want dir1/subdir1/newfile to move to | |
304 dir2/subdir2/ (not to dir2/subdir1/ as we would infer based on just the rename | |
305 of dir1/ to dir2/). | |
306 | |
307 $ hg init nested-renames | |
308 $ cd nested-renames | |
309 $ mkdir dir1 | |
310 $ echo a > dir1/file1 | |
311 $ echo b > dir1/file2 | |
312 $ mkdir dir1/subdir1 | |
313 $ echo c > dir1/subdir1/file3 | |
314 $ echo d > dir1/subdir1/file4 | |
315 $ hg ci -Aqm initial | |
316 $ hg mv dir1 dir2 | |
317 moving dir1/file1 to dir2/file1 | |
318 moving dir1/file2 to dir2/file2 | |
319 moving dir1/subdir1/file3 to dir2/subdir1/file3 | |
320 moving dir1/subdir1/file4 to dir2/subdir1/file4 | |
321 $ hg mv dir2/subdir1 dir2/subdir2 | |
322 moving dir2/subdir1/file3 to dir2/subdir2/file3 | |
323 moving dir2/subdir1/file4 to dir2/subdir2/file4 | |
324 $ hg ci -m 'move dir1/ to dir2/ and dir1/subdir1/ to dir2/subdir2/' | |
325 $ hg co 0 | |
326 4 files updated, 0 files merged, 4 files removed, 0 files unresolved | |
327 $ echo e > dir1/subdir1/file5 | |
328 $ hg ci -Aqm 'add file in dir1/subdir1/' | |
329 $ hg merge 1 | |
330 5 files updated, 0 files merged, 4 files removed, 0 files unresolved | |
331 (branch merge, don't forget to commit) | |
332 $ hg files | |
333 dir2/file1 | |
334 dir2/file2 | |
335 dir2/subdir2/file3 | |
336 dir2/subdir2/file4 | |
337 dir2/subdir2/file5 | |
338 $ cd .. |