MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / get_session_diff

Function get_session_diff

src/utils/git.py:167–215  ·  view source on GitHub ↗
(
    cwd: str | None = None,
    *,
    staged: bool = False,
    paths: list[str] | None = None,
)

Source from the content-addressed store, hash-verified

165
166
167def get_session_diff(
168 cwd: str | None = None,
169 *,
170 staged: bool = False,
171 paths: list[str] | None = None,
172) -> DiffResult:
173 args = ["diff"]
174 if staged:
175 args.append("--cached")
176 args.append("--stat")
177 if paths:
178 args.append("--")
179 args.extend(paths)
180
181 stat_output = _run_git_ok(args, cwd)
182
183 diff_args = ["diff"]
184 if staged:
185 diff_args.append("--cached")
186 if paths:
187 diff_args.append("--")
188 diff_args.extend(paths)
189
190 diff_output = _run_git_ok(diff_args, cwd)
191
192 files_changed = 0
193 insertions = 0
194 deletions = 0
195 if stat_output:
196 lines = stat_output.strip().splitlines()
197 if lines:
198 summary = lines[-1]
199 import re
200 files_match = re.search(r"(\d+)\s+file", summary)
201 ins_match = re.search(r"(\d+)\s+insertion", summary)
202 del_match = re.search(r"(\d+)\s+deletion", summary)
203 if files_match:
204 files_changed = int(files_match.group(1))
205 if ins_match:
206 insertions = int(ins_match.group(1))
207 if del_match:
208 deletions = int(del_match.group(1))
209
210 return DiffResult(
211 diff_text=diff_output,
212 files_changed=files_changed,
213 insertions=insertions,
214 deletions=deletions,
215 )
216
217
218def get_diff_against_branch(

Callers 4

runMethod · 0.90
test_no_changesMethod · 0.90
test_with_changesMethod · 0.90
get_session_diff_asyncFunction · 0.85

Calls 4

_run_git_okFunction · 0.85
DiffResultClass · 0.85
searchMethod · 0.80
appendMethod · 0.45

Tested by 2

test_no_changesMethod · 0.72
test_with_changesMethod · 0.72