Skip to content

Instantly share code, notes, and snippets.

@alexmorley
Created March 28, 2019 12:37
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 alexmorley/4943748f0bff557ca3fc4cd22da1b5e8 to your computer and use it in GitHub Desktop.
Save alexmorley/4943748f0bff557ca3fc4cd22da1b5e8 to your computer and use it in GitHub Desktop.
Adding commits to a repo from another with unrelated commit histories
# First do:
# git format-patch $commit_id..HEAD
# edit this script to only include commits that change watchfile*
# *note that commits that include this file AND alter other files will also be included
# then run this script
# then run ./process_patches.py | xargs git am
import os
import sys
watchfile = 'chapters/testing.md'
patchdir = '/home/amorley/git_repos/archiv/becky/the-turing-way-testing'
patchfiles = os.listdir(patchdir)
patchfiles = list(filter(lambda x: x[-5:] == 'patch', patchfiles))
patchestoapply = []
for file in patchfiles:
with open(patchdir+'/'+file, 'r', encoding='utf8') as f:
try:
commit = f.readline().split(' ')[1]
except:
continue
author_info = f.readline()
author_name = str.join(' ',author_info.split(' ')[1:3])
author_email = author_info[author_info.index('<')+1:author_info.index('>')]
date = f.readline()
subject = f.readline()
for i,line in enumerate(f):
if '+++ b/{}'.format(watchfile) in line:
patchestoapply.append(patchdir+'/'+file)
patchestoapply = sorted(patchestoapply)
for p in patchestoapply:
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment