diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py --- a/hgext/lfs/__init__.py +++ b/hgext/lfs/__init__.py @@ -226,9 +226,11 @@ def reposetup(ui, repo): s = repo.set('%n:%n', _bin(kwargs[r'node']), _bin(last)) else: s = repo.set('%n', _bin(kwargs[r'node'])) + match = repo.narrowmatch() for ctx in s: # TODO: is there a way to just walk the files in the commit? - if any(ctx[f].islfs() for f in ctx.files() if f in ctx): + if any(ctx[f].islfs() for f in ctx.files() + if f in ctx and match(f)): repo.requirements.add('lfs') repo._writerequirements() repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) diff --git a/tests/test-narrow-commit.t b/tests/test-narrow-commit.t --- a/tests/test-narrow-commit.t +++ b/tests/test-narrow-commit.t @@ -28,7 +28,11 @@ create full repo $ cd .. - $ hg clone --narrow ssh://user@dummy/master narrow --include inside +(The lfs extension does nothing here, but this test ensures that its hook that +determines whether to add the lfs requirement, respects the narrow boundaries.) + + $ hg --config extensions.lfs= clone --narrow ssh://user@dummy/master narrow \ + > --include inside requesting all changes adding changesets adding manifests