Mercurial > hg
changeset 35213:24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
We do the same thing on clone for the largefiles extension, as a convenience.
Similar to largefiles, it's probably safer to only enable this extension on a
per repo basis because it is trivial to add an lfs file. And that gives the
repository some centralized VCS characteristics.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 16 Nov 2017 20:23:20 -0500 |
parents | c7b45db8f317 |
children | a8c778b2a689 |
files | hgext/lfs/__init__.py hgext/lfs/wrapper.py tests/test-lfs.t |
diffstat | 3 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/lfs/__init__.py Sat Dec 02 16:29:49 2017 +0900 +++ b/hgext/lfs/__init__.py Thu Nov 16 20:23:20 2017 -0500 @@ -37,6 +37,7 @@ exchange, extensions, filelog, + hg, localrepo, registrar, revlog, @@ -151,6 +152,8 @@ ), ) + 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.
--- a/hgext/lfs/wrapper.py Sat Dec 02 16:29:49 2017 +0900 +++ b/hgext/lfs/wrapper.py Thu Nov 16 20:23:20 2017 -0500 @@ -202,6 +202,25 @@ 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)
--- a/tests/test-lfs.t Sat Dec 02 16:29:49 2017 +0900 +++ b/tests/test-lfs.t Thu Nov 16 20:23:20 2017 -0500 @@ -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