diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py --- a/hgext/narrow/narrowcommands.py +++ b/hgext/narrow/narrowcommands.py @@ -1,686 +1,691 @@ # narrowcommands.py - command modifications for narrowhg extension # # Copyright 2017 Google, Inc. # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. from __future__ import absolute_import import itertools import os from mercurial.i18n import _ from mercurial.node import ( hex, short, ) from mercurial import ( bundle2, cmdutil, commands, discovery, encoding, error, exchange, extensions, hg, narrowspec, pathutil, pycompat, registrar, repair, repoview, requirements, sparse, util, wireprototypes, ) from mercurial.utils import ( urlutil, ) table = {} command = registrar.command(table) def setup(): """Wraps user-facing mercurial commands with narrow-aware versions.""" entry = extensions.wrapcommand(commands.table, b'clone', clonenarrowcmd) entry[1].append( (b'', b'narrow', None, _(b"create a narrow clone of select files")) ) entry[1].append( ( b'', b'depth', b'', _(b"limit the history fetched by distance from heads"), ) ) entry[1].append((b'', b'narrowspec', b'', _(b"read narrowspecs from file"))) # TODO(durin42): unify sparse/narrow --include/--exclude logic a bit if b'sparse' not in extensions.enabled(): entry[1].append( (b'', b'include', [], _(b"specifically fetch this file/directory")) ) entry[1].append( ( b'', b'exclude', [], _(b"do not fetch this file/directory, even if included"), ) ) entry = extensions.wrapcommand(commands.table, b'pull', pullnarrowcmd) entry[1].append( ( b'', b'depth', b'', _(b"limit the history fetched by distance from heads"), ) ) extensions.wrapcommand(commands.table, b'archive', archivenarrowcmd) def clonenarrowcmd(orig, ui, repo, *args, **opts): """Wraps clone command, so 'hg clone' first wraps localrepo.clone().""" opts = pycompat.byteskwargs(opts) wrappedextraprepare = util.nullcontextmanager() narrowspecfile = opts[b'narrowspec'] if narrowspecfile: filepath = os.path.join(encoding.getcwd(), narrowspecfile) ui.status(_(b"reading narrowspec from '%s'\n") % filepath) try: fdata = util.readfile(filepath) except IOError as inst: raise error.Abort( _(b"cannot read narrowspecs from '%s': %s") % (filepath, encoding.strtolocal(inst.strerror)) ) includes, excludes, profiles = sparse.parseconfig(ui, fdata, b'narrow') if profiles: raise error.ConfigError( _( b"cannot specify other files using '%include' in" b" narrowspec" ) ) narrowspec.validatepatterns(includes) narrowspec.validatepatterns(excludes) # narrowspec is passed so we should assume that user wants narrow clone opts[b'narrow'] = True opts[b'include'].extend(includes) opts[b'exclude'].extend(excludes) if opts[b'narrow']: def pullbundle2extraprepare_widen(orig, pullop, kwargs): orig(pullop, kwargs) if opts.get(b'depth'): kwargs[b'depth'] = opts[b'depth'] wrappedextraprepare = extensions.wrappedfunction( exchange, b'_pullbundle2extraprepare', pullbundle2extraprepare_widen ) with wrappedextraprepare: return orig(ui, repo, *args, **pycompat.strkwargs(opts)) def pullnarrowcmd(orig, ui, repo, *args, **opts): """Wraps pull command to allow modifying narrow spec.""" wrappedextraprepare = util.nullcontextmanager() if requirements.NARROW_REQUIREMENT in repo.requirements: def pullbundle2extraprepare_widen(orig, pullop, kwargs): orig(pullop, kwargs) if opts.get('depth'): kwargs[b'depth'] = opts['depth'] wrappedextraprepare = extensions.wrappedfunction( exchange, b'_pullbundle2extraprepare', pullbundle2extraprepare_widen ) with wrappedextraprepare: return orig(ui, repo, *args, **opts) def archivenarrowcmd(orig, ui, repo, *args, **opts): """Wraps archive command to narrow the default includes.""" if requirements.NARROW_REQUIREMENT in repo.requirements: repo_includes, repo_excludes = repo.narrowpats includes = set(opts.get('include', [])) excludes = set(opts.get('exclude', [])) includes, excludes, unused_invalid = narrowspec.restrictpatterns( includes, excludes, repo_includes, repo_excludes ) if includes: opts['include'] = includes if excludes: opts['exclude'] = excludes return orig(ui, repo, *args, **opts) def pullbundle2extraprepare(orig, pullop, kwargs): repo = pullop.repo if requirements.NARROW_REQUIREMENT not in repo.requirements: return orig(pullop, kwargs) if wireprototypes.NARROWCAP not in pullop.remote.capabilities(): raise error.Abort(_(b"server does not support narrow clones")) orig(pullop, kwargs) kwargs[b'narrow'] = True include, exclude = repo.narrowpats kwargs[b'oldincludepats'] = include kwargs[b'oldexcludepats'] = exclude if include: kwargs[b'includepats'] = include if exclude: kwargs[b'excludepats'] = exclude # calculate known nodes only in ellipses cases because in non-ellipses cases # we have all the nodes if wireprototypes.ELLIPSESCAP1 in pullop.remote.capabilities(): kwargs[b'known'] = [ hex(ctx.node()) for ctx in repo.set(b'::%ln', pullop.common) if ctx.node() != repo.nullid ] if not kwargs[b'known']: # Mercurial serializes an empty list as '' and deserializes it as # [''], so delete it instead to avoid handling the empty string on # the server. del kwargs[b'known'] extensions.wrapfunction( exchange, b'_pullbundle2extraprepare', pullbundle2extraprepare ) def _narrow( ui, repo, remote, commoninc, oldincludes, oldexcludes, newincludes, newexcludes, force, backup, ): oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes) newmatch = narrowspec.match(repo.root, newincludes, newexcludes) # This is essentially doing "hg outgoing" to find all local-only # commits. We will then check that the local-only commits don't # have any changes to files that will be untracked. unfi = repo.unfiltered() outgoing = discovery.findcommonoutgoing(unfi, remote, commoninc=commoninc) ui.status(_(b'looking for local changes to affected paths\n')) progress = ui.makeprogress( topic=_(b'changesets'), unit=_(b'changesets'), total=len(outgoing.missing) + len(outgoing.excluded), ) localnodes = [] with progress: for n in itertools.chain(outgoing.missing, outgoing.excluded): progress.increment() if any(oldmatch(f) and not newmatch(f) for f in unfi[n].files()): localnodes.append(n) revstostrip = unfi.revs(b'descendants(%ln)', localnodes) hiddenrevs = repoview.filterrevs(repo, b'visible') visibletostrip = list( repo.changelog.node(r) for r in (revstostrip - hiddenrevs) ) if visibletostrip: ui.status( _( b'The following changeset(s) or their ancestors have ' b'local changes not on the remote:\n' ) ) maxnodes = 10 if ui.verbose or len(visibletostrip) <= maxnodes: for n in visibletostrip: ui.status(b'%s\n' % short(n)) else: for n in visibletostrip[:maxnodes]: ui.status(b'%s\n' % short(n)) ui.status( _(b'...and %d more, use --verbose to list all\n') % (len(visibletostrip) - maxnodes) ) if not force: raise error.StateError( _(b'local changes found'), hint=_(b'use --force-delete-local-changes to ignore'), ) with ui.uninterruptible(): if revstostrip: tostrip = [unfi.changelog.node(r) for r in revstostrip] if repo[b'.'].node() in tostrip: # stripping working copy, so move to a different commit first urev = max( repo.revs( b'(::%n) - %ln + null', repo[b'.'].node(), visibletostrip, ) ) hg.clean(repo, urev) overrides = {(b'devel', b'strip-obsmarkers'): False} + if backup: + ui.status(_(b'moving unwanted changesets to backup\n')) + else: + ui.status(_(b'deleting unwanted changesets\n')) with ui.configoverride(overrides, b'narrow'): repair.strip(ui, unfi, tostrip, topic=b'narrow', backup=backup) todelete = [] for t, f, f2, size in repo.store.datafiles(): if f.startswith(b'data/'): file = f[5:-2] if not newmatch(file): todelete.append(f) elif f.startswith(b'meta/'): dir = f[5:-13] dirs = sorted(pathutil.dirs({dir})) + [dir] include = True for d in dirs: visit = newmatch.visitdir(d) if not visit: include = False break if visit == b'all': break if not include: todelete.append(f) repo.destroying() with repo.transaction(b'narrowing'): # Update narrowspec before removing revlogs, so repo won't be # corrupt in case of crash repo.setnarrowpats(newincludes, newexcludes) for f in todelete: ui.status(_(b'deleting %s\n') % f) util.unlinkpath(repo.svfs.join(f)) repo.store.markremoved(f) + ui.status(_(b'deleting unwanted files from working copy\n')) narrowspec.updateworkingcopy(repo, assumeclean=True) narrowspec.copytoworkingcopy(repo) repo.destroyed() def _widen( ui, repo, remote, commoninc, oldincludes, oldexcludes, newincludes, newexcludes, ): # for now we assume that if a server has ellipses enabled, we will be # exchanging ellipses nodes. In future we should add ellipses as a client # side requirement (maybe) to distinguish a client is shallow or not and # then send that information to server whether we want ellipses or not. # Theoretically a non-ellipses repo should be able to use narrow # functionality from an ellipses enabled server remotecap = remote.capabilities() ellipsesremote = any( cap in remotecap for cap in wireprototypes.SUPPORTED_ELLIPSESCAP ) # check whether we are talking to a server which supports old version of # ellipses capabilities isoldellipses = ( ellipsesremote and wireprototypes.ELLIPSESCAP1 in remotecap and wireprototypes.ELLIPSESCAP not in remotecap ) def pullbundle2extraprepare_widen(orig, pullop, kwargs): orig(pullop, kwargs) # The old{in,ex}cludepats have already been set by orig() kwargs[b'includepats'] = newincludes kwargs[b'excludepats'] = newexcludes wrappedextraprepare = extensions.wrappedfunction( exchange, b'_pullbundle2extraprepare', pullbundle2extraprepare_widen ) # define a function that narrowbundle2 can call after creating the # backup bundle, but before applying the bundle from the server def setnewnarrowpats(): repo.setnarrowpats(newincludes, newexcludes) repo.setnewnarrowpats = setnewnarrowpats # silence the devel-warning of applying an empty changegroup overrides = {(b'devel', b'all-warnings'): False} common = commoninc[0] with ui.uninterruptible(): if ellipsesremote: ds = repo.dirstate p1, p2 = ds.p1(), ds.p2() with ds.parentchange(): ds.setparents(repo.nullid, repo.nullid) if isoldellipses: with wrappedextraprepare: exchange.pull(repo, remote, heads=common) else: known = [] if ellipsesremote: known = [ ctx.node() for ctx in repo.set(b'::%ln', common) if ctx.node() != repo.nullid ] with remote.commandexecutor() as e: bundle = e.callcommand( b'narrow_widen', { b'oldincludes': oldincludes, b'oldexcludes': oldexcludes, b'newincludes': newincludes, b'newexcludes': newexcludes, b'cgversion': b'03', b'commonheads': common, b'known': known, b'ellipses': ellipsesremote, }, ).result() trmanager = exchange.transactionmanager( repo, b'widen', remote.url() ) with trmanager, repo.ui.configoverride(overrides, b'widen'): op = bundle2.bundleoperation( repo, trmanager.transaction, source=b'widen' ) # TODO: we should catch error.Abort here bundle2.processbundle(repo, bundle, op=op) if ellipsesremote: with ds.parentchange(): ds.setparents(p1, p2) with repo.transaction(b'widening'): repo.setnewnarrowpats() narrowspec.updateworkingcopy(repo) narrowspec.copytoworkingcopy(repo) # TODO(rdamazio): Make new matcher format and update description @command( b'tracked', [ (b'', b'addinclude', [], _(b'new paths to include')), (b'', b'removeinclude', [], _(b'old paths to no longer include')), ( b'', b'auto-remove-includes', False, _(b'automatically choose unused includes to remove'), ), (b'', b'addexclude', [], _(b'new paths to exclude')), (b'', b'import-rules', b'', _(b'import narrowspecs from a file')), (b'', b'removeexclude', [], _(b'old paths to no longer exclude')), ( b'', b'clear', False, _(b'whether to replace the existing narrowspec'), ), ( b'', b'force-delete-local-changes', False, _(b'forces deletion of local changes when narrowing'), ), ( b'', b'backup', True, _(b'back up local changes when narrowing'), ), ( b'', b'update-working-copy', False, _(b'update working copy when the store has changed'), ), ] + commands.remoteopts, _(b'[OPTIONS]... [REMOTE]'), inferrepo=True, helpcategory=command.CATEGORY_MAINTENANCE, ) def trackedcmd(ui, repo, remotepath=None, *pats, **opts): """show or change the current narrowspec With no argument, shows the current narrowspec entries, one per line. Each line will be prefixed with 'I' or 'X' for included or excluded patterns, respectively. The narrowspec is comprised of expressions to match remote files and/or directories that should be pulled into your client. The narrowspec has *include* and *exclude* expressions, with excludes always trumping includes: that is, if a file matches an exclude expression, it will be excluded even if it also matches an include expression. Excluding files that were never included has no effect. Each included or excluded entry is in the format described by 'hg help patterns'. The options allow you to add or remove included and excluded expressions. If --clear is specified, then all previous includes and excludes are DROPPED and replaced by the new ones specified to --addinclude and --addexclude. If --clear is specified without any further options, the narrowspec will be empty and will not match any files. If --auto-remove-includes is specified, then those includes that don't match any files modified by currently visible local commits (those not shared by the remote) will be added to the set of explicitly specified includes to remove. --import-rules accepts a path to a file containing rules, allowing you to add --addinclude, --addexclude rules in bulk. Like the other include and exclude switches, the changes are applied immediately. """ opts = pycompat.byteskwargs(opts) if requirements.NARROW_REQUIREMENT not in repo.requirements: raise error.InputError( _( b'the tracked command is only supported on ' b'repositories cloned with --narrow' ) ) # Before supporting, decide whether it "hg tracked --clear" should mean # tracking no paths or all paths. if opts[b'clear']: raise error.InputError(_(b'the --clear option is not yet supported')) # import rules from a file newrules = opts.get(b'import_rules') if newrules: try: filepath = os.path.join(encoding.getcwd(), newrules) fdata = util.readfile(filepath) except IOError as inst: raise error.StorageError( _(b"cannot read narrowspecs from '%s': %s") % (filepath, encoding.strtolocal(inst.strerror)) ) includepats, excludepats, profiles = sparse.parseconfig( ui, fdata, b'narrow' ) if profiles: raise error.InputError( _( b"including other spec files using '%include' " b"is not supported in narrowspec" ) ) opts[b'addinclude'].extend(includepats) opts[b'addexclude'].extend(excludepats) addedincludes = narrowspec.parsepatterns(opts[b'addinclude']) removedincludes = narrowspec.parsepatterns(opts[b'removeinclude']) addedexcludes = narrowspec.parsepatterns(opts[b'addexclude']) removedexcludes = narrowspec.parsepatterns(opts[b'removeexclude']) autoremoveincludes = opts[b'auto_remove_includes'] update_working_copy = opts[b'update_working_copy'] only_show = not ( addedincludes or removedincludes or addedexcludes or removedexcludes or newrules or autoremoveincludes or update_working_copy ) oldincludes, oldexcludes = repo.narrowpats # filter the user passed additions and deletions into actual additions and # deletions of excludes and includes addedincludes -= oldincludes removedincludes &= oldincludes addedexcludes -= oldexcludes removedexcludes &= oldexcludes widening = addedincludes or removedexcludes narrowing = removedincludes or addedexcludes # Only print the current narrowspec. if only_show: ui.pager(b'tracked') fm = ui.formatter(b'narrow', opts) for i in sorted(oldincludes): fm.startitem() fm.write(b'status', b'%s ', b'I', label=b'narrow.included') fm.write(b'pat', b'%s\n', i, label=b'narrow.included') for i in sorted(oldexcludes): fm.startitem() fm.write(b'status', b'%s ', b'X', label=b'narrow.excluded') fm.write(b'pat', b'%s\n', i, label=b'narrow.excluded') fm.end() return 0 if update_working_copy: with repo.wlock(), repo.lock(), repo.transaction(b'narrow-wc'): narrowspec.updateworkingcopy(repo) narrowspec.copytoworkingcopy(repo) return 0 if not (widening or narrowing or autoremoveincludes): ui.status(_(b"nothing to widen or narrow\n")) return 0 with repo.wlock(), repo.lock(): cmdutil.bailifchanged(repo) # Find the revisions we have in common with the remote. These will # be used for finding local-only changes for narrowing. They will # also define the set of revisions to update for widening. r = urlutil.get_unique_pull_path(b'tracked', repo, ui, remotepath) url, branches = r ui.status(_(b'comparing with %s\n') % urlutil.hidepassword(url)) remote = hg.peer(repo, opts, url) try: # check narrow support before doing anything if widening needs to be # performed. In future we should also abort if client is ellipses and # server does not support ellipses if ( widening and wireprototypes.NARROWCAP not in remote.capabilities() ): raise error.Abort(_(b"server does not support narrow clones")) commoninc = discovery.findcommonincoming(repo, remote) if autoremoveincludes: outgoing = discovery.findcommonoutgoing( repo, remote, commoninc=commoninc ) ui.status(_(b'looking for unused includes to remove\n')) localfiles = set() for n in itertools.chain(outgoing.missing, outgoing.excluded): localfiles.update(repo[n].files()) suggestedremovals = [] for include in sorted(oldincludes): match = narrowspec.match(repo.root, [include], oldexcludes) if not any(match(f) for f in localfiles): suggestedremovals.append(include) if suggestedremovals: for s in suggestedremovals: ui.status(b'%s\n' % s) if ( ui.promptchoice( _( b'remove these unused includes (yn)?' b'$$ &Yes $$ &No' ) ) == 0 ): removedincludes.update(suggestedremovals) narrowing = True else: ui.status(_(b'found no unused includes\n')) if narrowing: newincludes = oldincludes - removedincludes newexcludes = oldexcludes | addedexcludes _narrow( ui, repo, remote, commoninc, oldincludes, oldexcludes, newincludes, newexcludes, opts[b'force_delete_local_changes'], opts[b'backup'], ) # _narrow() updated the narrowspec and _widen() below needs to # use the updated values as its base (otherwise removed includes # and addedexcludes will be lost in the resulting narrowspec) oldincludes = newincludes oldexcludes = newexcludes if widening: newincludes = oldincludes | addedincludes newexcludes = oldexcludes - removedexcludes _widen( ui, repo, remote, commoninc, oldincludes, oldexcludes, newincludes, newexcludes, ) finally: remote.close() return 0 diff --git a/tests/test-narrow-clone-non-narrow-server.t b/tests/test-narrow-clone-non-narrow-server.t --- a/tests/test-narrow-clone-non-narrow-server.t +++ b/tests/test-narrow-clone-non-narrow-server.t @@ -1,67 +1,68 @@ Test attempting a narrow clone against a server that doesn't support narrowhg. $ . "$TESTDIR/narrow-library.sh" $ hg init master $ cd master $ for x in `$TESTDIR/seq.py 10`; do > echo $x > "f$x" > hg add "f$x" > hg commit -m "Add $x" > done $ hg serve -a localhost -p $HGPORT1 --config extensions.narrow=! -d \ > --pid-file=hg.pid $ cat hg.pid >> "$DAEMON_PIDS" $ hg serve -a localhost -p $HGPORT2 -d --pid-file=hg.pid $ cat hg.pid >> "$DAEMON_PIDS" Verify that narrow is advertised in the bundle2 capabilities: $ cat >> unquote.py < from __future__ import print_function > import sys > if sys.version[0] == '3': > import urllib.parse as up > unquote = up.unquote_plus > else: > import urllib > unquote = urllib.unquote_plus > print(unquote(list(sys.stdin)[1])) > EOF $ echo hello | hg -R . serve --stdio | \ > "$PYTHON" unquote.py | tr ' ' '\n' | grep narrow exp-narrow-1 $ cd .. $ hg clone --narrow --include f1 http://localhost:$HGPORT1/ narrowclone requesting all changes abort: server does not support narrow clones [255] Make a narrow clone (via HGPORT2), then try to narrow and widen into it (from HGPORT1) to prove that narrowing is fine and widening fails gracefully: $ hg clone -r 0 --narrow --include f1 http://localhost:$HGPORT2/ narrowclone adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files new changesets * (glob) updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd narrowclone $ hg tracked --addexclude f2 http://localhost:$HGPORT1/ comparing with http://localhost:$HGPORT1/ searching for changes looking for local changes to affected paths + deleting unwanted files from working copy $ hg tracked --addinclude f1 http://localhost:$HGPORT1/ nothing to widen or narrow $ hg tracked --addinclude f9 http://localhost:$HGPORT1/ comparing with http://localhost:$HGPORT1/ abort: server does not support narrow clones [255] diff --git a/tests/test-narrow-patterns.t b/tests/test-narrow-patterns.t --- a/tests/test-narrow-patterns.t +++ b/tests/test-narrow-patterns.t @@ -1,459 +1,461 @@ $ . "$TESTDIR/narrow-library.sh" initialize nested directories to validate complex include/exclude patterns $ hg init master $ cd master $ cat >> .hg/hgrc < [narrow] > serveellipses=True > EOF $ echo root > root $ hg add root $ hg commit -m 'add root' $ for d in dir1 dir2 dir1/dirA dir1/dirB dir2/dirA dir2/dirB > do > mkdir -p $d > echo $d/foo > $d/foo > hg add $d/foo > hg commit -m "add $d/foo" > echo $d/bar > $d/bar > hg add $d/bar > hg commit -m "add $d/bar" > done #if execbit $ chmod +x dir1/dirA/foo $ hg commit -m "make dir1/dirA/foo executable" #else $ hg import --bypass - < # HG changeset patch > make dir1/dirA/foo executable > > diff --git a/dir1/dirA/foo b/dir1/dirA/foo > old mode 100644 > new mode 100755 > EOF applying patch from stdin $ hg update -qr tip #endif $ hg log -G -T '{rev} {node|short} {files}\n' @ 13 c87ca422d521 dir1/dirA/foo | o 12 951b8a83924e dir2/dirB/bar | o 11 01ae5a51b563 dir2/dirB/foo | o 10 5eababdf0ac5 dir2/dirA/bar | o 9 99d690663739 dir2/dirA/foo | o 8 8e80155d5445 dir1/dirB/bar | o 7 406760310428 dir1/dirB/foo | o 6 623466a5f475 dir1/dirA/bar | o 5 06ff3a5be997 dir1/dirA/foo | o 4 33227af02764 dir2/bar | o 3 5e1f9d8d7c69 dir2/foo | o 2 594bc4b13d4a dir1/bar | o 1 47f480a08324 dir1/foo | o 0 2a4f0c3b67da root $ cd .. clone a narrow portion of the master, such that we can widen it later $ hg clone --narrow ssh://user@dummy/master narrow \ > --include dir1 \ > --include dir2 \ > --exclude dir1/dirA \ > --exclude dir1/dirB \ > --exclude dir2/dirA \ > --exclude dir2/dirB requesting all changes adding changesets adding manifests adding file changes added 6 changesets with 4 changes to 4 files new changesets *:* (glob) updating to branch default 4 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd narrow $ hg tracked I path:dir1 I path:dir2 X path:dir1/dirA X path:dir1/dirB X path:dir2/dirA X path:dir2/dirB $ hg manifest -r tip dir1/bar dir1/dirA/bar dir1/dirA/foo dir1/dirB/bar dir1/dirB/foo dir1/foo dir2/bar dir2/dirA/bar dir2/dirA/foo dir2/dirB/bar dir2/dirB/foo dir2/foo root $ find * | sort dir1 dir1/bar dir1/foo dir2 dir2/bar dir2/foo $ hg log -G -T '{rev} {node|short}{if(ellipsis, "...")} {files}\n' @ 5 c87ca422d521... dir1/dirA/foo | o 4 33227af02764 dir2/bar | o 3 5e1f9d8d7c69 dir2/foo | o 2 594bc4b13d4a dir1/bar | o 1 47f480a08324 dir1/foo | o 0 2a4f0c3b67da... root widen the narrow checkout $ hg tracked --removeexclude dir1/dirA comparing with ssh://user@dummy/master searching for changes saved backup bundle to $TESTTMP/narrow/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 9 changesets with 6 changes to 6 files $ hg tracked I path:dir1 I path:dir2 X path:dir1/dirB X path:dir2/dirA X path:dir2/dirB $ find * | sort dir1 dir1/bar dir1/dirA dir1/dirA/bar dir1/dirA/foo dir1/foo dir2 dir2/bar dir2/foo #if execbit $ test -x dir1/dirA/foo && echo executable executable $ test -x dir1/dirA/bar || echo not executable not executable #endif $ hg log -G -T '{rev} {node|short}{if(ellipsis, "...")} {files}\n' @ 8 c87ca422d521 dir1/dirA/foo | o 7 951b8a83924e... dir2/dirB/bar | o 6 623466a5f475 dir1/dirA/bar | o 5 06ff3a5be997 dir1/dirA/foo | o 4 33227af02764 dir2/bar | o 3 5e1f9d8d7c69 dir2/foo | o 2 594bc4b13d4a dir1/bar | o 1 47f480a08324 dir1/foo | o 0 2a4f0c3b67da... root widen narrow spec again, but exclude a file in previously included spec $ hg tracked --removeexclude dir2/dirB --addexclude dir1/dirA/bar comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/dir1/dirA/bar.i (reporevlogstore !) deleting data/dir1/dirA/bar/0eca1d0cbdaea4651d1d04d71976a6d2d9bfaae5 (reposimplestore !) deleting data/dir1/dirA/bar/index (reposimplestore !) + deleting unwanted files from working copy saved backup bundle to $TESTTMP/narrow/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 11 changesets with 7 changes to 7 files $ hg tracked I path:dir1 I path:dir2 X path:dir1/dirA/bar X path:dir1/dirB X path:dir2/dirA $ find * | sort dir1 dir1/bar dir1/dirA dir1/dirA/foo dir1/foo dir2 dir2/bar dir2/dirB dir2/dirB/bar dir2/dirB/foo dir2/foo $ hg log -G -T '{rev} {node|short}{if(ellipsis, "...")} {files}\n' @ 10 c87ca422d521 dir1/dirA/foo | o 9 951b8a83924e dir2/dirB/bar | o 8 01ae5a51b563 dir2/dirB/foo | o 7 5eababdf0ac5... dir2/dirA/bar | o 6 623466a5f475... dir1/dirA/bar | o 5 06ff3a5be997 dir1/dirA/foo | o 4 33227af02764 dir2/bar | o 3 5e1f9d8d7c69 dir2/foo | o 2 594bc4b13d4a dir1/bar | o 1 47f480a08324 dir1/foo | o 0 2a4f0c3b67da... root widen narrow spec yet again, excluding a directory in previous spec $ hg tracked --removeexclude dir2/dirA --addexclude dir1/dirA comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/dir1/dirA/foo.i (reporevlogstore !) deleting data/dir1/dirA/foo/162caeb3d55dceb1fee793aa631ac8c73fcb8b5e (reposimplestore !) deleting data/dir1/dirA/foo/index (reposimplestore !) + deleting unwanted files from working copy saved backup bundle to $TESTTMP/narrow/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 13 changesets with 8 changes to 8 files $ hg tracked I path:dir1 I path:dir2 X path:dir1/dirA X path:dir1/dirA/bar X path:dir1/dirB $ find * | sort dir1 dir1/bar dir1/foo dir2 dir2/bar dir2/dirA dir2/dirA/bar dir2/dirA/foo dir2/dirB dir2/dirB/bar dir2/dirB/foo dir2/foo $ hg log -G -T '{rev} {node|short}{if(ellipsis, "...")} {files}\n' @ 12 c87ca422d521... dir1/dirA/foo | o 11 951b8a83924e dir2/dirB/bar | o 10 01ae5a51b563 dir2/dirB/foo | o 9 5eababdf0ac5 dir2/dirA/bar | o 8 99d690663739 dir2/dirA/foo | o 7 8e80155d5445... dir1/dirB/bar | o 6 623466a5f475... dir1/dirA/bar | o 5 06ff3a5be997... dir1/dirA/foo | o 4 33227af02764 dir2/bar | o 3 5e1f9d8d7c69 dir2/foo | o 2 594bc4b13d4a dir1/bar | o 1 47f480a08324 dir1/foo | o 0 2a4f0c3b67da... root include a directory that was previously explicitly excluded $ hg tracked --removeexclude dir1/dirA comparing with ssh://user@dummy/master searching for changes saved backup bundle to $TESTTMP/narrow/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 13 changesets with 9 changes to 9 files $ hg tracked I path:dir1 I path:dir2 X path:dir1/dirA/bar X path:dir1/dirB $ find * | sort dir1 dir1/bar dir1/dirA dir1/dirA/foo dir1/foo dir2 dir2/bar dir2/dirA dir2/dirA/bar dir2/dirA/foo dir2/dirB dir2/dirB/bar dir2/dirB/foo dir2/foo $ hg log -G -T '{rev} {node|short}{if(ellipsis, "...")} {files}\n' @ 12 c87ca422d521 dir1/dirA/foo | o 11 951b8a83924e dir2/dirB/bar | o 10 01ae5a51b563 dir2/dirB/foo | o 9 5eababdf0ac5 dir2/dirA/bar | o 8 99d690663739 dir2/dirA/foo | o 7 8e80155d5445... dir1/dirB/bar | o 6 623466a5f475... dir1/dirA/bar | o 5 06ff3a5be997 dir1/dirA/foo | o 4 33227af02764 dir2/bar | o 3 5e1f9d8d7c69 dir2/foo | o 2 594bc4b13d4a dir1/bar | o 1 47f480a08324 dir1/foo | o 0 2a4f0c3b67da... root $ cd .. clone a narrow portion of the master, such that we can widen it later $ hg clone --narrow ssh://user@dummy/master narrow2 --include dir1/dirA requesting all changes adding changesets adding manifests adding file changes added 5 changesets with 2 changes to 2 files new changesets *:* (glob) updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd narrow2 $ find * | sort dir1 dir1/dirA dir1/dirA/bar dir1/dirA/foo $ hg tracked --addinclude dir1 comparing with ssh://user@dummy/master searching for changes saved backup bundle to $TESTTMP/narrow2/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 10 changesets with 6 changes to 6 files $ find * | sort dir1 dir1/bar dir1/dirA dir1/dirA/bar dir1/dirA/foo dir1/dirB dir1/dirB/bar dir1/dirB/foo dir1/foo $ hg log -G -T '{rev} {node|short}{if(ellipsis, "...")} {files}\n' @ 9 c87ca422d521 dir1/dirA/foo | o 8 951b8a83924e... dir2/dirB/bar | o 7 8e80155d5445 dir1/dirB/bar | o 6 406760310428 dir1/dirB/foo | o 5 623466a5f475 dir1/dirA/bar | o 4 06ff3a5be997 dir1/dirA/foo | o 3 33227af02764... dir2/bar | o 2 594bc4b13d4a dir1/bar | o 1 47f480a08324 dir1/foo | o 0 2a4f0c3b67da... root Illegal patterns are rejected $ hg tracked --addinclude glob:** abort: invalid prefix on narrow pattern: glob:** (narrow patterns must begin with one of the following: path:, rootfilesin:) [255] $ hg tracked --addexclude set:ignored abort: invalid prefix on narrow pattern: set:ignored (narrow patterns must begin with one of the following: path:, rootfilesin:) [255] $ cat .hg/store/narrowspec [include] path:dir1 path:dir1/dirA [exclude] $ cat > .hg/store/narrowspec << EOF > [include] > glob:** > EOF $ hg tracked abort: invalid prefix on narrow pattern: glob:** (narrow patterns must begin with one of the following: path:, rootfilesin:) [255] $ cat > .hg/store/narrowspec << EOF > [include] > path:. > [exclude] > set:ignored > EOF $ hg tracked abort: invalid prefix on narrow pattern: set:ignored (narrow patterns must begin with one of the following: path:, rootfilesin:) [255] diff --git a/tests/test-narrow-share.t b/tests/test-narrow-share.t --- a/tests/test-narrow-share.t +++ b/tests/test-narrow-share.t @@ -1,197 +1,198 @@ #testcases flat tree #testcases safe normal #if safe $ echo "[format]" >> $HGRCPATH $ echo "exp-share-safe = True" >> $HGRCPATH #endif $ . "$TESTDIR/narrow-library.sh" #if tree $ cat << EOF >> $HGRCPATH > [experimental] > treemanifest = 1 > EOF #endif $ cat << EOF >> $HGRCPATH > [extensions] > share = > EOF $ hg init remote $ cd remote $ for x in `$TESTDIR/seq.py 0 10` > do > mkdir d$x > echo $x > d$x/f > hg add d$x/f > hg commit -m "add d$x/f" > done $ cd .. $ hg clone --narrow ssh://user@dummy/remote main -q \ > --include d1 --include d3 --include d5 --include d7 Ignore file called "ignored" $ echo ignored > main/.hgignore $ hg share main share updating working directory 4 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg -R share tracked I path:d1 I path:d3 I path:d5 I path:d7 $ hg -R share files share/d1/f share/d3/f share/d5/f share/d7/f Narrow the share and check that the main repo's working copy gets updated # Make sure the files that are supposed to be known-clean get their timestamps set in the dirstate $ sleep 2 $ hg -R main st $ hg -R main debugdirstate --no-dates n 644 2 set d1/f n 644 2 set d3/f n 644 2 set d5/f n 644 2 set d7/f # Make d3/f dirty $ echo x >> main/d3/f $ echo y >> main/d3/g $ touch main/d3/ignored $ touch main/d3/untracked $ hg add main/d3/g $ hg -R main st M d3/f A d3/g ? d3/untracked # Make d5/f not match the dirstate timestamp even though it's clean $ sleep 2 $ hg -R main st M d3/f A d3/g ? d3/untracked $ hg -R main debugdirstate --no-dates n 644 2 set d1/f n 644 2 set d3/f a 0 -1 unset d3/g n 644 2 set d5/f n 644 2 set d7/f $ touch main/d5/f $ hg -R share tracked --removeinclude d1 --removeinclude d3 --removeinclude d5 comparing with ssh://user@dummy/remote searching for changes looking for local changes to affected paths deleting data/d1/f.i deleting data/d3/f.i deleting data/d5/f.i deleting meta/d1/00manifest.i (tree !) deleting meta/d3/00manifest.i (tree !) deleting meta/d5/00manifest.i (tree !) + deleting unwanted files from working copy $ hg -R main tracked I path:d7 $ hg -R main files abort: working copy's narrowspec is stale (run 'hg tracked --update-working-copy') [255] $ hg -R main tracked --update-working-copy not deleting possibly dirty file d3/f not deleting possibly dirty file d3/g not deleting possibly dirty file d5/f not deleting unknown file d3/untracked not deleting ignored file d3/ignored # d1/f, d3/f, d3/g and d5/f should no longer be reported $ hg -R main files main/d7/f # d1/f should no longer be there, d3/f should be since it was dirty, d3/g should be there since # it was added, and d5/f should be since we couldn't be sure it was clean $ find main/d* -type f | sort main/d3/f main/d3/g main/d3/ignored main/d3/untracked main/d5/f main/d7/f Widen the share and check that the main repo's working copy gets updated $ hg -R share tracked --addinclude d1 --addinclude d3 -q $ hg -R share tracked I path:d1 I path:d3 I path:d7 $ hg -R share files share/d1/f share/d3/f share/d7/f $ hg -R main tracked I path:d1 I path:d3 I path:d7 $ hg -R main files abort: working copy's narrowspec is stale (run 'hg tracked --update-working-copy') [255] $ hg -R main tracked --update-working-copy # d1/f, d3/f should be back $ hg -R main files main/d1/f main/d3/f main/d7/f # d3/f should be modified (not clobbered by the widening), and d3/g should be untracked $ hg -R main st --all M d3/f ? d3/g ? d3/untracked I d3/ignored C d1/f C d7/f We should also be able to unshare without breaking everything: $ hg share main share-unshare updating working directory 3 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd share-unshare $ hg unshare $ hg verify checking changesets checking manifests checking directory manifests (tree !) crosschecking files in changesets and manifests checking files checked 11 changesets with 3 changes to 3 files $ cd .. Dirstate should be left alone when upgrading from version of hg that didn't support narrow+share $ hg share main share-upgrade updating working directory 3 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd share-upgrade $ echo x >> d1/f $ echo y >> d3/g $ hg add d3/g $ hg rm d7/f $ hg st M d1/f A d3/g R d7/f Make it look like a repo from before narrow+share was supported $ rm .hg/narrowspec.dirstate $ hg ci -Am test abort: working copy's narrowspec is stale (run 'hg tracked --update-working-copy') [255] $ hg tracked --update-working-copy $ hg st M d1/f A d3/g R d7/f $ cd .. diff --git a/tests/test-narrow-trackedcmd.t b/tests/test-narrow-trackedcmd.t --- a/tests/test-narrow-trackedcmd.t +++ b/tests/test-narrow-trackedcmd.t @@ -1,229 +1,231 @@ #testcases flat tree $ . "$TESTDIR/narrow-library.sh" #if tree $ cat << EOF >> $HGRCPATH > [experimental] > treemanifest = 1 > EOF #endif $ hg init master $ cd master $ cat >> .hg/hgrc < [narrow] > serveellipses=True > EOF $ mkdir inside $ echo 'inside' > inside/f $ hg add inside/f $ hg commit -m 'add inside' $ mkdir widest $ echo 'widest' > widest/f $ hg add widest/f $ hg commit -m 'add widest' $ mkdir outside $ echo 'outside' > outside/f $ hg add outside/f $ hg commit -m 'add outside' $ cd .. narrow clone the inside file $ hg clone --narrow ssh://user@dummy/master narrow --include inside requesting all changes adding changesets adding manifests adding file changes added 2 changesets with 1 changes to 1 files new changesets *:* (glob) updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd narrow $ hg tracked I path:inside $ ls -A .hg inside $ cat inside/f inside $ cd .. add more upstream files which we will include in a wider narrow spec $ cd master $ mkdir wider $ echo 'wider' > wider/f $ hg add wider/f $ echo 'widest v2' > widest/f $ hg commit -m 'add wider, update widest' $ echo 'widest v3' > widest/f $ hg commit -m 'update widest v3' $ echo 'inside v2' > inside/f $ hg commit -m 'update inside' $ mkdir outside2 $ echo 'outside2' > outside2/f $ hg add outside2/f $ hg commit -m 'add outside2' $ echo 'widest v4' > widest/f $ hg commit -m 'update widest v4' $ hg log -T "{if(ellipsis, '...')}{rev}: {desc}\n" 7: update widest v4 6: add outside2 5: update inside 4: update widest v3 3: add wider, update widest 2: add outside 1: add widest 0: add inside $ cd .. Testing the --import-rules flag of `hg tracked` command $ cd narrow $ hg tracked --import-rules hg tracked: option --import-rules requires argument hg tracked [OPTIONS]... [REMOTE] show or change the current narrowspec options ([+] can be repeated): --addinclude VALUE [+] new paths to include --removeinclude VALUE [+] old paths to no longer include --auto-remove-includes automatically choose unused includes to remove --addexclude VALUE [+] new paths to exclude --import-rules VALUE import narrowspecs from a file --removeexclude VALUE [+] old paths to no longer exclude --clear whether to replace the existing narrowspec --force-delete-local-changes forces deletion of local changes when narrowing --[no-]backup back up local changes when narrowing (default: on) --update-working-copy update working copy when the store has changed -e --ssh CMD specify ssh command to use --remotecmd CMD specify hg command to run on the remote side --insecure do not verify server certificate (ignoring web.cacerts config) (use 'hg tracked -h' to show more help) [10] $ hg tracked --import-rules doesnotexist abort: cannot read narrowspecs from '$TESTTMP/narrow/doesnotexist': $ENOENT$ [50] $ cat > specs < %include foo > [include] > path:widest/ > [exclude] > path:inside/ > EOF $ hg tracked --import-rules specs abort: including other spec files using '%include' is not supported in narrowspec [10] $ cat > specs < [include] > outisde > [exclude] > inside > EOF $ hg tracked --import-rules specs comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/inside/f.i deleting meta/inside/00manifest.i (tree !) + deleting unwanted files from working copy saved backup bundle to $TESTTMP/narrow/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 2 changesets with 0 changes to 0 files $ hg tracked I path:outisde X path:inside Testing the --import-rules flag with --addinclude and --addexclude $ cat > specs < [include] > widest > EOF $ hg tracked --import-rules specs --addinclude 'wider/' comparing with ssh://user@dummy/master searching for changes saved backup bundle to $TESTTMP/narrow/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 3 changesets with 1 changes to 1 files $ hg tracked I path:outisde I path:wider I path:widest X path:inside $ cat > specs < [exclude] > outside2 > EOF $ hg tracked --import-rules specs --addexclude 'widest' comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/widest/f.i deleting meta/widest/00manifest.i (tree !) + deleting unwanted files from working copy $ hg tracked I path:outisde I path:wider X path:inside X path:outside2 X path:widest $ hg tracked --import-rules specs --clear abort: the --clear option is not yet supported [10] Testing with passing a out of wdir file $ cat > ../nspecs < [include] > widest > EOF $ hg tracked --import-rules ../nspecs comparing with ssh://user@dummy/master searching for changes saved backup bundle to $TESTTMP/narrow/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 3 changesets with 0 changes to 0 files $ cd .. Testing tracked command on a non-narrow repo $ hg init non-narrow $ cd non-narrow $ hg tracked --addinclude foobar abort: the tracked command is only supported on repositories cloned with --narrow [10] diff --git a/tests/test-narrow.t b/tests/test-narrow.t --- a/tests/test-narrow.t +++ b/tests/test-narrow.t @@ -1,524 +1,541 @@ #testcases flat tree #testcases lfs-on lfs-off $ cat >> $HGRCPATH << EOF > [experimental] > evolution=createmarkers > EOF #if lfs-on $ cat >> $HGRCPATH < [extensions] > lfs = > EOF #endif $ . "$TESTDIR/narrow-library.sh" #if tree $ cat << EOF >> $HGRCPATH > [experimental] > treemanifest = 1 > EOF #endif $ hg init master $ cd master $ cat >> .hg/hgrc < [narrow] > serveellipses=True > EOF $ for x in `$TESTDIR/seq.py 0 10` > do > mkdir d$x > echo $x > d$x/f > hg add d$x/f > hg commit -m "add d$x/f" > done $ hg log -T "{rev}: {desc}\n" 10: add d10/f 9: add d9/f 8: add d8/f 7: add d7/f 6: add d6/f 5: add d5/f 4: add d4/f 3: add d3/f 2: add d2/f 1: add d1/f 0: add d0/f $ cd .. Error if '.' or '..' are in the directory to track. $ hg clone --narrow ssh://user@dummy/master foo --include ./asdf abort: "." and ".." are not allowed in narrowspec paths [255] $ hg clone --narrow ssh://user@dummy/master foo --include asdf/.. abort: "." and ".." are not allowed in narrowspec paths [255] $ hg clone --narrow ssh://user@dummy/master foo --include a/./c abort: "." and ".." are not allowed in narrowspec paths [255] Names with '.' in them are OK. $ hg clone --narrow ./master should-work --include a/.b/c requesting all changes adding changesets adding manifests adding file changes added 1 changesets with 0 changes to 0 files new changesets * (glob) updating to branch default 0 files updated, 0 files merged, 0 files removed, 0 files unresolved Test repo with local changes $ hg clone --narrow ssh://user@dummy/master narrow-local-changes --include d0 --include d3 --include d6 requesting all changes adding changesets adding manifests adding file changes added 6 changesets with 3 changes to 3 files new changesets *:* (glob) updating to branch default 3 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd narrow-local-changes $ echo local change >> d0/f $ hg ci -m 'local change to d0' $ hg co '.^' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ echo local change >> d3/f $ hg ci -m 'local hidden change to d3' created new head $ hg ci --amend -m 'local change to d3' $ hg tracked --removeinclude d0 comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths The following changeset(s) or their ancestors have local changes not on the remote: * (glob) abort: local changes found (use --force-delete-local-changes to ignore) [20] Check that nothing was removed by the failed attempts $ hg tracked I path:d0 I path:d3 I path:d6 $ hg files d0/f d3/f d6/f $ find * d0 d0/f d3 d3/f d6 d6/f $ hg verify -q Force deletion of local changes $ hg log -T "{rev}: {desc} {outsidenarrow}\n" 8: local change to d3 6: local change to d0 5: add d10/f outsidenarrow 4: add d6/f 3: add d5/f outsidenarrow 2: add d3/f 1: add d2/f outsidenarrow 0: add d0/f $ hg tracked --removeinclude d0 --force-delete-local-changes comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths The following changeset(s) or their ancestors have local changes not on the remote: * (glob) + moving unwanted changesets to backup saved backup bundle to $TESTTMP/narrow-local-changes/.hg/strip-backup/*-narrow.hg (glob) deleting data/d0/f.i (reporevlogstore !) deleting meta/d0/00manifest.i (tree !) deleting data/d0/f/362fef284ce2ca02aecc8de6d5e8a1c3af0556fe (reposimplestore !) deleting data/d0/f/4374b5650fc5ae54ac857c0f0381971fdde376f7 (reposimplestore !) deleting data/d0/f/index (reposimplestore !) + deleting unwanted files from working copy $ hg log -T "{rev}: {desc} {outsidenarrow}\n" 7: local change to d3 5: add d10/f outsidenarrow 4: add d6/f 3: add d5/f outsidenarrow 2: add d3/f 1: add d2/f outsidenarrow 0: add d0/f outsidenarrow Can restore stripped local changes after widening $ hg tracked --addinclude d0 -q $ hg unbundle .hg/strip-backup/*-narrow.hg -q $ hg --hidden co -r 'desc("local change to d0")' -q $ cat d0/f 0 local change Pruned commits affecting removed paths should not prevent narrowing $ hg co '.^' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg debugobsolete `hg log -T '{node}' -r 'desc("local change to d0")'` 1 new obsolescence markers obsoleted 1 changesets $ hg tracked --removeinclude d0 comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths + moving unwanted changesets to backup saved backup bundle to $TESTTMP/narrow-local-changes/.hg/strip-backup/*-narrow.hg (glob) deleting data/d0/f.i (reporevlogstore !) deleting meta/d0/00manifest.i (tree !) deleting data/d0/f/362fef284ce2ca02aecc8de6d5e8a1c3af0556fe (reposimplestore !) deleting data/d0/f/4374b5650fc5ae54ac857c0f0381971fdde376f7 (reposimplestore !) deleting data/d0/f/index (reposimplestore !) + deleting unwanted files from working copy Updates off of stripped commit if necessary $ hg co -r 'desc("local change to d3")' -q $ echo local change >> d6/f $ hg ci -m 'local change to d6' $ hg tracked --removeinclude d3 --force-delete-local-changes comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths The following changeset(s) or their ancestors have local changes not on the remote: * (glob) * (glob) 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + moving unwanted changesets to backup saved backup bundle to $TESTTMP/narrow-local-changes/.hg/strip-backup/*-narrow.hg (glob) deleting data/d3/f.i (reporevlogstore !) deleting meta/d3/00manifest.i (tree !) deleting data/d3/f/2661d26c649684b482d10f91960cc3db683c38b4 (reposimplestore !) deleting data/d3/f/99fa7136105a15e2045ce3d9152e4837c5349e4d (reposimplestore !) deleting data/d3/f/index (reposimplestore !) + deleting unwanted files from working copy $ hg log -T '{desc}\n' -r . add d10/f Updates to nullid if necessary $ hg tracked --addinclude d3 -q $ hg co null -q $ mkdir d3 $ echo local change > d3/f $ hg add d3/f $ hg ci -m 'local change to d3' created new head $ hg tracked --removeinclude d3 --force-delete-local-changes comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths The following changeset(s) or their ancestors have local changes not on the remote: * (glob) 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + moving unwanted changesets to backup saved backup bundle to $TESTTMP/narrow-local-changes/.hg/strip-backup/*-narrow.hg (glob) deleting data/d3/f.i (reporevlogstore !) deleting meta/d3/00manifest.i (tree !) deleting data/d3/f/2661d26c649684b482d10f91960cc3db683c38b4 (reposimplestore !) deleting data/d3/f/5ce0767945cbdbca3b924bb9fbf5143f72ab40ac (reposimplestore !) deleting data/d3/f/index (reposimplestore !) + deleting unwanted files from working copy $ hg id 000000000000 $ cd .. Narrowing doesn't resurrect old commits (unlike what regular `hg strip` does) $ hg clone --narrow ssh://user@dummy/master narrow-obsmarkers --include d0 --include d3 -q $ cd narrow-obsmarkers $ echo a >> d0/f2 $ hg add d0/f2 $ hg ci -m 'modify d0/' $ echo a >> d3/f2 $ hg add d3/f2 $ hg commit --amend -m 'modify d0/ and d3/' $ hg log -T "{rev}: {desc}\n" 5: modify d0/ and d3/ 3: add d10/f 2: add d3/f 1: add d2/f 0: add d0/f $ hg tracked --removeinclude d3 --force-delete-local-changes -q $ hg log -T "{rev}: {desc}\n" 3: add d10/f 2: add d3/f 1: add d2/f 0: add d0/f $ cd .. Widening doesn't lose bookmarks $ hg clone --narrow ssh://user@dummy/master widen-bookmarks --include d0 -q $ cd widen-bookmarks $ hg bookmark my-bookmark $ hg log -T "{rev}: {desc} {bookmarks}\n" 1: add d10/f my-bookmark 0: add d0/f $ hg tracked --addinclude d3 -q $ hg log -T "{rev}: {desc} {bookmarks}\n" 3: add d10/f my-bookmark 2: add d3/f 1: add d2/f 0: add d0/f $ cd .. Can remove last include, making repo empty $ hg clone --narrow ssh://user@dummy/master narrow-empty --include d0 -r 5 adding changesets adding manifests adding file changes added 2 changesets with 1 changes to 1 files new changesets *:* (glob) updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd narrow-empty $ hg tracked --removeinclude d0 comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/d0/f.i (reporevlogstore !) deleting meta/d0/00manifest.i (tree !) deleting data/d0/f/362fef284ce2ca02aecc8de6d5e8a1c3af0556fe (reposimplestore !) deleting data/d0/f/index (reposimplestore !) + deleting unwanted files from working copy $ hg tracked $ hg files [1] $ test -d d0 [1] Do some work in the empty clone $ hg diff --change . $ hg branch foo marked working directory as branch foo (branches are permanent and global, did you want a bookmark?) $ hg ci -m empty $ hg log -T "{rev}: {desc} {outsidenarrow}\n" 2: empty 1: add d5/f outsidenarrow 0: add d0/f outsidenarrow $ hg pull -q Can widen the empty clone $ hg tracked --addinclude d0 comparing with ssh://user@dummy/master searching for changes saved backup bundle to $TESTTMP/narrow-empty/.hg/strip-backup/*-widen.hg (glob) adding changesets adding manifests adding file changes added 3 changesets with 1 changes to 1 files $ hg tracked I path:d0 $ hg files d0/f $ find * d0 d0/f $ cd .. TODO(martinvonz): test including e.g. d3/g and then removing it once https://bitbucket.org/Google/narrowhg/issues/6 is fixed $ hg clone --narrow ssh://user@dummy/master narrow --include d0 --include d3 --include d6 --include d9 requesting all changes adding changesets adding manifests adding file changes added 8 changesets with 4 changes to 4 files new changesets *:* (glob) updating to branch default 4 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd narrow $ hg tracked I path:d0 I path:d3 I path:d6 I path:d9 $ hg tracked --removeinclude d6 comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/d6/f.i (reporevlogstore !) deleting meta/d6/00manifest.i (tree !) deleting data/d6/f/7339d30678f451ac8c3f38753beeb4cf2e1655c7 (reposimplestore !) deleting data/d6/f/index (reposimplestore !) + deleting unwanted files from working copy $ hg tracked I path:d0 I path:d3 I path:d9 #if repofncache $ hg debugrebuildfncache fncache already up to date #endif $ find * d0 d0/f d3 d3/f d9 d9/f $ hg verify -q $ hg tracked --addexclude d3/f comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/d3/f.i (reporevlogstore !) deleting data/d3/f/2661d26c649684b482d10f91960cc3db683c38b4 (reposimplestore !) deleting data/d3/f/index (reposimplestore !) + deleting unwanted files from working copy $ hg tracked I path:d0 I path:d3 I path:d9 X path:d3/f #if repofncache $ hg debugrebuildfncache fncache already up to date #endif $ find * d0 d0/f d9 d9/f $ hg verify -q $ hg tracked --addexclude d0 comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/d0/f.i (reporevlogstore !) deleting meta/d0/00manifest.i (tree !) deleting data/d0/f/362fef284ce2ca02aecc8de6d5e8a1c3af0556fe (reposimplestore !) deleting data/d0/f/index (reposimplestore !) + deleting unwanted files from working copy $ hg tracked I path:d3 I path:d9 X path:d0 X path:d3/f #if repofncache $ hg debugrebuildfncache fncache already up to date #endif $ find * d9 d9/f Make a 15 of changes to d9 to test the path without --verbose (Note: using regexes instead of "* (glob)" because if the test fails, it produces more sensible diffs) $ hg tracked I path:d3 I path:d9 X path:d0 X path:d3/f $ for x in `$TESTDIR/seq.py 1 15` > do > echo local change >> d9/f > hg commit -m "change $x to d9/f" > done $ hg tracked --removeinclude d9 comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths The following changeset(s) or their ancestors have local changes not on the remote: ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ...and 5 more, use --verbose to list all abort: local changes found (use --force-delete-local-changes to ignore) [20] Now test it *with* verbose. $ hg tracked --removeinclude d9 --verbose comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths The following changeset(s) or their ancestors have local changes not on the remote: ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) ^[0-9a-f]{12}$ (re) abort: local changes found (use --force-delete-local-changes to ignore) [20] $ cd .. Test --auto-remove-includes $ hg clone --narrow ssh://user@dummy/master narrow-auto-remove -q \ > --include d0 --include d1 --include d2 $ cd narrow-auto-remove $ echo a >> d0/f $ hg ci -m 'local change to d0' $ hg co '.^' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ echo a >> d1/f $ hg ci -m 'local change to d1' created new head $ hg debugobsolete $(hg log -T '{node}' -r 'desc("local change to d0")') 1 new obsolescence markers obsoleted 1 changesets $ echo n | hg tracked --auto-remove-includes --config ui.interactive=yes comparing with ssh://user@dummy/master searching for changes looking for unused includes to remove path:d0 path:d2 remove these unused includes (yn)? n $ hg tracked --auto-remove-includes comparing with ssh://user@dummy/master searching for changes looking for unused includes to remove path:d0 path:d2 remove these unused includes (yn)? y looking for local changes to affected paths + moving unwanted changesets to backup saved backup bundle to $TESTTMP/narrow-auto-remove/.hg/strip-backup/*-narrow.hg (glob) deleting data/d0/f.i deleting data/d2/f.i deleting meta/d0/00manifest.i (tree !) deleting meta/d2/00manifest.i (tree !) + deleting unwanted files from working copy $ hg tracked I path:d1 $ hg files d1/f $ hg tracked --auto-remove-includes comparing with ssh://user@dummy/master searching for changes looking for unused includes to remove found no unused includes Test --no-backup $ hg tracked --addinclude d0 --addinclude d2 -q $ hg unbundle .hg/strip-backup/*-narrow.hg -q $ rm .hg/strip-backup/* $ hg tracked --auto-remove-includes --no-backup comparing with ssh://user@dummy/master searching for changes looking for unused includes to remove path:d0 path:d2 remove these unused includes (yn)? y looking for local changes to affected paths + deleting unwanted changesets deleting data/d0/f.i deleting data/d2/f.i deleting meta/d0/00manifest.i (tree !) deleting meta/d2/00manifest.i (tree !) + deleting unwanted files from working copy $ ls .hg/strip-backup/ Test removing include while concurrently modifying file in that path $ hg clone --narrow ssh://user@dummy/master narrow-concurrent-modify -q \ > --include d0 --include d1 $ cd narrow-concurrent-modify $ hg --config 'hooks.pretxnopen = echo modified >> d0/f' tracked --removeinclude d0 comparing with ssh://user@dummy/master searching for changes looking for local changes to affected paths deleting data/d0/f.i deleting meta/d0/00manifest.i (tree !) + deleting unwanted files from working copy not deleting possibly dirty file d0/f