Skip to content

Instantly share code, notes, and snippets.

@mdamien
Created October 23, 2019 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdamien/7bf0cf69121fd38c91c0cb027f7aedf4 to your computer and use it in GitHub Desktop.
Save mdamien/7bf0cf69121fd38c91c0cb027f7aedf4 to your computer and use it in GitHub Desktop.
3-way merge with diff-match-patch
import os, glob
import diff_match_patch as dmp_module
dmp = dmp_module.diff_match_patch()
stashed = False
for file in glob.glob('textes_des_reglements/**/*.md'):
# (FR) commit à partir duquel les corrections ont été manuelles
# (EN) commit where started the manual corrections
os.system('git checkout c548aae')
with open(file) as f:
v0 = f.read()
# (FR) commit à partir duquel les correction manuelles auraient dut demarrer
# (EN) commit where the manual corrections should have started
os.system('git checkout correction-premier')
with open(file) as f:
v1 = f.read()
os.system('git checkout master')
with open(file) as f:
v2 = f.read()
patches = dmp.patch_make(v0, v2)
(v3, Result) = dmp.patch_apply(patches, v1)
# la version corrigée est gardée dans git stash le temps du script
if stashed:
os.system('git stash pop')
open(file, 'w').write(v3)
os.system('git stash')
stashed = True
os.system('git stash pop')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment