diff --git a/bin/extract_as_new_module.py b/bin/extract_as_new_module.py
index 550d587697dd36fe3617c382de96e8c9e82a47c4..29ac27729cf2d2cc6c2c00211787e3ccca4298a9 100755
--- a/bin/extract_as_new_module.py
+++ b/bin/extract_as_new_module.py
@@ -413,7 +413,7 @@ def dependenciesAndPatches(modulePath, skip=None):
         )
         deps = getDependencies(modulePath)
         deps = filterDependencies(deps, skip or [])
-        deps = addDependencyVersions(deps, ignoreUntracked=True)
+        deps = addDependencyVersions(deps)
         deps = addDependencyPatches(deps)
     except Exception as exc:
         raise Exception("Error getting the dependencies.") from exc
diff --git a/bin/make_installscript.py b/bin/make_installscript.py
index 0f71c24ae6bb7872dd953d9cff26cdde8ffe9f54..b89789abda795b365513845a7300197dc088fc29 100755
--- a/bin/make_installscript.py
+++ b/bin/make_installscript.py
@@ -15,6 +15,7 @@ import subprocess
 
 from util.moduleinfo import getDependencies, getModuleInfo
 from util.installscript import (
+    modulesWithUntrackedFiles,
     addDependencyPatches,
     addDependencyVersions,
     getDefaultScriptName,
@@ -104,8 +105,18 @@ def runMakeInstallScript():
     deps = addDependencyVersions(deps)
     printFoundVersionInfo(deps)
 
-    printProgressInfo(["Making patches for unpublished & uncommitted changes"])
-    deps = addDependencyPatches(deps, cmdArgs.get("allow_untracked", False))
+    untracked = modulesWithUntrackedFiles(deps)
+    if not cmdArgs.get("allow_untracked", False) and untracked:
+        untrackedPaths = "\n".join(f" - {dep['path']}" for dep in untracked)
+        raise Exception(
+            "Found untracked files in the following modules:\n"
+            f"{untrackedPaths}\n"
+            "Please commit, stash, or remove them. Alternatively, you can "
+            "use --allow-untracked to include them in the patches."
+        )
+
+    printProgressInfo(["Making patches for unpublished, uncommitted & untracked changes"])
+    deps = addDependencyPatches(deps)
 
     # actual script generation
     modPath = os.path.abspath(modPath)
diff --git a/bin/util/installscript.py b/bin/util/installscript.py
index c6e36f2d62d6e6f4eaddc4465a8721d25b1acc68..543929d32747eaafae665d1a31aaad109f0bdbe4 100644
--- a/bin/util/installscript.py
+++ b/bin/util/installscript.py
@@ -88,23 +88,17 @@ def addDependencyVersions(dependencies):
     return mergedResult
 
 
-def addDependencyPatches(dependenciesWithVersions, allowUntrackedFiles=False):
+def modulesWithUntrackedFiles(dependencies):
+    """Find modules with untracked files"""
+    return [dep for dep in dependencies if hasUntrackedFiles(dep["path"])]
+
+
+def addDependencyPatches(dependenciesWithVersions):
     """Add patch info to all dependencies"""
 
     def getKey(dependency):
         return dependency["path"]
 
-    if not allowUntrackedFiles and any(hasUntrackedFiles(getKey(p)) for p in dependenciesWithVersions):
-        untrackedPaths = "\n".join(
-            f" - {getKey(p)}" for p in filter(lambda p: hasUntrackedFiles(getKey(p)), dependenciesWithVersions)
-        )
-        raise Exception(
-            "Found untracked files in the following modules:\n"
-            f"{untrackedPaths}\n"
-            "Please commit, stash, or remove them. Alternatively, you can "
-            "set allowUntracked=True and include them to the patches."
-        )
-
     patches = getPatches({getKey(d): d for d in dependenciesWithVersions})
 
     mergedResult = []