diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py index 6864c405f0235d5c42937658049f0405d5d1abdc_aGdleHQvbGZzL19faW5pdF9fLnB5..e0a1b9ee93cdfb40ba43e8838a1edf4ea3ea24f3_aGdleHQvbGZzL19faW5pdF9fLnB5 100644 --- a/hgext/lfs/__init__.py +++ b/hgext/lfs/__init__.py @@ -37,6 +37,7 @@ exchange, extensions, filelog, + localrepo, registrar, revlog, scmutil, @@ -84,6 +85,13 @@ templatekeyword = registrar.templatekeyword() +def featuresetup(ui, supported): + # don't die on seeing a repo with the lfs requirement + supported |= {'lfs'} + +def uisetup(ui): + localrepo.localrepository.featuresetupfuncs.add(featuresetup) + def reposetup(ui, repo): # Nothing to do with a remote repo if not repo.local(): @@ -98,6 +106,17 @@ # Push hook repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) + if 'lfs' not in repo.requirements: + def checkrequireslfs(ui, repo, **kwargs): + if 'lfs' not in repo.requirements: + ctx = repo[kwargs['node']] + # TODO: is there a way to just walk the files in the commit? + if any(ctx[f].islfs() for f in ctx.files()): + repo.requirements.add('lfs') + repo._writerequirements() + + ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs') + def wrapfilelog(filelog): wrapfunction = extensions.wrapfunction diff --git a/tests/test-lfs.t b/tests/test-lfs.t index 6864c405f0235d5c42937658049f0405d5d1abdc_dGVzdHMvdGVzdC1sZnMudA==..e0a1b9ee93cdfb40ba43e8838a1edf4ea3ea24f3_dGVzdHMvdGVzdC1sZnMudA== 100644 --- a/tests/test-lfs.t +++ b/tests/test-lfs.t @@ -20,4 +20,6 @@ # Commit large file $ echo $LONG > largefile + $ grep lfs .hg/requires + [1] $ hg commit --traceback -Aqm "add large file" @@ -23,4 +25,6 @@ $ hg commit --traceback -Aqm "add large file" + $ grep lfs .hg/requires + lfs # Ensure metadata is stored $ hg debugdata largefile 0