New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for git-mergetool #4

Open
hkdobrev opened this Issue Jan 2, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@hkdobrev

hkdobrev commented Jan 2, 2018

Hi! Thanks for this great tool!

I've tried to configure it as a Git mergetool:

git config --global merge.tool fac

However, Git ignores it and it runs vimdiff for me. Previously, I had opendiff configured to start FileMerge and it works. I've also tried various different merge tools like sublimerge and I was expecting this to work tool.

git-mergetool command should start the tool with 3 arguments for each file with conflicts. I understand fac is supposed to be run for the whole set of merge conflicts and not just single files. However, for starters, it could start for the whole set and ignore the arguments passed to it. Later it could automatically move to the file which was passed to it.

Do you think there's a particular reason why git-mergetool would not start fac with the above configuration? I've already checked that fac is in my PATH.

Thanks!

@mkchoi212

This comment has been minimized.

Owner

mkchoi212 commented Jan 2, 2018

I have no idea. I will look into it though! Thanks for the heads up!

@mkchoi212 mkchoi212 added the todo label Jan 2, 2018

@auscompgeek

This comment has been minimized.

auscompgeek commented Jan 3, 2018

@hkdobrev Did you set mergetool.fac.cmd, as per git-config(1)?

@hkdobrev

This comment has been minimized.

hkdobrev commented Jan 3, 2018

@auscompgeek I haven't. Forgot about that! Thanks for the tip!

OK, so this works:

git config --global mergetool.fac.cmd fac
git config --global merge.tool fac

Now git-mergetool starts fac. However, it's started with all files and when you close it, Git opens it for the next file. So it's not suitable in this mode. I think it should detect it's used as a mergetool based on the command line arguments passed to it and open only the specified file so this workflow works.

@mkchoi212 mkchoi212 added feature and removed todo labels Jan 3, 2018

@mkchoi212

This comment has been minimized.

Owner

mkchoi212 commented Jan 3, 2018

Tried fmt.Println(len(os.Args), os.Args) but seems like nothing special is passed to the program by git. Any ideas on how we could detect if git-mergetool started fac?

Only one that comes to my mind is running ps || pgrep to find if git-mergetool is running.

@auscompgeek

This comment has been minimized.

auscompgeek commented Jan 4, 2018

A number of environment variables are set by git-mergetool(1). You could take a look at how the known mergetools to git are implemented by looking at the shell scripts in /usr/lib/git-core/mergetools/.

You can pass any argument you like in the cmd setting, so there's definitely no need for pgrep hacks.

@hkdobrev

This comment has been minimized.

hkdobrev commented Jan 4, 2018

From git help config:

mergetool.<tool>.cmd
Specify the command to invoke the specified merge tool. The specified command is evaluated in shell with the following variables available:
BASE is the name of a temporary file containing the common base of the files to be merged, if available;
LOCAL is the name of a temporary file containing the contents of the file on the current branch;
REMOTE is the name of a temporary file containing the contents of the file from the branch being merged;
MERGED contains the name of the file to which the merge tool should write the results of a successful merge.

So the configuration in .gitconfig should be something like:

[mergetool.fac]
    cmd = fac $BASE $LOCAL $REMOTE

An example from the opendiff mergetool opening FileMerge from XCode:

"$merge_tool_path" "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED" | cat

I guess you can either specify arguments or command line options for these and include a simple shell file in the repo to run it. This way it would be a 2-line configuration to use fac as your mergetool :)

@mkchoi212 mkchoi212 added this to the 2.0 milestone May 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment