From 6aa8df8b98117ebe8eb3cbbe26f991e4a71cfda6 Mon Sep 17 00:00:00 2001 From: Lucas Derraugh Date: Sun, 14 Jul 2019 22:08:57 -0700 Subject: [PATCH] Add DiffMerge tool support Changes come from original PR #481 made by @akantsevoi. Fixes #59. --- GitUp/Application/Base.lproj/MainMenu.xib | 2 ++ .../Utilities/GIViewController+Utilities.h | 1 + .../Utilities/GIViewController+Utilities.m | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/GitUp/Application/Base.lproj/MainMenu.xib b/GitUp/Application/Base.lproj/MainMenu.xib index 3cfa6d5e..023b46b5 100644 --- a/GitUp/Application/Base.lproj/MainMenu.xib +++ b/GitUp/Application/Base.lproj/MainMenu.xib @@ -356,6 +356,7 @@ You must close and reopen any opened repositories in GitUp after changing this s + @@ -392,6 +393,7 @@ You must close and reopen any opened repositories in GitUp after changing this s + diff --git a/GitUpKit/Utilities/GIViewController+Utilities.h b/GitUpKit/Utilities/GIViewController+Utilities.h index a8cb9e0c..8c4c2a0f 100644 --- a/GitUpKit/Utilities/GIViewController+Utilities.h +++ b/GitUpKit/Utilities/GIViewController+Utilities.h @@ -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; diff --git a/GitUpKit/Utilities/GIViewController+Utilities.m b/GitUpKit/Utilities/GIViewController+Utilities.m index f7eecfec..04ba6556 100644 --- a/GitUpKit/Utilities/GIViewController+Utilities.m +++ b/GitUpKit/Utilities/GIViewController+Utilities.m @@ -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"; @@ -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]; @@ -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(); } @@ -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(); } @@ -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(); }