diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py --- a/hgext/lfs/__init__.py +++ b/hgext/lfs/__init__.py @@ -37,6 +37,7 @@ from mercurial import ( exchange, extensions, filelog, + hg, localrepo, registrar, revlog, @@ -151,6 +152,8 @@ def extsetup(ui): ), ) + wrapfunction(hg, 'clone', wrapper.hgclone) + # Make bundle choose changegroup3 instead of changegroup2. This affects # "hg bundle" command. Note: it does not cover all bundle formats like # "packed1". Using "packed1" with lfs will likely cause trouble. diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py --- a/hgext/lfs/wrapper.py +++ b/hgext/lfs/wrapper.py @@ -202,6 +202,25 @@ def vfsinit(orig, self, othervfs): if util.safehasattr(othervfs, name): setattr(self, name, getattr(othervfs, name)) +def hgclone(orig, ui, opts, *args, **kwargs): + result = orig(ui, opts, *args, **kwargs) + + if result is not None: + sourcerepo, destrepo = result + repo = destrepo.local() + + # When cloning to a remote repo (like through SSH), no repo is available + # from the peer. Therefore the hgrc can't be updated. + if not repo: + return result + + # If lfs is required for this repo, permanently enable it locally + if 'lfs' in repo.requirements: + with repo.vfs('hgrc', 'a', text=True) as fp: + fp.write('\n[extensions]\nlfs=\n') + + return result + def _canskipupload(repo): # if remotestore is a null store, upload is a no-op and can be skipped return isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote) diff --git a/tests/test-lfs.t b/tests/test-lfs.t --- a/tests/test-lfs.t +++ b/tests/test-lfs.t @@ -199,6 +199,8 @@ updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd repo7 + $ hg config extensions --debug | grep lfs + $TESTTMP/repo7/.hg/hgrc:*: extensions.lfs= (glob) $ cat large LARGE-BECAUSE-IT-IS-MORE-THAN-30-BYTES $ cat small