From 3ac75840aebadfcadd8a987da77d5dcbeacf44c0 Mon Sep 17 00:00:00 2001 From: Alexei Kharchev Date: Sun, 4 Feb 2024 16:15:31 +0800 Subject: [PATCH 1/2] Added ours/theirs policies --- .gitattributes | 3 ++- .gitconfig | 7 +++++-- example.sh | 20 +++++++++++++------- git_drivers/ours.sh | 12 ++++++++++++ git_drivers/theirs.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 10 deletions(-) create mode 100755 git_drivers/ours.sh create mode 100755 git_drivers/theirs.sh 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..eedf588 --- /dev/null +++ b/git_drivers/ours.sh @@ -0,0 +1,12 @@ +printf "checking ...\n" +diff $2 $3 && exit 0 + +printf " +####################### +# Merge driver called # +#######################\n" + +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..767bff9 --- /dev/null +++ b/git_drivers/theirs.sh @@ -0,0 +1,43 @@ +printf "checking ...\n" +diff $2 $3 && exit 0 + +printf " +####################### +# Merge driver called # +#######################\n" + +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 From 12ef9f48fecf74059418fc99bde39c7c60ca7a5b Mon Sep 17 00:00:00 2001 From: Alexei Kharchev Date: Mon, 5 Feb 2024 23:50:50 +0800 Subject: [PATCH 2/2] Changed git_drivers/*.sh --- git_drivers/ours.sh | 2 +- git_drivers/theirs.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/git_drivers/ours.sh b/git_drivers/ours.sh index eedf588..746f034 100755 --- a/git_drivers/ours.sh +++ b/git_drivers/ours.sh @@ -5,7 +5,7 @@ printf " ####################### # Merge driver called # #######################\n" - +sleep 0.5 cp -f $2 $3 echo "Keep file from current branch!" diff --git a/git_drivers/theirs.sh b/git_drivers/theirs.sh index 767bff9..c93f6b3 100755 --- a/git_drivers/theirs.sh +++ b/git_drivers/theirs.sh @@ -5,7 +5,7 @@ printf " ####################### # Merge driver called # #######################\n" - +sleep 0.5 cp -f $3 $2 echo "file was overwrited from another branch!"