diff --git a/hgext3rd/sparse.py b/hgext3rd/sparse.py --- a/hgext3rd/sparse.py +++ b/hgext3rd/sparse.py @@ -9,7 +9,7 @@ """ from mercurial import util, cmdutil, extensions, context, dirstate, commands -from mercurial import localrepo, error, hg, registrar +from mercurial import localrepo, error, hg, registrar, scmutil from mercurial import match as matchmod from mercurial import merge as mergemod from mercurial.node import nullid @@ -657,6 +657,12 @@ --clear-rules removes all local include and exclude rules, while leaving any enabled profiles in place. + The following config option defines whether sparse treats supplied + paths as relative to repo root or to the current working dir: + + [sparse] + reporootpaths = on + Returns 0 if editing the sparse checkout succeeds. """ include = opts.get('include') @@ -736,6 +742,10 @@ newprofiles = set(oldprofiles) oldstatus = repo.status() + if not ui.configbool('sparse', 'reporootpaths', True): + # supplied file patterns should be treated as relative + # to current working dir, so we need to convert them first + pats = scmutil.match(repo['.'], pats).files() if any(pat.startswith('/') for pat in pats): err = _('paths cannot start with /') diff --git a/tests/test-sparse.t b/tests/test-sparse.t --- a/tests/test-sparse.t +++ b/tests/test-sparse.t @@ -38,6 +38,23 @@ (do not use absolute paths) [255] +Repo root-relaive vs. cwd-relative includes + $ mkdir subdir + $ cd subdir + $ hg sparse --config sparse.reporootpaths=on --include reporoot/path + $ hg sparse --config sparse.reporootpaths=off --include cwd/path + $ hg sparse + [include] + $TESTTMP/myrepo/hide + hide + reporoot/path + subdir/cwd/path + [exclude] + + + $ cd .. + $ rm -rf subdir + Verify commiting while sparse includes other files $ echo z > hide