diff --git a/nbgrader/utils.py b/nbgrader/utils.py
index 55824f3f..55f440ab 100644
--- a/nbgrader/utils.py
+++ b/nbgrader/utils.py
@@ -194,8 +194,10 @@ def find_all_files(path, exclude=None):
     """Recursively finds all filenames rooted at `path`, optionally excluding
     some based on filename globs."""
     files = []
+    to_skip = []
     for dirname, dirnames, filenames in os.walk(path):
-        if is_ignored(dirname, exclude):
+        if is_ignored(dirname, exclude) or dirname in to_skip:
+            to_skip.extend([os.path.join(dirname, x) for x in dirnames])
             continue
         for filename in filenames:
             fullpath = os.path.join(dirname, filename)

Unexpected behaviour of utils.find_all_files
<!--
Thanks for helping to improve nbgrader!

If you are submitting a bug report or looking for support, please use the below
template so we can efficiently solve the problem.

If you are requesting a new feature, feel free to remove irrelevant pieces of
the issue template. 
-->


### Operating system
Ubunto 16.04

### `nbgrader --version`
nbgrader version 0.5.4

### `jupyterhub --version` (if used with JupyterHub)
0.8.1

### `jupyter notebook --version` 
5.4.1

### Expected behavior
By including '.git' or '.git/**' in CourseDirectory.ignore anything under the git directory to be ignored.

### Actual behavior
Anything in subdirectories of '.git' is included.

### Steps to reproduce the behavior
$ mkdir -p foo/bar/qwe
$ touch foo/bar/qwe/file.py
$ /opt/conda/bin/python -c "from nbgrader.utils import find_all_files;print(find_all_files('foo', ['bar']))"
['foo/bar/qwe/file.py']

I'm sorry if this is expected behaviour but I found it surprising.
diff --git a/nbgrader/tests/utils/test_utils.py b/nbgrader/tests/utils/test_utils.py
index 2814ea5c..ca76e83f 100644
--- a/nbgrader/tests/utils/test_utils.py
+++ b/nbgrader/tests/utils/test_utils.py
@@ -272,18 +272,34 @@ def test_is_ignored(temp_cwd):
 
 
 def test_find_all_files(temp_cwd):
-    os.makedirs(join("foo", "bar"))
+    os.makedirs(join("foo", "bar", "quux"))
     with open(join("foo", "baz.txt"), "w") as fh:
         fh.write("baz")
     with open(join("foo", "bar", "baz.txt"), "w") as fh:
         fh.write("baz")
+    with open(join("foo", "bar", "quux", "baz.txt"), "w") as fh:
+        fh.write("baz")
 
-    assert utils.find_all_files("foo") == [join("foo", "baz.txt"), join("foo", "bar", "baz.txt")]
+    assert utils.find_all_files("foo") == [
+        join("foo", "baz.txt"),
+        join("foo", "bar", "baz.txt"),
+        join("foo", "bar", "quux", "baz.txt")]
     assert utils.find_all_files("foo", ["bar"]) == [join("foo", "baz.txt")]
-    assert utils.find_all_files(join("foo", "bar")) == [join("foo", "bar", "baz.txt")]
+    assert utils.find_all_files("foo", ["quux"]) == [
+        join("foo", "baz.txt"),
+        join("foo", "bar", "baz.txt")]
+    assert utils.find_all_files(join("foo", "bar")) == [
+        join("foo", "bar", "baz.txt"),
+        join("foo", "bar", "quux", "baz.txt")]
     assert utils.find_all_files(join("foo", "bar"), ["*.txt"]) == []
-    assert utils.find_all_files(".") == [join(".", "foo", "baz.txt"), join(".", "foo", "bar", "baz.txt")]
+    assert utils.find_all_files(".") == [
+        join(".", "foo", "baz.txt"),
+        join(".", "foo", "bar", "baz.txt"),
+        join(".", "foo", "bar", "quux", "baz.txt")]
     assert utils.find_all_files(".", ["bar"]) == [join(".", "foo", "baz.txt")]
+    assert utils.find_all_files(".", ["quux"]) == [
+        join(".", "foo", "baz.txt"),
+        join(".", "foo", "bar", "baz.txt")]
 
 
 def test_unzip_invalid_ext(temp_cwd):

pip install -e .[dev]
parse_log_pytest
requirements.txt
pyenchant sphinxcontrib-spelling sphinx_rtd_theme nbval pytest
apt-get update apt-get install -y gcc
3.5
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
alembic==1.7.7
anyio==3.6.2
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
async-generator==1.10
attrs==22.2.0
Babel==2.11.0
backcall==0.2.0
bleach==4.1.0
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
comm==0.1.4
contextvars==2.4
coverage==6.2
dataclasses==0.8
decorator==5.1.1
defusedxml==0.7.1
docutils==0.18.1
entrypoints==0.4
greenlet==2.0.2
idna==3.10
imagesize==1.4.1
immutables==0.19
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig==1.1.1
ipykernel==5.5.6
ipython==7.16.3
ipython-genutils==0.2.0
ipywidgets==7.8.5
jedi==0.17.2
Jinja2==3.0.3
json5==0.9.16
jsonschema==3.2.0
jupyter==1.1.1
jupyter-client==7.1.2
jupyter-console==6.4.3
jupyter-core==4.9.2
jupyter-server==1.13.1
jupyterlab==3.2.9
jupyterlab-pygments==0.1.2
jupyterlab-server==2.10.3
jupyterlab_widgets==1.1.11
Mako==1.1.6
MarkupSafe==2.0.1
mistune==0.8.4
nbclassic==0.3.5
nbclient==0.5.9
nbconvert==6.0.7
nbformat==5.1.3
-e git+https://github.com/jupyter/nbgrader.git@bbc694e8ee4c1aa4eeaee0936491ff19b20bad60#egg=nbgrader
nbval==0.10.0
nest-asyncio==1.6.0
notebook==6.4.10
packaging==21.3
pandocfilters==1.5.1
parso==0.7.1
pexpect==4.9.0
pickleshare==0.7.5
pluggy==1.0.0
prometheus-client==0.17.1
prompt-toolkit==3.0.36
ptyprocess==0.7.0
py==1.11.0
pycparser==2.21
pyenchant==3.2.2
Pygments==2.14.0
pyparsing==3.1.4
pyrsistent==0.18.0
pytest==7.0.1
python-dateutil==2.9.0.post0
pytz==2025.2
pyzmq==25.1.2
requests==2.27.1
Send2Trash==1.8.3
six==1.17.0
sniffio==1.2.0
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinx-rtd-theme==2.0.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
sphinxcontrib-spelling==7.7.0
SQLAlchemy==1.4.54
terminado==0.12.1
testpath==0.6.0
tomli==1.2.3
tornado==6.1
traitlets==4.3.3
typing_extensions==4.1.1
urllib3==1.26.20
wcwidth==0.2.13
webencodings==0.5.1
websocket-client==1.3.1
widgetsnbextension==3.6.10
zipp==3.6.0

