MCPcopy Create free account
hub / github.com/BillHuang2001/evogit / update_file_in_worktree

Function update_file_in_worktree

python-impl/evogit/utils/git.py:335–360  ·  view source on GitHub ↗

Update the content of the file in the specified worktree, then commit the updated file.

(
    config: EvoGitConfig,
    worktree: str,
    new_content: Union[str, bytes],
    filename: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

333
334
335def update_file_in_worktree(
336 config: EvoGitConfig,
337 worktree: str,
338 new_content: Union[str, bytes],
339 filename: Optional[str] = None,
340) -> None:
341 """Update the content of the file in the specified worktree, then commit the updated file."""
342 filename = filename if filename is not None else config.filename
343 if isinstance(new_content, str):
344 mode = "r+"
345 elif isinstance(new_content, bytes):
346 mode = "rb+"
347 else:
348 raise ValueError("new_content must be either a string or bytes.")
349
350 with open(os.path.join(worktree, filename), mode) as f:
351 current_content = f.read()
352 # if the content is the same, do nothing
353 if current_content == new_content:
354 return
355
356 f.seek(0)
357 f.write(new_content)
358 f.truncate()
359
360 subprocess.run(["git", "add", filename], cwd=worktree, check=True)
361
362
363def add_file_in_worktree(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected