MCPcopy Index your code
hub / github.com/langroid/langroid / git_diff_file

Function git_diff_file

langroid/utils/git_utils.py:228–252  ·  view source on GitHub ↗

Show diffs of file between the latest commit and the previous one if any. Args: repo (git.Repo): The Git repository object filepath (str): Path to the file to be diffed Returns: str: The diff output as a string

(repo: git.Repo, filepath: str)

Source from the content-addressed store, hash-verified

226
227
228def git_diff_file(repo: git.Repo, filepath: str) -> str:
229 """
230 Show diffs of file between the latest commit and the previous one if any.
231
232 Args:
233 repo (git.Repo): The Git repository object
234 filepath (str): Path to the file to be diffed
235
236 Returns:
237 str: The diff output as a string
238 """
239 try:
240 # Get the two most recent commits
241 commits = list(repo.iter_commits(paths=filepath, max_count=2))
242
243 if len(commits) < 2:
244 return "No previous commit found for comparison."
245
246 # Get the diff between the two commits for the specific file
247 diff = repo.git.diff(commits[1].hexsha, commits[0].hexsha, filepath)
248
249 return str(diff)
250 except git.GitCommandError as e:
251 logger.error(f"An error occurred while getting diff: {e}")
252 return f"Error: {str(e)}"

Callers 1

test_git_diff_fileFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_git_diff_fileFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…