diff --git a/git-grok b/git-grok index 7aa8e53..e089cf3 100755 --- a/git-grok +++ b/git-grok @@ -2052,8 +2052,9 @@ def body_suffix_upsert( BODY_SUFFIX_TITLE + "\n" + "\n".join(items) + "\n\n" + BODY_SUFFIX_FOOTER + "\n" ) if re.search(BODY_SUFFIX_RE, body, flags=re.M | re.I | re.X): - return re.sub(BODY_SUFFIX_RE, suffix, body, flags=re.M | re.I | re.X) - return body.rstrip() + "\n\n" + suffix + return re.sub(BODY_SUFFIX_RE, lambda _: suffix, body, flags=re.M | re.I | re.X) + else: + return body.rstrip() + "\n\n" + suffix # @@ -2065,7 +2066,7 @@ def body_build_from_injected_text( ) -> str: return re.sub( r"\s*" + re.escape(AI_PLACEHOLDER) + r"\s*", - f"\n\n{injected_text.text}\n\n", + lambda _: f"\n\n{injected_text.text}\n\n", injected_text.template_with_placeholder, ) @@ -2095,7 +2096,7 @@ def body_convert_to_injected_text( # Returns an AI hash comment. # def ai_hash_build(hash: str) -> str: - return re.sub(r"(?=-->)", ":" + hash, AI_PLACEHOLDER) + return re.sub(r"(?=-->)", lambda _: f":{hash}", AI_PLACEHOLDER) # diff --git a/tests/helpers.py b/tests/helpers.py index 36041e2..d615074 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -197,8 +197,9 @@ def git_init_and_cd_to_test_dir( # branch has already been deleted by a parallel test run or so). -def git_touch(file: str): - check_output_x("touch", file) +def git_touch(file: str, content: str | None = None): + with open(file, "w") as f: + f.write(content or "") def git_add_commit(msg: str): diff --git a/tests/test_ai.py b/tests/test_ai.py index 5b7f48f..8fb4928 100644 --- a/tests/test_ai.py +++ b/tests/test_ai.py @@ -11,7 +11,7 @@ class Test(TestCaseWithEmptyTestRepo): def test_ai(self): self.git_init_and_cd_to_test_dir(method="push.default") - git_touch("commit01") + git_touch("commit01", r"some \s text") git_add_commit("commit01") run_git_grok()