From 4288dc9a55a85836449ae2119ae2c6281c511798 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dennis=20Gl=C3=A4ser?= <dennis.glaeser@iws.uni-stuttgart.de>
Date: Fri, 28 Apr 2023 18:16:40 +0200
Subject: [PATCH] [bin][makeinstall] put untracked check in main script

---
 bin/extract_as_new_module.py |  2 +-
 bin/make_installscript.py    | 15 +++++++++++++--
 bin/util/installscript.py    | 18 ++++++------------
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/bin/extract_as_new_module.py b/bin/extract_as_new_module.py
index 550d587697..29ac27729c 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 0f71c24ae6..b89789abda 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 c6e36f2d62..543929d327 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 = []
-- 
GitLab