# HG changeset patch # User Matt Mackall # Date 2009-06-20 13:29:41 # Node ID f331de880cbbfbd601e710a2735718ccf882c462 # Parent 980f5b7c5fb61fc2f67935513849c37c2fe94405 update: add --check option diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2975,7 +2975,7 @@ def unbundle(ui, repo, fname1, *fnames, return postincoming(ui, repo, modheads, opts.get('update'), None) -def update(ui, repo, node=None, rev=None, clean=False, date=None): +def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False): """update working directory Update the repository's working directory to the specified @@ -2991,7 +2991,8 @@ def update(ui, repo, node=None, rev=None When there are uncommitted changes, use option -C/--clean to discard them, forcibly replacing the state of the working - directory with the requested revision. + directory with the requested revision. Alternately, use -c/--check + to abort. When there are uncommitted changes and option -C/--clean is not used, and the parent revision and requested revision are on the @@ -3011,6 +3012,12 @@ def update(ui, repo, node=None, rev=None if not rev: rev = node + if not clean and check: + # we could use dirty() but we can ignore merge and branch trivia + c = repo[None] + if c.modified() or c.added() or c.removed(): + raise util.Abort(_("uncommitted local changes")) + if date: if rev: raise util.Abort(_("you can't specify a revision and a date")) @@ -3502,6 +3509,7 @@ table = { "^update|up|checkout|co": (update, [('C', 'clean', None, _('overwrite locally modified files (no backup)')), + ('c', 'check', None, _('check for uncommitted changes')), ('d', 'date', '', _('tipmost revision matching date')), ('r', 'rev', '', _('revision'))], _('[-C] [-d DATE] [[-r] REV]')), diff --git a/tests/test-debugcomplete.out b/tests/test-debugcomplete.out --- a/tests/test-debugcomplete.out +++ b/tests/test-debugcomplete.out @@ -176,7 +176,7 @@ push: force, rev, ssh, remotecmd remove: after, force, include, exclude serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, webdir-conf, pid-file, stdio, templates, style, ipv6, certificate status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, include, exclude -update: clean, date, rev +update: clean, check, date, rev addremove: similarity, include, exclude, dry-run archive: no-decode, prefix, rev, type, include, exclude backout: merge, parent, rev, include, exclude, message, logfile, date, user diff --git a/tests/test-up-issue1456 b/tests/test-up-issue1456 --- a/tests/test-up-issue1456 +++ b/tests/test-up-issue1456 @@ -10,7 +10,7 @@ chmod +x foo hg ci -m1 hg co -q 0 echo dirty > foo -sleep 1 +hg up -c hg up -q cat foo hg st -A diff --git a/tests/test-up-issue1456.out b/tests/test-up-issue1456.out --- a/tests/test-up-issue1456.out +++ b/tests/test-up-issue1456.out @@ -1,3 +1,4 @@ +abort: uncommitted local changes dirty M foo % validate update of standalone execute bit change