MCPcopy
hub / github.com/Aider-AI/aider / git_cherry_pick_sr_onto_so

Function git_cherry_pick_sr_onto_so

aider/coders/search_replace.py:485–521  ·  view source on GitHub ↗
(texts)

Source from the content-addressed store, hash-verified

483
484
485def git_cherry_pick_sr_onto_so(texts):
486 search_text, replace_text, original_text = texts
487
488 with GitTemporaryDirectory() as dname:
489 repo = git.Repo(dname)
490
491 fname = Path(dname) / "file.txt"
492
493 fname.write_text(search_text)
494 repo.git.add(str(fname))
495 repo.git.commit("-m", "search")
496 search_hash = repo.head.commit.hexsha
497
498 # make search->replace
499 fname.write_text(replace_text)
500 repo.git.add(str(fname))
501 repo.git.commit("-m", "replace")
502 replace_hash = repo.head.commit.hexsha
503
504 # go back to search,
505 repo.git.checkout(search_hash)
506
507 # make search->original
508 fname.write_text(original_text)
509 repo.git.add(str(fname))
510 repo.git.commit("-m", "original")
511
512 # cherry pick replace onto original
513 try:
514 repo.git.cherry_pick(replace_hash, "--minimal")
515 except (git.exc.ODBError, git.exc.GitError):
516 # merge conflicts!
517 return
518
519 new_text = fname.read_text()
520
521 return new_text
522
523
524class SearchTextNotUnique(ValueError):

Callers

nothing calls this directly

Calls 4

write_textMethod · 0.80
commitMethod · 0.80
read_textMethod · 0.45

Tested by

no test coverage detected