diff --git a/.gitattributes b/.gitattributes index a350e7b..8907189 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -*.mrg merge=my-custom-driver +README.md merge=driver_ours +*.mrg merge=driver_theirs diff --git a/.gitconfig b/.gitconfig index 72b2409..6017780 100644 --- a/.gitconfig +++ b/.gitconfig @@ -1,3 +1,6 @@ -[merge "my-custom-driver"] +[merge "driver_ours"] name = A custom merge driver used to resolve conflicts in certain files - driver = my-merge-tool.sh %O %A %B + driver = git_drivers/ours.sh %O %A %B +[merge "driver_theirs"] + name = A custom merge driver used to resolve conflicts in certain files + driver = git_drivers/theirs.sh %O %A %B diff --git a/example.sh b/example.sh index 34e2c30..5e69bf3 100755 --- a/example.sh +++ b/example.sh @@ -15,16 +15,22 @@ git branch -D demo-branch-2 # Create 'my-file.mrg' on branch 1 git checkout -b demo-branch-1 -echo "created on: demo-branch-1" > my-file.mrg -git add my-file.mrg -git commit -m"demo-branch-1: added my-file.mrg" +[[ -d lib ]] || mkdir lib +echo "Description 1 in README.md" > README.md +echo "created on: demo-branch-1" > lib/my-file.mrg +git add README.md +git add lib/my-file.mrg +git commit -m "demo-branch-1: added my-file.mrg" # Create 'my-file.mrg' on branch 2 git checkout master git checkout -b demo-branch-2 -echo "created on: demo-branch-2" > my-file.mrg -git add my-file.mrg -git commit -m"demo-branch-2: added my-file.mrg" +[[ -d lib ]] || mkdir lib +echo "Description 2 in README.md" > README.md +echo "created on: demo-branch-2" > lib/my-file.mrg +git add README.md +git add lib/my-file.mrg +git commit -m "demo-branch-2: added my-file.mrg" # Merge the two branches, causing a conflict -git merge -m"Merged in demo-branch-1" demo-branch-1 +git merge -m "Merged in demo-branch-1" demo-branch-1 diff --git a/git_drivers/ours.sh b/git_drivers/ours.sh new file mode 100755 index 0000000..746f034 --- /dev/null +++ b/git_drivers/ours.sh @@ -0,0 +1,12 @@ +printf "checking ...\n" +diff $2 $3 && exit 0 + +printf " +####################### +# Merge driver called # +#######################\n" +sleep 0.5 +cp -f $2 $3 +echo "Keep file from current branch!" + +exit 0 diff --git a/git_drivers/theirs.sh b/git_drivers/theirs.sh new file mode 100755 index 0000000..c93f6b3 --- /dev/null +++ b/git_drivers/theirs.sh @@ -0,0 +1,43 @@ +printf "checking ...\n" +diff $2 $3 && exit 0 + +printf " +####################### +# Merge driver called # +#######################\n" +sleep 0.5 +cp -f $3 $2 +echo "file was overwrited from another branch!" + +exit 0 + + + + +#printf "ancestor: $1 +#---------\n" +#cat $1 +#printf "\n" +# +#printf "current branch: $2 +#---------\n" +#cat $2 +#printf "\n" +# +#printf "another branch: $3 +#---------\n" +#cat $3 +#printf "\n" +# +#printf "Resolving conflict ...\n" +#sleep 0.5 +#cat $3 > $2 +##echo "This is the merge result" > $2 +#echo "Conflict resolved!" +# +#printf "resolved: $2\n +#---------\n" +#cat $2 +#printf "\n" +# +#exit 0