Op 8-4-2012 17:01, Richard Heck schreef:
One of the nice things about git is its expandability, through aliases and scripts. To some extent, using these can hide the complexities of git and make it work more like svn. So I'm attaching a few of the ones I've developed so far. They're written in bash and so should work on any *nix.
These probably also work on windows when using "Git bash", which is the default and best way of using Git on windows.
I've written a script (inspired by git's own) to merge all feature branches (based on trunk-stable) into trunk-devel.
Also I've written a merge driver in Python for lyx_2_1.py. This because introducing a new file format is the most likely cause of merge conflicts, while these conflicts are easily solvable. Scripts for version.h and FORMAT are the next in the pipeline.
Vincent
#! /usr/bin/env python import sys import re import difflib ancestor = open(sys.argv[1], "r").readlines() current = open(sys.argv[2], "r").readlines() other = open(sys.argv[3], "r").readlines() d = difflib.Differ() diff_other = list(d.compare(ancestor, other)) diff_current = list(d.compare(ancestor, current)) result = [] success = 1 def_current = 0 def_other = 0 i_o = 0 i_c = 0 while i_c < len(diff_current) or i_o < len(diff_other): if i_c < len(diff_current): line_current = diff_current[i_c] else: line_current = ' ' if line_current.startswith('? '): i_c = i_c + 1 continue if i_o < len(diff_other): line_other = diff_other[i_o] else: line_other = ' ' if line_other.startswith('? '): i_o = i_o + 1 continue if line_current == line_other and line_current.startswith(' '): result.append(line_current[2:]) i_o = i_o + 1 i_c = i_c + 1 def_current = 0 elif line_current.startswith('+ ') and (def_current == 1 or line_current[2:].startswith('def ') or (len(line_current) > 13 and line_current[13] == '[')): def_current = 1 result.append(line_current[2:]) i_c = i_c + 1 elif line_current.startswith('+ ') and line_other.startswith(' '): result.append(line_current[2:]) i_c = i_c + 1 elif line_other.startswith('+ ') and line_current.startswith(' '): result.append(line_other[2:]) i_o = i_o + 1 def_current = 0 elif line_current.startswith('- ') and line_other.startswith(' '): i_c = i_c + 1 i_o = i_o + 1 def_current = 0 elif line_current.startswith(' ') and line_other.startswith('- '): i_c = i_c + 1 i_o = i_o + 1 def_current = 0 elif line_current.startswith('- ') and line_other.startswith('- '): i_c = i_c + 1 i_o = i_o + 1 def_current = 0 elif line_current.startswith('+ ') and line_other.startswith('+ '): result.append('<<<<<<< HEAD\n') result.append(line_current[2:]) result.append('=======\n') result.append(line_other[2:]) result.append('>>>>>>> other\n') success = 0 i_c = i_c + 1 i_o = i_o + 1 def_current = 0 else: sys.exit(1) f = open(sys.argv[2],'w') f.writelines(result) f.close() print 'Merging went cleanly' # Exit with zero if the merge went cleanly, non-zero otherwise. if success: sys.exit(0) else: sys.exit(1)
#!/bin/bash export PATH=$PATH:/c/Development/Python27:~/Documents/LyX/source/scripts cd ../gitlyx git update-index --refresh || (echo "Work tree not clean!" && exit 1) git checkout trunk-devel git reset --hard trunk-stable HH=`git show-ref --heads | sed -e 's/^\.\///' \ -e '/^[a-f0-9]* refs\/heads\/trunk-devel$/d' \ -e '/^[a-f0-9]* refs\/heads\/2.0.x$/d' \ -e '/^[a-f0-9]* refs\/heads\/trunk-stable$/d' \ -e '/^[a-f0-9]* refs\/heads\/mytrunkstable$/d' \ -e '/^[a-f0-9]* refs\/heads\/gitorious-master$/d' \ -e '/^[a-f0-9]* refs\/heads\/master$/d' \ -e '/^[a-f0-9]* refs\/heads\/attic[a-z\/-]*$/d' \ -e '/^[a-f0-9]* refs\/heads\/local[a-z\/0-9-]*$/d' \ -e '/^[a-f0-9]* refs\/heads\/other[a-z\/0-9-]*$/d'` for H in $HH do PP=`git rev-parse $H` case "$PP" in "$H") continue;; *) ;; esac H=${H:11} echo -e "\033[1m " $H "\033[0m " git merge --no-ff -qq $H || if git diff | grep -e "^.+" -e "^+." | grep -e "^..<<<<<<<" -e "^..=======" -e "^..>>>>>>>" >/dev/null then exit 1 else GIT_EDITOR=true git commit -a --no-verify echo "rerere: Accepted previous resolution" fi done cd ../scripts