diff --git a/lib/tools/common/patching_utils.py b/lib/tools/common/patching_utils.py index d2c4b79944..301724e051 100755 --- a/lib/tools/common/patching_utils.py +++ b/lib/tools/common/patching_utils.py @@ -512,6 +512,10 @@ class PatchInPatchFile: final_files_to_add = [f for f in all_files_to_add if f not in do_not_commit_files] final_files_to_add = [f for f in final_files_to_add if not any(re.match(r, f) for r in do_not_commit_regexes)] log.debug(f"Adding (post-config) {len(final_files_to_add)} files to git: {' '.join(final_files_to_add)}") + if len(final_files_to_add) == 0: + log.warning(f"There are 0 files to commit post-config. The whole patch should be removed.") + self.problems.append("no_files_to_commit_after_config") + return None repo.git.add("-f", final_files_to_add) if self.failed_to_parse or self.parent.patch_dir.is_autogen_dir or add_all_changes_in_git: diff --git a/lib/tools/patching.py b/lib/tools/patching.py index f29be61b3c..7b69e38241 100755 --- a/lib/tools/patching.py +++ b/lib/tools/patching.py @@ -320,7 +320,7 @@ if apply_patches: if one_patch.applied_ok and apply_patches_to_git: committed = one_patch.commit_changes_to_git(git_repo, (not rewrite_patches_in_place), split_patches, pconfig) - if not split_patches: + if not split_patches and (committed is not None): commit_hash = committed['commit_hash'] one_patch.git_commit_hash = commit_hash @@ -354,6 +354,10 @@ if apply_patches: log.warning(f"Skipping patch {one_patch} from rewrite because it was not applied successfully.") continue + if one_patch.rewritten_patch is None: + log.warning(f"Skipping patch {one_patch} from rewrite because it was not rewritten.") + continue + if one_patch.parent not in patch_files_by_parent: patch_files_by_parent[one_patch.parent] = [] patch_files_by_parent[one_patch.parent].append(one_patch) @@ -361,7 +365,7 @@ if apply_patches: for parent in patch_files_by_parent: patches = patch_files_by_parent[parent] parent.rewrite_patch_file(patches) - UNAPPLIED_PATCHES = [one_patch for one_patch in VALID_PATCHES if not one_patch.applied_ok] + UNAPPLIED_PATCHES = [one_patch for one_patch in VALID_PATCHES if (not one_patch.applied_ok) or (one_patch.rewritten_patch is None)] for failed_patch in UNAPPLIED_PATCHES: log.info( f"Consider removing {failed_patch.parent.full_file_path()}(:{failed_patch.counter}); "