Skip to content

Instantly share code, notes, and snippets.

@markstory
Created January 27, 2010 14:21
Show Gist options
  • Save markstory/287861 to your computer and use it in GitHub Desktop.
Save markstory/287861 to your computer and use it in GitHub Desktop.
Used to fix annoying and widespread conflicts
#! /usr/bin/env python
import os, re
def main():
"""Fix the stupid merge conflicts.."""
for root, dirs, files in os.walk('.'):
if '.git' in dirs:
dirs.remove('.git') # don't visit .git directories
if 'conflict_fix.py' in files:
files.remove('conflict_fix.py')
for f in files[:]:
try:
fullpath = os.path.join(root, f)
print 'fixing :', fullpath
fix_header(fullpath)
fix_copyright(fullpath)
except ValueError:
print 'Error in ', f
def fix_header(filename):
""" fixes the header conflicts"""
find = """<<<<<<< HEAD\n\
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)\n\
=======\n\
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)\n\
>>>>>>> 1.2\n"""
replace = " * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)\n"
fix_file(filename, find, replace)
def fix_copyright(filename):
""" fix copyright issues."""
find = "<<<<<<< HEAD\n\
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)\n\
=======\n\
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)\n\
>>>>>>> 1.2\n"
replace = " * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)\n"
fix_file(filename, find, replace)
def fix_file(filename, find, replace):
""" run a fix """
fixer = open(filename, 'r')
contents = fixer.read()
contents = re.sub(r"""<<<<<<< HEAD(\:.+)?""", '<<<<<<< HEAD', contents)
contents = re.sub(r""">>>>>>> 1\.2(\:.+)?""", '>>>>>>> 1.2', contents)
contents = contents.replace(find, replace)
target = open(filename, 'w')
target.write(contents)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment