Skip to content

Commit

Permalink
Add DiffMerge tool support
Browse files Browse the repository at this point in the history
Changes come from original PR #481 made by @akantsevoi. Fixes #59.
  • Loading branch information
lucasderraugh committed Jul 15, 2019
1 parent d3d7a12 commit 6aa8df8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions GitUp/Application/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ You must close and reopen any opened repositories in GitUp after changing this s
<menuItem title="Kaleidoscope" id="EDr-i6-aAh"/>
<menuItem title="Beyond Compare" id="cip-D6-GZD"/>
<menuItem title="P4Merge" id="RNS-uQ-WHF"/>
<menuItem title="DiffMerge" id="yH0-Kd-hsv"/>
<menuItem isSeparatorItem="YES" id="XvM-0Z-bmM"/>
<menuItem title="Git Tool" id="iEl-zc-obP"/>
</items>
Expand Down Expand Up @@ -392,6 +393,7 @@ You must close and reopen any opened repositories in GitUp after changing this s
<menuItem title="Kaleidoscope" id="pqO-7b-B5J"/>
<menuItem title="Beyond Compare" id="AaP-5A-YVD"/>
<menuItem title="P4Merge" id="Uq1-pA-HzR"/>
<menuItem title="DiffMerge" id="AXz-pD-fZY"/>
<menuItem isSeparatorItem="YES" id="opM-b3-5YC"/>
<menuItem title="Git Tool" id="yyO-2T-uYr"/>
</items>
Expand Down
1 change: 1 addition & 0 deletions GitUpKit/Utilities/GIViewController+Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern NSString* const GIViewControllerTool_Kaleidoscope;
extern NSString* const GIViewControllerTool_BeyondCompare;
extern NSString* const GIViewControllerTool_P4Merge;
extern NSString* const GIViewControllerTool_GitTool;
extern NSString* const GIViewControllerTool_DiffMerge;

extern NSString* const GIViewController_DiffTool;
extern NSString* const GIViewController_MergeTool;
Expand Down
23 changes: 23 additions & 0 deletions GitUpKit/Utilities/GIViewController+Utilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
#define kKSDiffPath @"/usr/local/bin/ksdiff"
#define kBComparePath @"/usr/local/bin/bcompare"
#define kP4MergePath @"/Applications/p4merge.app/Contents/Resources/launchp4merge"
#define kDiffMergePath @"/Applications/DiffMerge.app/Contents/Resources/diffmerge.sh"

NSString* const GIViewControllerTool_FileMerge = @"FileMerge";
NSString* const GIViewControllerTool_Kaleidoscope = @"Kaleidoscope";
NSString* const GIViewControllerTool_BeyondCompare = @"Beyond Compare";
NSString* const GIViewControllerTool_P4Merge = @"P4Merge";
NSString* const GIViewControllerTool_GitTool = @"Git Tool";
NSString* const GIViewControllerTool_DiffMerge = @"DiffMerge";

NSString* const GIViewController_DiffTool = @"GIViewController_DiffTool";
NSString* const GIViewController_MergeTool = @"GIViewController_MergeTool";
Expand Down Expand Up @@ -395,6 +397,14 @@ - (void)_runDiffGitToolForFile:(NSString*)file withOldPath:(NSString*)oldPath ne
}
}

- (void)_runDiffMergeToolWithArguments:(NSArray*)arguments {
if (([[NSFileManager defaultManager] isExecutableFileAtPath:kDiffMergePath])) {
[self _runTaskWithPath:kDiffMergePath arguments:arguments variables:nil waitUntilExit:NO reportErrors:NO]; // launch diff merge
} else {
[self presentAlertWithType:kGIAlertType_Stop title:NSLocalizedString(@"DiffMerge is not available!", nil) message:NSLocalizedString(@"P4Merge app doesn't appear to be installed.", nil)];
}
}

// http://git-scm.com/docs/git-mergetool
- (void)_runMergeGitToolForFile:(NSString*)file withOldPath:(NSString*)oldPath newPath:(NSString*)newPath basePath:(NSString*)basePath {
NSString* tool = [[self.repository readConfigOptionForVariable:@"merge.tool" error:NULL] value];
Expand Down Expand Up @@ -455,6 +465,8 @@ - (void)viewDeltasInDiffTool:(NSArray*)deltas {
[self _runP4MergeWithArguments:@[ @"-nl", oldTitle, @"-nr", newTitle, oldPath, newPath ]];
} else if ([identifier isEqualToString:GIViewControllerTool_GitTool]) {
[self _runDiffGitToolForFile:delta.canonicalPath withOldPath:oldPath newPath:newPath];
} else if ([identifier isEqualToString:GIViewControllerTool_DiffMerge]) {
[self _runDiffMergeToolWithArguments:@[ [NSString stringWithFormat:@"-t1=%@", oldTitle], [NSString stringWithFormat:@"-t2=%@", newTitle], oldPath, newPath ]];
} else {
XLOG_DEBUG_UNREACHABLE();
}
Expand Down Expand Up @@ -571,6 +583,15 @@ - (void)resolveConflictInMergeTool:(GCIndexConflict*)conflict {
[self _runP4MergeWithArguments:arguments];
} else if ([identifier isEqualToString:GIViewControllerTool_GitTool]) {
[self _runMergeGitToolForFile:mergePath withOldPath:ourPath newPath:theirPath basePath:ancestorPath];
} else if ([identifier isEqualToString:GIViewControllerTool_DiffMerge]) {
[arguments addObject:[NSString stringWithFormat:@"-r=%@", mergePath]];
[arguments addObject:[NSString stringWithFormat:@"-t1=%@", ourTitle]];
[arguments addObject:[NSString stringWithFormat:@"-t2=%@", ancestorTitle]];
[arguments addObject:[NSString stringWithFormat:@"-t3=%@", theirTitle]];
[arguments addObject:ourPath];
[arguments addObject:ancestorPath];
[arguments addObject:theirPath];
[self _runDiffMergeToolWithArguments:arguments];
} else {
XLOG_DEBUG_UNREACHABLE();
}
Expand Down Expand Up @@ -840,6 +861,8 @@ - (void)launchDiffToolWithCommit:(GCCommit*)commit otherCommit:(GCCommit*)otherC
[self _runBeyondCompareWithArguments:@[ [NSString stringWithFormat:@"-title1=%@", oldTitle], [NSString stringWithFormat:@"-title2=%@", newTitle], oldPath, newPath ]];
} else if ([identifier isEqualToString:GIViewControllerTool_P4Merge] || [identifier isEqualToString:GIViewControllerTool_GitTool]) {
; // Handled above
} else if ([identifier isEqualToString:GIViewControllerTool_DiffMerge]) {
[self _runDiffMergeToolWithArguments:@[ [NSString stringWithFormat:@"-t1=%@", oldTitle], [NSString stringWithFormat:@"-t2=%@", newTitle], oldPath, newPath ]];
} else {
XLOG_DEBUG_UNREACHABLE();
}
Expand Down

0 comments on commit 6aa8df8

Please sign in to comment.