Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to this example added ours/theirs policies and moved my-file.mrg to /lib direcory #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.mrg merge=my-custom-driver
README.md merge=driver_ours
*.mrg merge=driver_theirs
7 changes: 5 additions & 2 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -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
20 changes: 13 additions & 7 deletions example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions git_drivers/ours.sh
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions git_drivers/theirs.sh
Original file line number Diff line number Diff line change
@@ -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