diff hgext/lfs/wrapper.py @ 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 f8f939a2926c
children a8c778b2a689
line wrap: on
line diff
--- 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)