mercredi 19 mars 2014

[Script]GIT Conflict Fixer topic




GIT CONFLICT FIXER

I made this little script called Git Conflict Fixer, the name says all I guess. The script does not have a brain that can solve REAL issues in the code, what it does is the following:

- Search in current dir for merge derps inside the files (usually happens after merging a branch or maybe just 1 commit)
- Edits the derped files by the standard procedure:


Quote:









<<<<<<< HEAD
OLDCONTENT GETS REMOVED
UNTIL THIS LINE

=======
NEW CONTENT WILL BE USED
UNTIL THIS LINE
>>>>>>>





- Commits if wanted

In 90% of the cases this easy way is the right way to fix it (luckily). so the 10% that's left is up to yourself to fix

This is not a wonder tool from outer space that will fix all your problems, but it will definitely help you when doing merges. So don't blame me if your code is not working ;)


Github Repository:
https://github.com/broodplank/GitConflictResolver



The main script


Code:


#!/bin/bash
#Auto fix git merge/cherry-pick conflicts in files
#Revision 1

#Startup check
if [[ -e /tmp/conflicts ]]; then
        rm -f /tmp/conflicts
fi;

#HEADER
echo "--- GIT Conflict Resolver v1.0"
echo "-- Created by broodplank"
echo "- broodplank.net"
echo
echo "-> Checking for .git folder"
echo -n "Result: "

#Check for .git folder for behavior
if [[ -d ${PWD}/.git ]]; then

    echo "found, using git diff"
    echo
    echo "-> Finding conflicts..."
    git diff --name-only --diff-filter=U > /tmp/conflicts

else

    echo "not found, using native tools"
    echo
    echo "-> Finding conflicts..."
    grep -l -H -r '<<<<<<< HEAD' ${PWD}/* | awk '!a[]++' > /tmp/conflicts

fi;


#Check if conflicts exist
if [[ `cat /tmp/conflicts` != "" ]]; then
    echo
    echo "-> Conflicts found in files:"
    while read F  ; do
            echo '- '$F
    done </tmp/conflicts
else
    echo "STOP, No conflicts found!"
    exit
fi;

#Start executing standard conflict resolve strategy
echo
echo "-> Fixing conflicts..."
echo
while read G  ; do
        echo "--> Working on file: $G"
        echo "Removing text between HEAD and middle"
        sed -i -s '/<<<<<<< HEAD/,/=======/d' $G
        echo "Removing conflict footer"
        sed -i -s '/>>>>>>>/d' $G
        echo
done </tmp/conflicts

#Assume conflicts are actually solved
echo "--> Conflicts have been automatically fixed!"
echo
echo "Please note:"
echo "Although most of the conflicts can be resolved this way, It does not count for all conflicts."
echo "If you experience errors on compiling please review the changes made"
echo

#Stage commit?
if [[ -d ${PWD}/.git ]]; then
    echo "Would you like to stage the commit? () [Y/n]"
    echo -n ": "
    read choice
    if [[ $choice != "n" ]]; then
        git add .
        git commit
    fi


fi;
echo
echo "All done!"


Example output:

Merging AOSP master in frameworks/av:

 






Quote:









broodplank@Bulldozer ~/repos/platform_frameworks_av $ fixmerge
--- GIT Conflict Resolver v1.0
-- Created by broodplank
- broodplank.net

-> Checking for .git folder
Result: found, using git diff

-> Finding conflicts...

-> Conflicts found in files:
- cmds/screenrecord/screenrecord.cpp
- media/libmedia/AudioTrack.cpp
- media/libmediaplayerservice/Android.mk
- media/libstagefright/AwesomePlayer.cpp
- media/libstagefright/MPEG4Extractor.cpp
- media/libstagefright/TimedEventQueue.cpp
- media/libstagefright/Utils.cpp
- media/libstagefright/httplive/LiveSession.cpp
- media/libstagefright/wifi-display/source/TSPacketizer.cpp
- services/audioflinger/Threads.cpp

-> Fixing conflicts...

--> Working on file: cmds/screenrecord/screenrecord.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: media/libmedia/AudioTrack.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: media/libmediaplayerservice/Android.mk
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: media/libstagefright/AwesomePlayer.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: media/libstagefright/MPEG4Extractor.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: media/libstagefright/TimedEventQueue.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: media/libstagefright/Utils.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: media/libstagefright/httplive/LiveSession.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: media/libstagefright/wifi-display/source/TSPacketizer.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Working on file: services/audioflinger/Threads.cpp
Removing text between HEAD and middle
Removing conflict footer

--> Conflicts have been automatically fixed!

Please note:
Although most of the conflicts can be resolved this way, It does not count for all conflicts.
If you experience errors on compiling please review the changes made

Would you like to stage the commit? () [Y/n]
:
[kk-4.4 6ffce17] Merge remote-tracking branch 'a/master' into kk-4.4

All done!












Aucun commentaire:

Enregistrer un commentaire