[PATCH 0 of 8 RFC] Add guard option to update, which aborts if the update is unsafe
Laurens Holst
laurens.nospam at grauw.nl
Wed Dec 21 13:54:47 CST 2011
Op 21-12-2011 20:45, Laurens Holst schreef:
> This set of changes adds a --guard/-g flag that aborts the update if it touches
> any files that are modified locally and could potentially cause conflicts. The
> update could still break your code, however going back to a working version will
> now simply be a matter of updating back to the original revision. Later in the
> series it also performs tentative merges to see if there are conflicts, and
> only aborts when there is an actual conflict.
Quoted below is my batch file with tests, they show the output for
various operations.
It’s not in .t format because I wasn’t able to get that to run on this
Windows machine, so this’ll have to do for now. Are there instructions
on how to run? Almost all commands I used here are cross-platform, so in
theory I should be able to write a .t test that (mostly) works on
Windows without needing to install msys or cygwin (which I’m trying to
avoid :))... Any guidance on that?
~Laurens
test-guard.cmd:
=======================
@echo off
set REPO=test-guard
hg init %REPO%
(echo a && echo. && echo - && echo. && echo -) > %REPO%/a
hg -R %REPO% add %REPO%/a
hg -R %REPO% commit -m initial
(echo b && echo. && echo - && echo. && echo -) > %REPO%/a
hg -R %REPO% commit -m change
hg -R %REPO% cp %REPO%/a %REPO%/b
hg -R %REPO% commit -m copy
hg -R %REPO% mv %REPO%/b %REPO%/c
hg -R %REPO% commit -m move
echo ===================================================================
echo Tests for conflicts in bi-directional changes and the null revision
echo ===================================================================
:: setup
hg -R %REPO% update 1 -C -q
:: updating down with conflicting local change
echo xxx > %REPO%/a
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 0 -g
:: updating down with no local change
hg -R %REPO% revert %REPO%/a
echo 1 files updated, 0 files merged, 0 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 0 -g
:: updating up with conflicting local change
echo xxx > %REPO%/a
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 1 -g
:: updating up with no local change
hg -R %REPO% revert %REPO%/a
echo 1 files updated, 0 files merged, 0 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 1 -g
:: updating to null with no local change
echo 0 files updated, 0 files merged, 1 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update null -g
:: updating from null to 0 with conflicting local change
echo xxx > %REPO%/a
echo abort: untracked file in working directory differs from file in
requested revision: 'a' (EXPECTED)
hg -R %REPO% update 0 -g
:: updating from null to 0 with no local change
del /q %REPO%/a
echo 1 files updated, 0 files merged, 0 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 0 -g
:: updating to null with conflicting local change (EXPECTED)
echo xxx > %REPO%/a
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update null -g
echo ==========================================
echo Tests for updating across copies and moves
echo ==========================================
:: setup
hg -R %REPO% update 1 -C -q
:: updating up with modified copied file
echo xxx > %REPO%/a
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 2 -g
:: updating up with unmodified copied file
hg -R %REPO% revert %REPO%/a
echo 1 files updated, 0 files merged, 0 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 2 -g
:: updating up with modified moved file
echo xxx > %REPO%/b
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 3 -g
:: updating up with unmodified moved file
hg -R %REPO% revert %REPO%/b
echo 1 files updated, 0 files merged, 1 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 3 -g
:: updating down with modified moved file
echo xxx > %REPO%/c
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 2 -g
:: updating down with unmodified moved file
hg -R %REPO% revert %REPO%/c
echo 1 files updated, 0 files merged, 1 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 2 -g
:: updating down with modified copied file
echo xxx > %REPO%/b
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 1 -g
:: updating down with unmodified copied file
hg -R %REPO% revert %REPO%/b
echo 0 files updated, 0 files merged, 1 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 1 -g
echo ===================================================
echo Tests for updating files unrelated to local changes
echo ===================================================
:: setup
hg -R %REPO% update 2 -C -q
:: updating up with modified unrelated file
echo xxx > %REPO%/a
echo 1 files updated, 0 files merged, 1 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 3 -g
:: updating down with modified unrelated file
echo xxx > %REPO%/a
echo 1 files updated, 0 files merged, 1 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 2 -g
echo =============================
echo Tests for conflicts in merges
echo =============================
:: setup
hg -R %REPO% update 0 -C -q
:: updating with mergeable change
echo yyy >> %REPO%/a
echo 0 files updated, 1 files merged, 0 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 1 -g
:: ================================
:: TODO: Add tests for binary files
:: ================================
echo =======================================================
echo Tests for special handling of internal merge mechanisms
echo =======================================================
:: setup
hg -R %REPO% update 0 -C -q
echo xxx > %REPO%/a
:: updating with internal:local always succeeds
echo 0 files updated, 1 files merged, 0 files removed, 0 files
unresolved (EXPECTED)
hg -R %REPO% update 1 -g --config merge-patterns.**=internal:local
:: updating with internal:other always fails
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 0 -g --config merge-patterns.**=internal:other
:: updating with internal:dump always fails
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 0 -g --config merge-patterns.**=internal:dump
:: updating with internal:prompt always fails
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 0 -g --config merge-patterns.**=internal:prompt
:: updating with internal:fail always fails
hg -R %REPO% revert %REPO%/a
echo yyy >> %REPO%/a
echo abort: update touches modified files (EXPECTED)
hg -R %REPO% update 0 -g --config merge-patterns.**=internal:fail
rmdir /s /q %REPO%
--
~~ Ushiko-san! Kimi wa doushite, Ushiko-san nan da!! ~~
Laurens Holst, developer, Utrecht, the Netherlands
Website: www.grauw.nl. Working @ www.roughcookie.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4332 bytes
Desc: S/MIME cryptografische ondertekening
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20111221/f3187141/attachment.bin>
More information about the Mercurial-devel
mailing list