threads / discuss / 17404

How to install and use a custom merge driver

Subject: How to install and use a custom merge driver

## tl;dr

9 messages between Jan 28, 2009 and Jan 29, 2009.

replies: 8people: 3as markdown or json

Alec Clews· Jan 28, 2009, 03:10 UTC · lore
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
-- 
Alec Clews
Personal <alec.clews@gmail.com>			Melbourne, Australia.
Jabber:  alecclews@jabber.org.au		PGPKey ID: 0x9BBBFC7C
Blog  http://alecthegeek.wordpress.com/
Jeff King· Jan 28, 2009, 06:18 UTC · re: Alec Clews · lore

Re: How to install and use a custom merge driver

On Wed, Jan 28, 2009 at 02:10:18PM +1100, Alec Clews wrote:
Show 5 quoted lines
> 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
Alec Clews· Jan 28, 2009, 23:04 UTC · re: Jeff King · lore

Re: How to install and use a custom merge driver

Jeff King <peff <at> peff.net> writes:
Show 10 quoted lines
> On Wed, Jan 28, 2009 at 02:10:18PM +1100, Alec Clews wrote:
> 
> > 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
Alec Clews· Jan 28, 2009, 23:31 UTC · re: Alec Clews · lore

Re: How to install and use a custom merge driver

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
Jeff King· Jan 29, 2009, 03:25 UTC · re: Alec Clews · lore

Re: How to install and use a custom merge driver

On Wed, Jan 28, 2009 at 11:04:02PM +0000, Alec Clews wrote:
> 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).

> 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
Alec Clews· Jan 29, 2009, 04:47 UTC · re: Jeff King · lore

Re: How to install and use a custom merge driver

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
Jeff King· Jan 29, 2009, 05:03 UTC · re: Alec Clews · lore

Re: How to install and use a custom merge driver

On Thu, Jan 29, 2009 at 04:47:19AM +0000, Alec Clews wrote:
> 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
Alec Clews· Jan 29, 2009, 07:00 UTC · re: Jeff King · lore

Re: How to install and use a custom merge driver

Jeff King wrote:
Show 6 quoted lines
> 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<---------------------------------

-- 
Alec Clews
Personal <alec.clews@gmail.com>			Melbourne, Australia.
Jabber:  alecclews@jabber.org.au		PGPKey ID: 0x9BBBFC7C
Blog  http://alecthegeek.wordpress.com/
Jeff King· Jan 29, 2009, 07:11 UTC · re: Alec Clews · lore

Re: How to install and use a custom merge driver

On Thu, Jan 29, 2009 at 06:00:51PM +1100, Alec Clews wrote:
> 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

← back to recent threads