How to integrate visual conflict resolution (P4Merge) into SourceTree
Asked Answered
E

2

15

For quite some time now, I have been bedeviled by SourceTree's lack of usable conflict resolution.

There is supposed to be a procedure for integrating p4Merge or some other diff/merge tool into SourceTree. For the moment, p4Merge is my tool of choice; now I just need to figure out how to

  1. Get SourceTree to accept p4Merge as its merge/diff tool, and
  2. Be able to actually call p4Merge from SourceTree to resolve conflicts.

So far the only thing I've been successful at doing is getting P4Merge to display a diff from within SourceTree. So the Actions/External Diff menu item works, but the Actions/Resolve Conflicts/Launch External Merge Tool menu item does not (it is grayed out).

enter image description here

I have selected P4Merge for both the Diff tool and the Merge tool in the Tools/Options/Diff tab in SourceTree. I can't put anything in the two command line boxes (even if I knew what to put there), because they are also grayed out.

picture of Options/Diff dialog

How do I make this work?

SourceTree is at version 1.9.5.0, which should be the latest as of this writing. P4Merge doesn't appear to have a Help/About dialog, but it was installed recently (within the last 3 months).

Erstwhile answered 2/8, 2016 at 17:49 Comment(0)
E
5

I have SourceTree version 1.5.2.0, and I configured external merge tool as seen on the screenshot. P4Merge is installed into C:\Program Files\Perforce and is not on the Path. I did not set any specific values into .gitconfig regarding diff/merge tools (I realize that this is kind of 'works on my machine answer', but it was indeed that simple).

here is how I configured external merge tool

As for the workflow, different teams may have different approaches. What we do in our team for each feature work (usually done by only one developer) is the following (screenshots for how to perform each operation in SourceTree are at the end of the post):

  1. Rebase develop branch
  2. Create new feature branch
  3. Work on a feature, make commits (usually, multiple)
  4. If there were many changes to develop since the time branching was done, we can merge develop to our feature branch to resolve any potential conflicts and make sure feature still works
  5. Merge to develop branch followed by Push - our CI is configured to trigger deployment to Test environment when new changes are pushed to develop branch
  6. If all is good, we merge develop branch to master branch, which would trigger deployment to Production environment

To rebase develop: enter image description here

To create new branch out of develop: enter image description here

To merge develop into feature branch:

enter image description here

Here is how SourceTree shows that there are conflicts after merge: enter image description here

Update: In order to verify whether SourceTree is configured correctly, I suggest you do the following:

  1. Download and unzip locally a small repository with two branches from https://1drv.ms/u/s!Ahrx2cBEbNLOy1xsUNuZJrUe80Ox
  2. Add this repository to SourceTree by executing: File - Clone/New... - Add Working Copy - [select folder 'git-config']
  3. Right-click on branch with name 'origin/version-2' and select 'merge'
  4. You should see the warning about merge conflicts, and then after right-click on file.txt, the following should appear:

enter image description here

Erelia answered 9/8, 2016 at 19:27 Comment(11)
These settings didn't work. The "Launch External Merge Tool" menu option is still grayed out.Erstwhile
Saw your edit. Looks like I'm going to have to become a Git expert after all.Erstwhile
Sorry in advance for a stupid question: you do actually have conflicts in the current branch after merging, correct? If yes, can you show the screenshot of the context menu which appears when you click on file with conflicts in your "working copy changes" section on the screen?Erelia
It always looks like the screenshot I already provided in my question. I've yet to see the "resolve conflicts" context menu items enable.Erstwhile
by looking at your screenshot I get an impression that your merge succeeded without conflicts. I will add an image to my answer to show how the UI looks when there are merge conflicts (you will see that branch will get grey color as oppose to blue which is visible in your picture)Erelia
What do you click on to get the "resolve conflicts" menu to enable?Erstwhile
I right-click on a file with conflicts (the one with an icon with exclamation mark). If there are conflicts in several files, I would right-click on each individual fileErelia
It would seem that all of this works only if you don't commit first. Is that true? if so, how do you even know there are conflicts?Erstwhile
The repository state I showed on the screenshot with conflict was a result of trying to merge two branches (version-2 into master), but file.txt changed in master after version-2 branch was created. Commits were made successfully to each of the branches, it's only during merge that conflict was discovered and had to be dealt withErelia
@RobertHarvey I updated an answer with instructions how to check whether SourceTree is configured correctly using a small test repository which you can download from onedriveErelia
Thanks. Actually, I created a test repository yesterday and spent the better part of the afternoon figuring out how the workflow works. I'll post an answer with the entire workflow when I have some time.Erstwhile
P
4

I think you don`t have problem with P4Merge. You problem is

Actions/Resolve Conflicts/Launch External Merge Tool menu item does not (it is grayed out)

I think sourceTree has this behavior because you don`t have conflicts in the current branch.

You may check this easy: Run command git mergetool master . -d and see output. I suppose output will be No files need merging.

If you have unresolved conflicts in current branch sourceTree Actions/Resolve Conflicts enabled for me:enter image description here

Please edit a question if you real porblem with P4Merge and with other mergetool sourceTree works fine.

Pascoe answered 10/8, 2016 at 9:41 Comment(2)
One of my prevailing assumptions is that I don't have to drop to command line to do this. That, after all, is the whole point of using SourceTree.Erstwhile
Yes. Command git mergetool master . -d is just a test. Run it once and look on the output. If the output is No files need merging it mean SourceTree works correct. You don`t have conflicts for resolving.Pascoe

© 2022 - 2024 — McMap. All rights reserved.