Skip to contentSkip to conversation

How to install and use a custom merge driver

DISCUSSION Alec Clews 3 participants 9 messages Jun 15, 2016

lore
Share & tools
lore

Alec Clews

author
#0 lore raw

Background:

I want to use git to track the delivery of patch files into existing file trees. This means that new files will need to be copied over existing files (especially in the case of binary files or textual conflicts)

To this end I want to use a custom merge driver (actually the cp command)

Setup:

I have set up my ..git/info/gitattributes as follows

* merge=overwrite

I have defined in .git/config

[merge "overwrite"]
name = overwrite using cp
driver = cp %B %A

Problem:

However when I perform a git merge the default merge is being called. Is there something else needed to make git perform the copy operation?

Many thanks

Signature · 4 lines
Alec Clews
Personal <[email protected]>			Melbourne, Australia.
Jabber:  [email protected]		PGPKey ID: 0x9BBBFC7C
Blog  http://alecthegeek.wordpress.com/
#1 lore raw
Quoted 5 lines · Alec Clews

Setup:

I have set up my ..git/info/gitattributes as follows

* merge=overwrite

Your setup looks right, except that the correct file is ".git/info/attributes".

-Peff

#2 lore raw
Quoted 10 lines · Jeff King <peff <at> peff.net> writes:
Quoted 5 lines · Alec Clews

Setup:

I have set up my ..git/info/gitattributes as follows

* merge=overwrite

Your setup looks right, except that the correct file is ".git/info/attributes".

Thanks Jeff

I fixed that problem -- however it did not make any difference.

Is there someway to enable logging to see how git is making this choice?

- Alec

#3 lore raw
Quoted 1 line · Alec Clews

I fixed that problem -- however it did not make any difference.

Can you post an exact recipe for recreating the problem? It works just fine here, using:

-- >8 --
commit() {
echo $1 >file && git add file && git commit -m $1
}

mkdir repo && cd repo && git init
commit base
commit branch-master
git checkout -b other HEAD^
commit branch-other

echo '* merge=overwrite' >.git/info/attributes
cat >>.git/config <<'EOF'
[merge "overwrite"]
name = overwrite using cp
driver= cp %B %A
EOF

git merge master
-- 8< --

I get an automatic merge with the contents from "master" (and without the merge config, there is obviously a conflict).

Quoted 1 line

Is there someway to enable logging to see how git is making this choice?

You can try "git check-attr merge file" to be sure that it is picking up the attribute.

-Peff

#4 lore raw

Problem solved.

It appears that TAB is not supported as white space in either attributes or config files? I removed all the tabs and it works as described on the box

Many many thanks for the help Jeff

- Alec

#5 lore raw
Quoted 2 lines · Alec Clews

It appears that TAB is not supported as white space in either attributes or config files? I removed all the tabs and it works as described on the box

That's odd. It should be fine. And if I repeat the test I posted with:

printf '*\tmerge=overwrite\n' >.git/info/attributes (printf '[merge "overwrite"]\n'
printf '\tname = overwrite using cp\n' printf '\tdriver = cp %%B %%A\n'
) >>.git/config

it works as before.

What git version are you using? Can you post a shell snippet that breaks reliably?

-Peff

author
#6 lore raw
Quoted 6 lines · Jeff King

On Thu, Jan 29, 2009 at 04:47:19AM +0000, Alec Clews wrote:

What git version are you using? Can you post a shell snippet that breaks reliably?

I used 1.5.6.3 on Ubuntu and 1.6.1.1 on Cygwin.

The problem appears to be spaces around '=' in the attributes file. This fails for me

----------8<----------------------------------
commit() {
echo $1 >file && git add file && git commit -m $1
}

rm -rf repo

mkdir repo && cd repo && git init
commit base
commit branch-master
git checkout -b other HEAD^
commit branch-other

echo '* merge = overwrite' >.git/info/attributes
cat >>.git/config <<'EOF'
[merge "overwrite"]
name = overwrite using cp
driver= cp %B %A
EOF

git merge master
----------8<---------------------------------

Signature · 4 lines
Alec Clews
Personal <[email protected]>			Melbourne, Australia.
Jabber:  [email protected]		PGPKey ID: 0x9BBBFC7C
Blog  http://alecthegeek.wordpress.com/
#7 lore raw
Quoted 4 lines · Alec Clews

The problem appears to be spaces around '=' in the attributes file. This fails for me
[...]
echo '* merge = overwrite' >.git/info/attributes

Ah, OK. That isn't supposed to work. The attributes are whitespace separated, and some don't even have an equals at all (e.g., "merge", "-merge", and "merge=foo" are all valid). So that parses to "please use the ordinary text merge driver", and some attributes that nobody uses called "=" and "overwrite".

-Peff

#8 lore raw
In reply to Alec Clews
Quoted 1 line · Alec Clews <alecclews <at> gmail.com> writes:

Is there someway to enable logging to see how git is making this choice?

Found the answer to my question.

GIT_MERGE_VERBOSITY=5
GIT_TRACE=true

Which results in

+ git merge --stat del2
trace: built-in: git 'merge' '--stat' 'del2'
Merging:
38f3eb9 Accepting delivery del1
virtual del2
found 1 common ancestor(s):
af9dc93 Creating empty staging repo
Auto-merging src/main.c
CONFLICT (add/add): Merge conflict in src/main.c Automatic merge failed; fix conflicts and then commit the result.

So I'm none the wiser :-(. Any suggestions from wiser people than I?

Thanks

-Alec