How to install and use a custom merge driver

9 messages, 3 authors, 2016-06-15 · open the first message on its own page

How to install and use a custom merge driver

From: Alec Clews <hidden>
Date: 2016-06-15 22:46:02

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 [off-list ref]			Melbourne, Australia.
Jabber:  alecclews@jabber.org.au		PGPKey ID: 0x9BBBFC7C
Blog  http://alecthegeek.wordpress.com/

Re: How to install and use a custom merge driver

From: Jeff King <hidden>
Date: 2016-06-15 22:46:03

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".

-Peff

Re: How to install and use a custom merge driver

From: Alec Clews <hidden>
Date: 2016-06-15 22:46:03

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

Re: How to install and use a custom merge driver

From: Alec Clews <hidden>
Date: 2016-06-15 22:46:03

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

Re: How to install and use a custom merge driver

From: Jeff King <hidden>
Date: 2016-06-15 22:46:03

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

Re: How to install and use a custom merge driver

From: Alec Clews <hidden>
Date: 2016-06-15 22:46:03

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

Re: How to install and use a custom merge driver

From: Jeff King <hidden>
Date: 2016-06-15 22:46:03

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

Re: How to install and use a custom merge driver

From: Alec Clews <hidden>
Date: 2016-06-15 22:46:03

Jeff King wrote:
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 [off-list ref]			Melbourne, Australia.
Jabber:  alecclews@jabber.org.au		PGPKey ID: 0x9BBBFC7C
Blog  http://alecthegeek.wordpress.com/

Re: How to install and use a custom merge driver

From: Jeff King <hidden>
Date: 2016-06-15 22:46:03

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help