mkchoi212 / fac

Easy-to-use CUI for fixing git conflicts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for git-mergetool

hkdobrev opened this issue · comments

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!

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

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

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

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.

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.

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 :)