diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py --- a/hgext/lfs/wrapper.py +++ b/hgext/lfs/wrapper.py @@ -46,7 +46,13 @@ '''Wrap server command to announce lfs server capability''' caps = orig(repo, proto) if util.safehasattr(repo.svfs, 'lfslocalblobstore'): - # XXX: change to 'lfs=serve' when separate git server isn't required? + # Advertise a slightly different capability when lfs is *required*, so + # that the client knows it MUST load the extension. If lfs is not + # required on the server, there's no reason to autoload the extension + # on the client. + if b'lfs' in repo.requirements: + caps.append('lfs-serve') + caps.append('lfs') return caps diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -578,6 +578,23 @@ createopts['narrowfiles'] = True + if srcpeer.capable(b'lfs-serve'): + # Repository creation honors the config if it disabled the extension, so + # we can't just announce that lfs will be enabled. This check avoids + # saying that lfs will be enabled, and then saying it's an unknown + # feature. The lfs creation option is set in either case so that a + # requirement is added. If the extension is explicitly disabled but the + # requirement is set, the clone aborts early, before transferring any + # data. + createopts['lfs'] = True + + if extensions.disabledext('lfs'): + ui.status(_('(remote is using large file support (lfs), but it is ' + 'explicitly disabled in the local configuration)\n')) + else: + ui.status(_('(remote is using large file support (lfs); lfs will ' + 'be enabled for this repository)\n')) + shareopts = shareopts or {} sharepool = shareopts.get('pool') sharenamemode = shareopts.get('mode') diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -2895,6 +2895,9 @@ if createopts.get('narrowfiles'): requirements.add(repository.NARROW_REQUIREMENT) + if createopts.get('lfs'): + requirements.add('lfs') + return requirements def filterknowncreateopts(ui, createopts): @@ -2912,6 +2915,7 @@ they know how to handle. """ known = { + 'lfs', 'backend', 'narrowfiles', 'sharedrepo', @@ -2931,6 +2935,9 @@ backend The storage backend to use. + lfs + Repository will be created with ``lfs`` requirement. The lfs extension + will automatically be loaded when the repository is accessed. narrowfiles Set up repository to support narrow file storage. sharedrepo diff --git a/tests/test-lfs-serve-access.t b/tests/test-lfs-serve-access.t --- a/tests/test-lfs-serve-access.t +++ b/tests/test-lfs-serve-access.t @@ -42,6 +42,7 @@ Downloads fail... $ hg clone http://localhost:$HGPORT httpclone + (remote is using large file support (lfs); lfs will be enabled for this repository) requesting all changes adding changesets adding manifests @@ -76,6 +77,7 @@ $ hg clone --debug http://localhost:$HGPORT/subdir/mount/point cloned2 using http://localhost:$HGPORT/subdir/mount/point sending capabilities command + (remote is using large file support (lfs); lfs will be enabled for this repository) query 1; heads sending batch command requesting all changes @@ -88,7 +90,6 @@ adding file changes adding lfs.bin revisions added 1 changesets with 1 changes to 1 files - calling hook pretxnchangegroup.lfs: hgext.lfs.checkrequireslfs bundle2-input-part: total payload size 648 bundle2-input-part: "listkeys" (params: 1 mandatory) supported bundle2-input-part: "phase-heads" supported @@ -239,6 +240,7 @@ Test an I/O error in localstore.verify() (Batch API) with GET $ hg clone http://localhost:$HGPORT1 httpclone2 + (remote is using large file support (lfs); lfs will be enabled for this repository) requesting all changes adding changesets adding manifests diff --git a/tests/test-lfs-serve.t b/tests/test-lfs-serve.t --- a/tests/test-lfs-serve.t +++ b/tests/test-lfs-serve.t @@ -304,10 +304,10 @@ $ grep 'lfs' .hg/requires $SERVER_REQUIRES $TESTTMP/server/.hg/requires:lfs -TODO: fail more gracefully. - - $ hg clone -q http://localhost:$HGPORT $TESTTMP/client4_clone - abort: HTTP Error 500: Internal Server Error + $ hg clone http://localhost:$HGPORT $TESTTMP/client4_clone + (remote is using large file support (lfs), but it is explicitly disabled in the local configuration) + abort: repository requires features unknown to this Mercurial: lfs! + (see https://mercurial-scm.org/wiki/MissingRequirement for more information) [255] $ grep 'lfs' $TESTTMP/client4_clone/.hg/requires $SERVER_REQUIRES grep: $TESTTMP/client4_clone/.hg/requires: $ENOENT$ @@ -661,8 +661,6 @@ $ cat $TESTTMP/errors.log | grep '^[A-Z]' Traceback (most recent call last): ValueError: no common changegroup version - Traceback (most recent call last): - ValueError: no common changegroup version #else $ cat $TESTTMP/errors.log #endif