Created
March 28, 2019 12:37
-
-
Save alexmorley/4943748f0bff557ca3fc4cd22da1b5e8 to your computer and use it in GitHub Desktop.
Adding commits to a repo from another with unrelated commit histories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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