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 07fd3d9f519ed266a614d24634a910139cc01e86..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, @@ -45,11 +46,11 @@ def runMakeInstallScript(): help="File in which to write the install script", ) parser.add_argument( - "-i", - "--ignoreuntracked", + "-a", + "--allow-untracked", required=False, action="store_true", - help="Use this to ignore untracked files present", + help="Use this to include untracked files into patches", ) parser.add_argument( "-t", @@ -101,10 +102,20 @@ def runMakeInstallScript(): sys.exit("No dependencies found. Exiting.") printProgressInfo(["Determining the module versions"]) - deps = addDependencyVersions(deps, cmdArgs.get("ignoreuntracked", False)) + deps = addDependencyVersions(deps) printFoundVersionInfo(deps) - printProgressInfo(["Making patches for unpublished & uncommitted changes"]) + 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 diff --git a/bin/util/common.py b/bin/util/common.py index a383104a4abb1f2898f6ed3ad92c2fb811a125ce..e2dd997f0d8566a96104ac8e4811d58a556754aa 100644 --- a/bin/util/common.py +++ b/bin/util/common.py @@ -306,7 +306,7 @@ def mostRecentCommonCommitWithRemote(modFolderPath, branchFilter=isPersistentBra # function to extract persistent, remotely available git versions for all -def getPersistentVersions(modFolderPaths, ignoreUntracked=False): +def getPersistentVersions(modFolderPaths): """Get versions of last commit on a persistent branch""" result = {} for modFolderPath in modFolderPaths: @@ -314,13 +314,6 @@ def getPersistentVersions(modFolderPaths, ignoreUntracked=False): if not isGitRepository(modFolderPath): raise Exception("Folder is not a git repository") - if hasUntrackedFiles(modFolderPath) and not ignoreUntracked: - raise Exception( - f"Found untracked files in '{modFolderPath}'. " - "Please commit, stash, or remove them. Alternatively, if you " - "are sure they are not needed set ignoreUntracked=True" - ) - result[modFolderPath] = {} result[modFolderPath]["remote"] = getRemote(modFolderPath) diff --git a/bin/util/installscript.py b/bin/util/installscript.py index 2e6516ff47329e9e50ff14685f21467c7566148b..543929d32747eaafae665d1a31aaad109f0bdbe4 100644 --- a/bin/util/installscript.py +++ b/bin/util/installscript.py @@ -10,7 +10,7 @@ import os import sys import textwrap -from util.common import getPersistentVersions, versionTable, getPatches +from util.common import getPersistentVersions, hasUntrackedFiles, versionTable, getPatches from util.moduleinfo import getModuleInfo from util.installscript_writer import InstallScriptWriterBash from util.installscript_writer import InstallScriptWriterPython @@ -71,13 +71,13 @@ def filterDependencies(dependencies, skipFolders=None): return [dep for dep in dependencies if not skipFolder(dep["folder"])] -def addDependencyVersions(dependencies, ignoreUntracked=False): +def addDependencyVersions(dependencies): """Add version info to all dependencies""" def getKey(dependency): return dependency["path"] - versions = getPersistentVersions([getKey(d) for d in dependencies], ignoreUntracked) + versions = getPersistentVersions([getKey(d) for d in dependencies]) if len(versions) != len(dependencies): raise Exception("Not all versions of all modules could be found.") @@ -88,6 +88,11 @@ def addDependencyVersions(dependencies, ignoreUntracked=False): return mergedResult +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"""