name: nbgrader
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - alembic==1.7.7
      - anyio==3.6.2
      - argon2-cffi==21.3.0
      - argon2-cffi-bindings==21.2.0
      - async-generator==1.10
      - attrs==22.2.0
      - babel==2.11.0
      - backcall==0.2.0
      - bleach==4.1.0
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - comm==0.1.4
      - contextvars==2.4
      - coverage==6.2
      - dataclasses==0.8
      - decorator==5.1.1
      - defusedxml==0.7.1
      - docutils==0.18.1
      - entrypoints==0.4
      - greenlet==2.0.2
      - idna==3.10
      - imagesize==1.4.1
      - immutables==0.19
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - ipykernel==5.5.6
      - ipython==7.16.3
      - ipython-genutils==0.2.0
      - ipywidgets==7.8.5
      - jedi==0.17.2
      - jinja2==3.0.3
      - json5==0.9.16
      - jsonschema==3.2.0
      - jupyter==1.1.1
      - jupyter-client==7.1.2
      - jupyter-console==6.4.3
      - jupyter-core==4.9.2
      - jupyter-server==1.13.1
      - jupyterlab==3.2.9
      - jupyterlab-pygments==0.1.2
      - jupyterlab-server==2.10.3
      - jupyterlab-widgets==1.1.11
      - mako==1.1.6
      - markupsafe==2.0.1
      - mistune==0.8.4
      - nbclassic==0.3.5
      - nbclient==0.5.9
      - nbconvert==6.0.7
      - nbformat==5.1.3
      - nbval==0.10.0
      - nest-asyncio==1.6.0
      - notebook==6.4.10
      - packaging==21.3
      - pandocfilters==1.5.1
      - parso==0.7.1
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pluggy==1.0.0
      - prometheus-client==0.17.1
      - prompt-toolkit==3.0.36
      - ptyprocess==0.7.0
      - py==1.11.0
      - pycparser==2.21
      - pyenchant==3.2.2
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pyrsistent==0.18.0
      - pytest==7.0.1
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pyzmq==25.1.2
      - requests==2.27.1
      - send2trash==1.8.3
      - six==1.17.0
      - sniffio==1.2.0
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinx-rtd-theme==2.0.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - sphinxcontrib-spelling==7.7.0
      - sqlalchemy==1.4.54
      - terminado==0.12.1
      - testpath==0.6.0
      - tomli==1.2.3
      - tornado==6.1
      - traitlets==4.3.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - wcwidth==0.2.13
      - webencodings==0.5.1
      - websocket-client==1.3.1
      - widgetsnbextension==3.6.10
      - zipp==3.6.0
prefix: /opt/conda/envs/nbgrader

nbgrader/tests/utils/test_utils.py::test_find_all_files
nbgrader/tests/utils/test_utils.py::test_is_grade nbgrader/tests/utils/test_utils.py::test_is_solution nbgrader/tests/utils/test_utils.py::test_is_locked nbgrader/tests/utils/test_utils.py::test_determine_grade_code_grade nbgrader/tests/utils/test_utils.py::test_determine_grade_markdown_grade nbgrader/tests/utils/test_utils.py::test_determine_grade_solution nbgrader/tests/utils/test_utils.py::test_determine_grade_code_grade_and_solution nbgrader/tests/utils/test_utils.py::test_determine_grade_markdown_grade_and_solution nbgrader/tests/utils/test_utils.py::test_compute_checksum_identical nbgrader/tests/utils/test_utils.py::test_compute_checksum_cell_type nbgrader/tests/utils/test_utils.py::test_compute_checksum_whitespace nbgrader/tests/utils/test_utils.py::test_compute_checksum_source nbgrader/tests/utils/test_utils.py::test_compute_checksum_points nbgrader/tests/utils/test_utils.py::test_compute_checksum_grade_id nbgrader/tests/utils/test_utils.py::test_compute_checksum_grade_cell nbgrader/tests/utils/test_utils.py::test_compute_checksum_solution_cell nbgrader/tests/utils/test_utils.py::test_compute_checksum_utf8 nbgrader/tests/utils/test_utils.py::test_is_ignored nbgrader/tests/utils/test_utils.py::test_unzip_invalid_ext nbgrader/tests/utils/test_utils.py::test_unzip_bad_zip nbgrader/tests/utils/test_utils.py::test_unzip_no_output_path nbgrader/tests/utils/test_utils.py::test_unzip_create_own_folder nbgrader/tests/utils/test_utils.py::test_unzip_tree
nbgrader/utils.py
nbgrader/utils.py