Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions git-grok
Original file line number Diff line number Diff line change
Expand Up @@ -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


#
Expand All @@ -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,
)

Expand Down Expand Up @@ -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)


#
Expand Down
5 changes: 3 additions & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down