Add git-mergetool to run an appropriate merge conflict resolution program
Subsystems (2)
PATCH 1/1 Add git-mergetool to run an appropriate merge conflict resolution program
The git-mergetool program can be used to automatically run an appropriate merge resolution program to resolve merge conflicts. It will automatically run one of kdiff3, tkdiff, meld, xxdiff, or emacs emerge programs.
--- .gitignore | 1 + Documentation/config.txt | 5 + Documentation/git-mergetool.txt | 46 +++++++++ Makefile | 2 +- git-mergetool.sh | 208 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 261 insertions(+), 1 deletions(-) create mode 100644 Documentation/git-mergetool.txt create mode 100755 git-mergetool.sh
.gitignore +1 -0
@@ -75,6 +75,7 @@ git-merge-ours git-merge-recursive git-merge-resolve git-merge-stupid +git-mergetool git-mktag git-mktree git-name-rev
Documentation/config.txt +5 -0
@@ -453,6 +453,11 @@ merge.summary:: Whether to include summaries of merged commits in newly created merge commit messages. False by default. +merge.tool:: + Controls which merge resolution program is used by + gitlink:git-mergetool[l]. Valid values are: "kdiff3", "tkdiff", + "meld", "xxdiff", "emerge" + merge.verbosity:: Controls the amount of output shown by the recursive merge strategy. Level 0 outputs nothing except a final error
Documentation/git-mergetool.txt new file +46 -0
46 lines not on this page · raw message
Makefile +1 -1
@@ -177,7 +177,7 @@ SCRIPT_SH = \ git-clean.sh git-clone.sh git-commit.sh \ git-fetch.sh git-gc.sh \ git-ls-remote.sh \ - git-merge-one-file.sh git-parse-remote.sh \ + git-merge-one-file.sh git-mergetool.sh git-parse-remote.sh \ git-pull.sh git-rebase.sh \ git-repack.sh git-request-pull.sh git-reset.sh \ git-revert.sh git-sh-setup.sh \
git-mergetool.sh new file +208 -0
208 lines not on this page · raw message
Signature · 1 line
1.5.0.2.312.g5ced-dirty
Documentation/git-mergetool.txt line 7
Quoted 7 lines · Theodore Ts'o
Documentation/git-mergetool.txt new file +7
-0+git-mergetool(1) +================ + +NAME +---- +git-mergetool - Forward-port local commits to the updated upstream head +
Hmph. We already have a tool to achieve such a goal, and that is called git-rebase. Why would we want your program? ;-)
Quoted 6 lines
git-mergetool.sh new file +0
-0
git-mergetool.sh line 8
Quoted 8 lines
git-mergetool.sh new file +8
-0@@ -0,0 +1,208 @@ +#!/bin/sh +# +# This program resolves merge conflicts in git +# +# Copyright (c) 2006 Theodore Y. Ts'o +# +# This file is licensed under the GPL v2, or a later version +# at the discretion of Linus Torvalds.
Heh ;-).
git-mergetool.sh line 14
Quoted 6 lines
git-mergetool.sh new file +6
-0+# + +usage () { + echo "Usage: git mergetool [--tool=tool] [file to merge] ..." + exit 1 +}
Do we want to do this by hand ourselves, or dot-source sh-setup like others? You would also get die() for free.
git-mergetool.sh line 28
Quoted 13 lines
git-mergetool.sh new file +12
-0+merge_file () { + + if test ! -f "$path" ; then + echo "$path: file not found" + exit 1 + fi + + f=`git-ls-files -u "$path"` + if test -z "$f" ; then + echo "$path: file does not need merging" + exit 1 + fi
You should be able to set IFS to exclude SP and then you only have to say you do not support LF and HT, both of which are much less likely than SP to be in the pathname.
git-mergetool.sh line 36
Quoted 2 lines
git-mergetool.sh new file +2
-0+ mv "$path" "$BACKUP" + cp "$BACKUP" "$path"
What if $path is a symlink blob? ;-)
git-mergetool.sh line 78
Quoted 13 lines
git-mergetool.sh new file +8
-0+ git cat-file blob ":1:$path" > "$BASE" + git cat-file blob ":2:$path" > "$LOCAL" + git cat-file blob ":3:$path" > "$REMOTE" + case "$merge_tool" in + kdiff3) + tkdiff) + meld) + xxdiff)
It is depressing to see that the differences between the command lines of these have to be much larger than just the command name and order of three (or four if we count the result) paths parameters. I was hoping that we could do something like:
mergetool -t='newmerge $BASE $LOCAL $REMOTE'
git-mergetool.sh line 83
Quoted 4 lines
git-mergetool.sh new file +4
-0+ xxdiff -X --show-merged-pane \ + -R 'Accel.SaveAsMerged: "Ctrl-S"' \ + -R 'Accel.Search: "Ctrl+F"' \ + -R 'Accel.SearchForward: "Ctrl-G"' \
Do these configuration belong to individual scripts like this?
git-mergetool.sh line 167
Quoted 13 lines
git-mergetool.sh new file +13
-0+if test -z "$merge_tool" ; then + if type kdiff3 >/dev/null 2>&1 && test -n "$DISPLAY"; then + merge_tool="kdiff3"; + elif type tkdiff >/dev/null 2>&1 && test -n "$DISPLAY"; then + merge_tool=tkdiff + elif type xxdiff >/dev/null 2>&1 && test -n "$DISPLAY"; then + merge_tool=xxdiff + elif type meld >/dev/null 2>&1 && test -n "$DISPLAY"; then + merge_tool=meld + elif type emacs >/dev/null 2>&1; then + merge_tool=emerge + else + echo "No available merge tools available."
Curious choice of words...
git-mergetool.sh line 192
Quoted 2 lines
git-mergetool.sh new file +2
-0+if test $# -eq 0 ; then + files=`git ls-files -u --abbrev=8 | colrm 1 24 | sort -u`
Careful. I think --abbrev=8 just means use at least 8 but more
as needed to make them unique. sed -e 's/^[^ ]* //'
(whitespace are HTs) would be safer and simpler, as you are not dealing with a pathname that has LF in it anyway.
Quoted 12 lines · Junio C Hamano
Documentation/git-mergetool.txt line 7
Quoted 7 lines · Theodore Ts'o
Documentation/git-mergetool.txt new file +7
-0+git-mergetool(1) +================ + +NAME +---- +git-mergetool - Forward-port local commits to the updated upstream head +Hmph. We already have a tool to achieve such a goal, and that is called git-rebase. Why would we want your program? ;-)
Oops, sorry, I thought I had fixed that. Guess you figured out which program I used as a man page template, huh? :-)
Quoted 4 lines
git-mergetool.sh line 8
Quoted 2 lines
git-mergetool.sh new file +2
-0+# This file is licensed under the GPL v2, or a later version +# at the discretion of Linus Torvalds.Heh ;-).
Hey, that's what the COPYING file requested, and it was late when I started doing the git package integration, hence the stupid think-o with the man page. :-)
I assume you would prefer that it read Junio instead? Should we change the COPYING while we're at it, perhaps after consulting with Linus since he still owns so a fair amount of the copyright on git? It seems that if we're going to pre-collect permissions to move to GPLv3, it ought to be either you or him....
Quoted 2 lines
Do we want to do this by hand ourselves, or dot-source sh-setup like others? You would also get
die()for free.
Good point, I'll use git-sh-setup.
Quoted 3 lines
You should be able to set IFS to exclude SP and then you only have to say you do not support LF and HT, both of which are much less likely than SP to be in the pathname.
Do we have any coding guidelines about what characters we have to support in filenames? I had assumed that we should support at least SP and HT, but life does get easier if we don't need to worry about HT.
Quoted 4 lines
git-mergetool.sh line 36
Quoted 2 lines
git-mergetool.sh new file +2
-0+ mv "$path" "$BACKUP" + cp "$BACKUP" "$path"What if $path is a symlink blob? ;-)
Yeah, I need to add special case code for symlinks.
Quoted 6 lines
Quoted 6 lines
git-mergetool.sh new file +4
-0+ case "$merge_tool" in + kdiff3) + tkdiff) + meld)
Quoted 8 lines
git-mergetool.sh line 78
Quoted 3 lines
...
git-mergetool.sh new file +1
-0+ xxdiff)It is depressing to see that the differences between the command lines of these have to be much larger than just the command name and order of three (or four if we count the result) paths parameters.
Yep, it is depressing. There is no standard calling convention, and there is no standard exit status convention, either. Hence the requirement for meld and xxdiff to check to see if the file has changed. Grump....
Quoted 6 lines
git-mergetool.sh line 83
Quoted 4 lines
git-mergetool.sh new file +4
-0+ xxdiff -X --show-merged-pane \ + -R 'Accel.SaveAsMerged: "Ctrl-S"' \ + -R 'Accel.Search: "Ctrl+F"' \ + -R 'Accel.SearchForward: "Ctrl-G"' \Do these configuration belong to individual scripts like this?
The problem is that if you don't do this, using xxdiff is user-hostile in the extreme. The problem isn't so much that the save command has no accelerators, but the Save menu gives you five (5!) save options. You can save the merged file as:
* The right file
* The middle file
* The left file
* The file that was specified as the output on the command-line
* Some user-specified file (save-as)
So without those resource changes, the user would have to click on the File menu, and drag down to the "correct" save option or the file with the resolved merge conflicts would get saved to some random place.
Gaaah. I thought xxdiff was user hostile in the extreme, but Martin Langhoff really wanted it, and he was right that xxdiff will give you a built-in character-diff so you can see what changed on the individual line. So the resource changes were in my opinion the minimum necessary so that the user would have some chance of seeing which one of the five save options would actually do the right thing with respect to git-mergetool.
Quoted 4 lines
git-mergetool.sh line 167
Quoted 1 line
git-mergetool.sh new file +1
-0+ echo "No available merge tools available."Curious choice of words...
Yeah, that should probably read "merge conflict resolution programs", even though that's a lot more words.
Quoted 7 lines
git-mergetool.sh line 192
Quoted 2 lines
git-mergetool.sh new file +2
-0+if test $# -eq 0 ; then + files=`git ls-files -u --abbrev=8 | colrm 1 24 | sort -u`Careful. I think --abbrev=8 just means use at least 8 but more
as needed to make them unique. sed -e 's/^[^ ]* //'
(whitespace are HTs) would be safer and simpler, as you are not dealing with a pathname that has LF in it anyway.
OK, I can do that. Alternatively I guess I could submit a patch which caused git-ls-files to only list the files that still needed merging. (i.e., git-ls-files -u --nostage".) Do you have any preferences?
- Ted
Quoted 10 lines · Theodore Tso
Quoted 4 lines
git-mergetool.sh line 8
Quoted 2 lines
git-mergetool.sh new file +2
-0+# This file is licensed under the GPL v2, or a later version +# at the discretion of Linus Torvalds.Heh ;-).
Hey, that's what the COPYING file requested, and it was late when I started doing the git package integration, hence the stupid think-o with the man page. :-)
I assume you would prefer that it read Junio instead?
Oh, no, sorry. The text itself is just fine as is, if that is the way you want.
I just laughed out because I remembered the list discussion (which might also have cc'ed the kernel list, but I do not remember) about possible relicensing schenario, where Linus mentioned that exact clause in the COPYING file, saying that his discretion would by now be to let me decide ;-).
Quoted 7 lines
Quoted 3 lines
You should be able to set IFS to exclude SP and then you only have to say you do not support LF and HT, both of which are much less likely than SP to be in the pathname.
Do we have any coding guidelines about what characters we have to support in filenames? I had assumed that we should support at least SP and HT, but life does get easier if we don't need to worry about HT.
The core scripts, at least the ones I personally use, are meant to handle all characters, including SP, HT and LF, so if there were any guidelines that would be it. However, your particular case to interface with external editor needs eval with sq magic if it needs to be coded in portable bourne, which can be done, but I suspect it is not worth doing, as we would not see HT in pathnames in the practice. UNIXy folks tend to avoid any whitespaces in the filenames, and Windows folks cannot use HT in pathnames as far as I understand.
Quoted 11 lines
Yeah, that should probably read "merge conflict resolution programs", even though that's a lot more words.
Quoted 7 lines
git-mergetool.sh line 192
Quoted 2 lines
git-mergetool.sh new file +2
-0+if test $# -eq 0 ; then + files=`git ls-files -u --abbrev=8 | colrm 1 24 | sort -u`Careful. I think --abbrev=8 just means use at least 8 but more
as needed to make them unique. sed -e 's/^[^ ]* //'
(whitespace are HTs) would be safer and simpler, as you are not dealing with a pathname that has LF in it anyway.
Quoted 3 lines
OK, I can do that. Alternatively I guess I could submit a patch which caused git-ls-files to only list the files that still needed merging. (i.e., git-ls-files -u --nostage".) Do you have any preferences?
The latter would be more useful in general, and something I should have done long time ago to help scripts. Thanks.
Quoted 6 lines · Theodore Tso
I assume you would prefer that it read Junio instead? Should we change the COPYING while we're at it, perhaps after consulting with Linus since he still owns so a fair amount of the copyright on git? It seems that if we're going to pre-collect permissions to move to GPLv3, it ought to be either you or him....
I'm ok with Junio controlling it as far as I'm concerned. After all, he's been the maintainer for the last two years, so he gets the blame, and he'd better get the credit too.
Linus
I had a chance to use git-mergetool in real life for the first time today, when I merged 'maint' into 'master'. It has a symlink vs symlink conflict, so I got something like this:
================================================================
Merging the files: RelNotes
Symlink merge conflict for RelNotes:
'RelNotes' is a symlink containing 'Documentation/RelNotes-1.5.1.txt' in the local branch 'RelNotes' is a symlink containing 'Documentation/RelNotes-1.5.0.6.txt' in the remote branch
Use (r)emote or (l)ocal, or (a)bort?
================================================================
A few observations.
(1) Saying "a" <Return> does not let me exit. It keeps asking the same question.
(2) The word "symlink" might be less geekish if worded "symbolic
link".
(3) The message look very long, and repeats the same information.
(4) The status info gives local and then remote, but the choice is between remote and local.
The attached is a minimum fix for the above issues, but not for immediate application, as I am sure the rewording would make messages inconsistent with other cases. The updated output would look like this:
================================================================
Merging the files: RelNotes
Symbolic link merge conflict for 'RelNotes':
local: a symbolic link -> 'Documentation/RelNotes-1.5.1.txt'
remote: a symbolic link -> 'Documentation/RelNotes-1.5.0.6.txt'
Use (l)ocal or (r)emote, or (a)bort? l
================================================================
--- git-mergetool.sh | 19 ++++++++----------- 1 files changed, 8 insertions(+), 11 deletions(-)
git-mergetool.sh +8 -11
@@ -44,27 +44,24 @@ function describe_file () { branch="$2" file="$3" - echo -n " " + echo -n " ${branch}: " if test -z "$mode"; then - echo -n "'$path' was deleted" + echo "deleted" elif is_symlink "$mode" ; then - echo -n "'$path' is a symlink containing '" - cat "$file" - echo -n "'" + echo "a symbolic link -> '$(cat "$file")'" else if base_present; then - echo -n "'$path' was created" + echo "created" else - echo -n "'$path' was modified" + echo "modified" fi fi - echo " in the $branch branch" } resolve_symlink_merge () { while /bin/true; do - echo -n "Use (r)emote or (l)ocal, or (a)bort? " + echo -n "Use (l)ocal or (r)emote, or (a)bort? " read ans case "$ans" in [lL]*)
@@ -79,7 +76,7 @@ resolve_symlink_merge () { cleanup_temp_files --save-backup return ;; - [qQ]*) + [aAqQ]*) exit 1 ;; esac
@@ -147,7 +144,7 @@ merge_file () { fi if is_symlink "$local_mode" || is_symlink "$remote_mode"; then - echo "Symlink merge conflict for $path:" + echo "Symbolic link conflict for '$path':" describe_file "$local_mode" "local" "$LOCAL" describe_file "$remote_mode" "remote" "$REMOTE" resolve_symlink_merge
Quoted 8 lines · Junio C Hamano
I had a chance to use git-mergetool in real life for the first time today, when I merged 'maint' into 'master'. It has a symlink vs symlink conflict, so I got something like this:
A few observations.
(1) Saying "a" <Return> does not let me exit. It keeps asking the same question.
Yeah, I fixed that last night, along with a bunch of other git mergetool cleanups. I was about to request you to do a pull when I noticed your e-mail.
Quoted 11 lines
(2) The word "symlink" might be less geekish if worded "symbolic
link".(3) The message look very long, and repeats the same information.
(4) The status info gives local and then remote, but the choice is between remote and local.
The attached is a minimum fix for the above issues, but not for immediate application, as I am sure the rewording would make messages inconsistent with other cases.
OK, let me fix up the display and try to clean up the other messages. I agree that your output looks much nicer.
- Ted