From ae2cdc78dd4116f0b7bb0443f77f1af0a3a4442a Mon Sep 17 00:00:00 2001 From: Michael Delva Date: Thu, 4 Aug 2022 14:53:56 +0200 Subject: [PATCH 1/6] Added function in GitSourceControlUtils to get the last revision from origin/develop --- .../Private/GitSourceControlUtils.cpp | 45 ++++++++++++++++++- .../Private/GitSourceControlUtils.h | 3 ++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.cpp b/Source/GitSourceControl/Private/GitSourceControlUtils.cpp index 49e7c2c..50d6be5 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.cpp @@ -515,7 +515,13 @@ void GetUserConfig(const FString& InPathToGitBinary, const FString& InRepository bool GetBranchName(const FString& InPathToGitBinary, const FString& InRepositoryRoot, FString& OutBranchName) { - const FGitSourceControlProvider& Provider = FGitSourceControlModule::Get().GetProvider(); + auto * git_module = FModuleManager::Get().LoadModulePtr< FGitSourceControlModule >( "GitSourceControl" ); + if ( git_module == nullptr ) + { + return false; + } + + const FGitSourceControlProvider & Provider = git_module->GetProvider(); if (!Provider.GetBranchName().IsEmpty()) { OutBranchName = Provider.GetBranchName(); @@ -2157,6 +2163,43 @@ bool PullOrigin(const FString& InPathToGitBinary, const FString& InPathToReposit return bSuccess; } +TSharedPtr GetOriginDevelopRevision( const FString & InPathToGitBinary, const FString & InRepositoryRoot, const FString & InRelativeFileName, TArray & OutErrorMessages ) +{ + TGitSourceControlHistory OutHistory; + + TArray< FString > Results; + TArray< FString > Parameters; + Parameters.Add( TEXT( "origin/develop" ) ); + Parameters.Add( TEXT( "--date=raw" ) ); + Parameters.Add( TEXT( "--pretty=medium" ) ); // make sure format matches expected in ParseLogResults + + TArray< FString > Files; + const auto bResults = RunCommand( TEXT( "show" ), InPathToGitBinary, InRepositoryRoot, Parameters, Files, Results, OutErrorMessages ); + + if ( bResults ) + { + ParseLogResults( Results, OutHistory ); + } + + if ( OutHistory.Num() > 0 ) + { + auto AbsoluteFileName = FPaths::ConvertRelativePathToFull( InRelativeFileName ); + + AbsoluteFileName.RemoveFromStart( InRepositoryRoot ); + + if ( AbsoluteFileName[ 0 ] == '/' ) + { + AbsoluteFileName.RemoveAt( 0 ); + } + + + OutHistory[ 0 ]->Filename = AbsoluteFileName; + + return OutHistory[ 0 ]; + } + + return nullptr; +} } // namespace GitSourceControlUtils #undef LOCTEXT_NAMESPACE diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.h b/Source/GitSourceControl/Private/GitSourceControlUtils.h index 5657033..9c54106 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.h +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.h @@ -293,4 +293,7 @@ bool FetchRemote(const FString& InPathToGitBinary, const FString& InPathToReposi bool PullOrigin(const FString& InPathToGitBinary, const FString& InPathToRepositoryRoot, const TArray& InFiles, TArray& OutFiles, TArray& OutResults, TArray& OutErrorMessages); + +TSharedPtr< class ISourceControlRevision, ESPMode::ThreadSafe > GetOriginDevelopRevision( const FString & InPathToGitBinary, const FString & InRepositoryRoot, const FString & InRelativeFileName, TArray< FString > & OutErrorMessages ); + } From 9ab8fa95aa499851f27467f98c0f2208994a1107 Mon Sep 17 00:00:00 2001 From: Michael Delva Date: Thu, 4 Aug 2022 14:54:33 +0200 Subject: [PATCH 2/6] Added a new menu extension in the content browser to diff assets with their counterparts on origin/develop --- .../Private/GitSourceControlModule.cpp | 118 +++++++++++++++++- .../Private/GitSourceControlModule.h | 8 ++ 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/Source/GitSourceControl/Private/GitSourceControlModule.cpp b/Source/GitSourceControl/Private/GitSourceControlModule.cpp index 8a87a85..81ef799 100644 --- a/Source/GitSourceControl/Private/GitSourceControlModule.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlModule.cpp @@ -5,11 +5,20 @@ #include "GitSourceControlModule.h" +#include "AssetToolsModule.h" +#include "EditorStyleSet.h" #include "Misc/App.h" #include "Modules/ModuleManager.h" #include "Features/IModularFeatures.h" +#include "ContentBrowserModule.h" +#include "ContentBrowserDelegates.h" + #include "GitSourceControlOperations.h" +#include "GitSourceControlUtils.h" +#include "SourceControlHelpers.h" +#include "Framework/Commands/UIAction.h" +#include "Framework/MultiBox/MultiBoxBuilder.h" #if ENGINE_MAJOR_VERSION >= 5 #include "ContentBrowser/Public/ContentBrowserModule.h" @@ -59,6 +68,10 @@ void FGitSourceControlModule::StartupModule() CbdHandle_OnSearchBoxChanged = ContentBrowserModule.GetOnSearchBoxChanged().AddLambda( [this]( const FText&, bool ){ GitSourceControlProvider.TicksUntilNextForcedUpdate = 1; } ); CbdHandle_OnAssetSelectionChanged = ContentBrowserModule.GetOnAssetSelectionChanged().AddLambda( [this]( const TArray&, bool ) { GitSourceControlProvider.TicksUntilNextForcedUpdate = 1; } ); CbdHandle_OnAssetPathChanged = ContentBrowserModule.GetOnAssetPathChanged().AddLambda( [this]( const FString& ) { GitSourceControlProvider.TicksUntilNextForcedUpdate = 2; } ); + + auto & extenders = ContentBrowserModule.GetAllAssetViewContextMenuExtenders(); + extenders.Add( FContentBrowserMenuExtender_SelectedAssets::CreateRaw( this, &FGitSourceControlModule::OnExtendContentBrowserAssetSelectionMenu ) ); + ContentBrowserAssetExtenderDelegateHandle = extenders.Last().GetHandle(); #endif } @@ -72,11 +85,16 @@ void FGitSourceControlModule::ShutdownModule() #if ENGINE_MAJOR_VERSION >= 5 // Unregister ContentBrowserDelegate Handles - FContentBrowserModule& ContentBrowserModule = FModuleManager::Get().LoadModuleChecked("ContentBrowser"); + FContentBrowserModule & ContentBrowserModule = FModuleManager::Get().LoadModuleChecked< FContentBrowserModule >( "ContentBrowser" ); ContentBrowserModule.GetOnFilterChanged().Remove( CbdHandle_OnFilterChanged ); ContentBrowserModule.GetOnSearchBoxChanged().Remove( CbdHandle_OnSearchBoxChanged ); ContentBrowserModule.GetOnAssetSelectionChanged().Remove( CbdHandle_OnAssetSelectionChanged ); ContentBrowserModule.GetOnAssetPathChanged().Remove( CbdHandle_OnAssetPathChanged ); + + auto & extenders = ContentBrowserModule.GetAllAssetViewContextMenuExtenders(); + extenders.RemoveAll( [ &extender_delegate = ContentBrowserAssetExtenderDelegateHandle ]( const FContentBrowserMenuExtender_SelectedAssets & delegate ) { + return delegate.GetHandle() == extender_delegate; + } ); #endif } @@ -99,6 +117,102 @@ void FGitSourceControlModule::SetLastErrors(const TArray& InErrors) } } -IMPLEMENT_MODULE(FGitSourceControlModule, GitSourceControl); +TSharedRef FGitSourceControlModule::OnExtendContentBrowserAssetSelectionMenu( const TArray & selected_assets ) +{ + TSharedRef< FExtender > extender( new FExtender() ); + + extender->AddMenuExtension( + "AssetSourceControlActions", + EExtensionHook::After, + nullptr, + FMenuExtensionDelegate::CreateRaw( this, &FGitSourceControlModule::CreateGitContentBrowserAssetMenu, selected_assets ) ); + + return extender; +} + +void FGitSourceControlModule::CreateGitContentBrowserAssetMenu( FMenuBuilder & menu_builder, const TArray selected_assets ) +{ + menu_builder.AddMenuEntry( + LOCTEXT( "GitPlugin", "Diff against origin/develop" ), + LOCTEXT( "GitPlugin", "Diff that asset against the version on origin/develop." ), + FSlateIcon( FEditorStyle::GetStyleSetName(), "SourceControl.Actions.Diff" ), + FUIAction( FExecuteAction::CreateRaw( this, &FGitSourceControlModule::DiffAssetAgainstGitOriginDevelop, selected_assets ) ) ); +} + +void FGitSourceControlModule::DiffAssetAgainstGitOriginDevelop( const TArray selected_assets ) const +{ + for ( int32 AssetIdx = 0; AssetIdx < selected_assets.Num(); AssetIdx++ ) + { + // Get the actual asset (will load it) + const FAssetData & AssetData = selected_assets[ AssetIdx ]; + + if ( UObject * CurrentObject = AssetData.GetAsset() ) + { + const FString PackagePath = AssetData.PackageName.ToString(); + const FString PackageName = AssetData.AssetName.ToString(); + DiffAgainstOriginDevelop( CurrentObject, PackagePath, PackageName ); + } + } +} + +void FGitSourceControlModule::DiffAgainstOriginDevelop( UObject * InObject, const FString & InPackagePath, const FString & InPackageName ) const +{ + check( InObject ); + + const FGitSourceControlModule & GitSourceControl = FModuleManager::GetModuleChecked< FGitSourceControlModule >( "GitSourceControl" ); + const auto PathToGitBinary = GitSourceControl.AccessSettings().GetBinaryPath(); + const auto PathToRepositoryRoot = GitSourceControl.GetProvider().GetPathToRepositoryRoot(); + + ISourceControlProvider & SourceControlProvider = ISourceControlModule::Get().GetProvider(); + + const FAssetToolsModule & AssetToolsModule = FModuleManager::GetModuleChecked< FAssetToolsModule >( "AssetTools" ); + + // Get the SCC state + const FSourceControlStatePtr SourceControlState = SourceControlProvider.GetState( SourceControlHelpers::PackageFilename( InPackagePath ), EStateCacheUsage::Use ); + + // If we have an asset and its in SCC.. + if ( SourceControlState.IsValid() && InObject != nullptr && SourceControlState->IsSourceControlled() ) + { + // Get the file name of package + FString RelativeFileName; + if ( FPackageName::DoesPackageExist( InPackagePath, &RelativeFileName ) ) + { + //if(SourceControlState->GetHistorySize() > 0) + { + TArray< FString > Errors; + const auto Revision = GitSourceControlUtils::GetOriginDevelopRevision( PathToGitBinary, PathToRepositoryRoot, RelativeFileName, Errors ); + + check( Revision.IsValid() ); + + FString TempFileName; + if ( Revision->Get( TempFileName ) ) + { + // Try and load that package + UPackage * TempPackage = LoadPackage( nullptr, *TempFileName, LOAD_ForDiff | LOAD_DisableCompileOnLoad ); + if ( TempPackage != nullptr ) + { + // Grab the old asset from that old package + UObject * OldObject = FindObject< UObject >( TempPackage, *InPackageName ); + if ( OldObject != nullptr ) + { + /* Set the revision information*/ + FRevisionInfo OldRevision; + OldRevision.Changelist = Revision->GetCheckInIdentifier(); + OldRevision.Date = Revision->GetDate(); + OldRevision.Revision = Revision->GetRevision(); + + FRevisionInfo NewRevision; + NewRevision.Revision = TEXT( "" ); + + AssetToolsModule.Get().DiffAssets( OldObject, InObject, OldRevision, NewRevision ); + } + } + } + } + } + } +} + +IMPLEMENT_MODULE( FGitSourceControlModule, GitSourceControl ); #undef LOCTEXT_NAMESPACE diff --git a/Source/GitSourceControl/Private/GitSourceControlModule.h b/Source/GitSourceControl/Private/GitSourceControlModule.h index b05e909..a136c85 100644 --- a/Source/GitSourceControl/Private/GitSourceControlModule.h +++ b/Source/GitSourceControl/Private/GitSourceControlModule.h @@ -12,7 +12,9 @@ #include "GitSourceControlSettings.h" #include "GitSourceControlProvider.h" +#include "Framework/MultiBox/MultiBoxExtender.h" +struct FAssetData; /** UEGitPlugin is a simple Git Source Control Plugin for Unreal Engine @@ -122,6 +124,11 @@ class FGitSourceControlModule : public IModuleInterface static void SetLastErrors(const TArray& InErrors); private: + TSharedRef< FExtender > OnExtendContentBrowserAssetSelectionMenu( const TArray< FAssetData > & selected_assets ); + void CreateGitContentBrowserAssetMenu( FMenuBuilder & menu_builder, const TArray< FAssetData > selected_assets ); + void DiffAssetAgainstGitOriginDevelop( const TArray< FAssetData > selected_assets ) const; + void DiffAgainstOriginDevelop( UObject * InObject, const FString & InPackagePath, const FString & InPackageName ) const; + /** The one and only Git source control provider */ FGitSourceControlProvider GitSourceControlProvider; @@ -137,5 +144,6 @@ class FGitSourceControlModule : public IModuleInterface FDelegateHandle CbdHandle_OnAssetSelectionChanged; FDelegateHandle CbdHandle_OnSourcesViewChanged; FDelegateHandle CbdHandle_OnAssetPathChanged; + FDelegateHandle ContentBrowserAssetExtenderDelegateHandle; #endif }; From f82220ff3d31f90f3ba6f4cda203f8dff7aeb715 Mon Sep 17 00:00:00 2001 From: Michael Delva Date: Mon, 30 Jan 2023 14:42:36 +0100 Subject: [PATCH 3/6] Fixed warning --- Source/GitSourceControl/Private/GitSourceControlModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/GitSourceControl/Private/GitSourceControlModule.cpp b/Source/GitSourceControl/Private/GitSourceControlModule.cpp index 81ef799..d63da59 100644 --- a/Source/GitSourceControl/Private/GitSourceControlModule.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlModule.cpp @@ -135,7 +135,7 @@ void FGitSourceControlModule::CreateGitContentBrowserAssetMenu( FMenuBuilder & m menu_builder.AddMenuEntry( LOCTEXT( "GitPlugin", "Diff against origin/develop" ), LOCTEXT( "GitPlugin", "Diff that asset against the version on origin/develop." ), - FSlateIcon( FEditorStyle::GetStyleSetName(), "SourceControl.Actions.Diff" ), + FSlateIcon( FAppStyle::GetAppStyleSetName(), "SourceControl.Actions.Diff" ), FUIAction( FExecuteAction::CreateRaw( this, &FGitSourceControlModule::DiffAssetAgainstGitOriginDevelop, selected_assets ) ) ); } From 74ae46d010e4116f9ae4e92f0d73a58345388413 Mon Sep 17 00:00:00 2001 From: Michael Delva Date: Thu, 2 Feb 2023 11:31:07 +0100 Subject: [PATCH 4/6] Misisng include --- Source/GitSourceControl/Private/GitSourceControlModule.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/GitSourceControl/Private/GitSourceControlModule.cpp b/Source/GitSourceControl/Private/GitSourceControlModule.cpp index d63da59..02179b2 100644 --- a/Source/GitSourceControl/Private/GitSourceControlModule.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlModule.cpp @@ -16,6 +16,7 @@ #include "GitSourceControlOperations.h" #include "GitSourceControlUtils.h" +#include "ISourceControlModule.h" #include "SourceControlHelpers.h" #include "Framework/Commands/UIAction.h" #include "Framework/MultiBox/MultiBoxBuilder.h" From 74f2946dd9015ad5288c0fdb6f68aadbe9b9f47a Mon Sep 17 00:00:00 2001 From: Michael Delva Date: Mon, 27 Mar 2023 18:09:44 +0200 Subject: [PATCH 5/6] Generate as many menu items as there are status branches when diffing an asset --- .../Private/GitSourceControlModule.cpp | 34 +++++++++++-------- .../Private/GitSourceControlModule.h | 8 ++--- .../Private/GitSourceControlUtils.cpp | 4 +-- .../Private/GitSourceControlUtils.h | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Source/GitSourceControl/Private/GitSourceControlModule.cpp b/Source/GitSourceControl/Private/GitSourceControlModule.cpp index 02179b2..5f41bcd 100644 --- a/Source/GitSourceControl/Private/GitSourceControlModule.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlModule.cpp @@ -118,7 +118,7 @@ void FGitSourceControlModule::SetLastErrors(const TArray& InErrors) } } -TSharedRef FGitSourceControlModule::OnExtendContentBrowserAssetSelectionMenu( const TArray & selected_assets ) +TSharedRef FGitSourceControlModule::OnExtendContentBrowserAssetSelectionMenu( const TArray & SelectedAssets ) { TSharedRef< FExtender > extender( new FExtender() ); @@ -126,37 +126,41 @@ TSharedRef FGitSourceControlModule::OnExtendContentBrowserAssetSelect "AssetSourceControlActions", EExtensionHook::After, nullptr, - FMenuExtensionDelegate::CreateRaw( this, &FGitSourceControlModule::CreateGitContentBrowserAssetMenu, selected_assets ) ); + FMenuExtensionDelegate::CreateRaw( this, &FGitSourceControlModule::CreateGitContentBrowserAssetMenu, SelectedAssets ) ); return extender; } -void FGitSourceControlModule::CreateGitContentBrowserAssetMenu( FMenuBuilder & menu_builder, const TArray selected_assets ) +void FGitSourceControlModule::CreateGitContentBrowserAssetMenu( FMenuBuilder & MenuBuilder, const TArray< FAssetData > SelectedAssets ) { - menu_builder.AddMenuEntry( - LOCTEXT( "GitPlugin", "Diff against origin/develop" ), - LOCTEXT( "GitPlugin", "Diff that asset against the version on origin/develop." ), - FSlateIcon( FAppStyle::GetAppStyleSetName(), "SourceControl.Actions.Diff" ), - FUIAction( FExecuteAction::CreateRaw( this, &FGitSourceControlModule::DiffAssetAgainstGitOriginDevelop, selected_assets ) ) ); + for ( const auto & BranchName : FGitSourceControlModule::Get().GetProvider().GetStatusBranchNames() ) + { + MenuBuilder.AddMenuEntry( + // Directly call FInternationalization instead of using LOCTEXT as the macro requires literal strings and as such does not accept runtime constructed strings + FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText( *FString::Printf( TEXT( "Diff against %s" ), *BranchName ), TEXT( LOCTEXT_NAMESPACE ), TEXT( "GitPlugin" ) ), + FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText( *FString::Printf( TEXT( "Diff that asset against the version on %s" ), *BranchName ), TEXT( LOCTEXT_NAMESPACE ), TEXT( "GitPlugin" ) ), + FSlateIcon( FAppStyle::GetAppStyleSetName(), "SourceControl.Actions.Diff" ), + FUIAction( FExecuteAction::CreateRaw( this, &FGitSourceControlModule::DiffAssetAgainstGitOriginBranch, SelectedAssets, BranchName ) ) ); + } } -void FGitSourceControlModule::DiffAssetAgainstGitOriginDevelop( const TArray selected_assets ) const +void FGitSourceControlModule::DiffAssetAgainstGitOriginBranch( const TArray< FAssetData > SelectedAssets, FString BranchName ) const { - for ( int32 AssetIdx = 0; AssetIdx < selected_assets.Num(); AssetIdx++ ) + for ( int32 AssetIdx = 0; AssetIdx < SelectedAssets.Num(); AssetIdx++ ) { // Get the actual asset (will load it) - const FAssetData & AssetData = selected_assets[ AssetIdx ]; + const FAssetData & AssetData = SelectedAssets[ AssetIdx ]; if ( UObject * CurrentObject = AssetData.GetAsset() ) { const FString PackagePath = AssetData.PackageName.ToString(); const FString PackageName = AssetData.AssetName.ToString(); - DiffAgainstOriginDevelop( CurrentObject, PackagePath, PackageName ); + DiffAgainstOriginBranch( CurrentObject, PackagePath, PackageName, BranchName ); } } } -void FGitSourceControlModule::DiffAgainstOriginDevelop( UObject * InObject, const FString & InPackagePath, const FString & InPackageName ) const +void FGitSourceControlModule::DiffAgainstOriginBranch( UObject * InObject, const FString & InPackagePath, const FString & InPackageName, const FString & BranchName ) const { check( InObject ); @@ -178,10 +182,10 @@ void FGitSourceControlModule::DiffAgainstOriginDevelop( UObject * InObject, cons FString RelativeFileName; if ( FPackageName::DoesPackageExist( InPackagePath, &RelativeFileName ) ) { - //if(SourceControlState->GetHistorySize() > 0) + // if(SourceControlState->GetHistorySize() > 0) { TArray< FString > Errors; - const auto Revision = GitSourceControlUtils::GetOriginDevelopRevision( PathToGitBinary, PathToRepositoryRoot, RelativeFileName, Errors ); + const auto Revision = GitSourceControlUtils::GetOriginRevisionOnBranch( PathToGitBinary, PathToRepositoryRoot, RelativeFileName, Errors, BranchName ); check( Revision.IsValid() ); diff --git a/Source/GitSourceControl/Private/GitSourceControlModule.h b/Source/GitSourceControl/Private/GitSourceControlModule.h index a136c85..dded7c4 100644 --- a/Source/GitSourceControl/Private/GitSourceControlModule.h +++ b/Source/GitSourceControl/Private/GitSourceControlModule.h @@ -124,10 +124,10 @@ class FGitSourceControlModule : public IModuleInterface static void SetLastErrors(const TArray& InErrors); private: - TSharedRef< FExtender > OnExtendContentBrowserAssetSelectionMenu( const TArray< FAssetData > & selected_assets ); - void CreateGitContentBrowserAssetMenu( FMenuBuilder & menu_builder, const TArray< FAssetData > selected_assets ); - void DiffAssetAgainstGitOriginDevelop( const TArray< FAssetData > selected_assets ) const; - void DiffAgainstOriginDevelop( UObject * InObject, const FString & InPackagePath, const FString & InPackageName ) const; + TSharedRef< FExtender > OnExtendContentBrowserAssetSelectionMenu( const TArray< FAssetData > & SelectedAssets ); + void CreateGitContentBrowserAssetMenu( FMenuBuilder & MenuBuilder, const TArray< FAssetData > SelectedAssets ); + void DiffAssetAgainstGitOriginBranch( const TArray< FAssetData > SelectedAssets, FString BranchName ) const; + void DiffAgainstOriginBranch( UObject * InObject, const FString & InPackagePath, const FString & InPackageName, const FString & BranchName ) const; /** The one and only Git source control provider */ FGitSourceControlProvider GitSourceControlProvider; diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.cpp b/Source/GitSourceControl/Private/GitSourceControlUtils.cpp index 50d6be5..c4fccca 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.cpp @@ -2163,13 +2163,13 @@ bool PullOrigin(const FString& InPathToGitBinary, const FString& InPathToReposit return bSuccess; } -TSharedPtr GetOriginDevelopRevision( const FString & InPathToGitBinary, const FString & InRepositoryRoot, const FString & InRelativeFileName, TArray & OutErrorMessages ) +TSharedPtr GetOriginRevisionOnBranch( const FString & InPathToGitBinary, const FString & InRepositoryRoot, const FString & InRelativeFileName, TArray & OutErrorMessages, const FString & BranchName ) { TGitSourceControlHistory OutHistory; TArray< FString > Results; TArray< FString > Parameters; - Parameters.Add( TEXT( "origin/develop" ) ); + Parameters.Add( BranchName ); Parameters.Add( TEXT( "--date=raw" ) ); Parameters.Add( TEXT( "--pretty=medium" ) ); // make sure format matches expected in ParseLogResults diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.h b/Source/GitSourceControl/Private/GitSourceControlUtils.h index 9c54106..9c1d819 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.h +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.h @@ -294,6 +294,6 @@ bool PullOrigin(const FString& InPathToGitBinary, const FString& InPathToReposit TArray& OutResults, TArray& OutErrorMessages); -TSharedPtr< class ISourceControlRevision, ESPMode::ThreadSafe > GetOriginDevelopRevision( const FString & InPathToGitBinary, const FString & InRepositoryRoot, const FString & InRelativeFileName, TArray< FString > & OutErrorMessages ); +TSharedPtr< class ISourceControlRevision, ESPMode::ThreadSafe > GetOriginRevisionOnBranch( const FString & InPathToGitBinary, const FString & InRepositoryRoot, const FString & InRelativeFileName, TArray< FString > & OutErrorMessages, const FString & BranchName ); } From befef5e85374507958bdc6d5ef7ee048abe3a622 Mon Sep 17 00:00:00 2001 From: mcoms Date: Wed, 12 Apr 2023 12:47:52 -0400 Subject: [PATCH 6/6] only use the first status branch the first status branch is always up to date with all other branches due to automatic merging, and any content out of date on other branches will be unable to modify anyway, so they should check the latest version available across all branches (which is going to be on the first status branch) --- .../Private/GitSourceControlModule.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Source/GitSourceControl/Private/GitSourceControlModule.cpp b/Source/GitSourceControl/Private/GitSourceControlModule.cpp index 5f41bcd..1c8da27 100644 --- a/Source/GitSourceControl/Private/GitSourceControlModule.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlModule.cpp @@ -133,14 +133,19 @@ TSharedRef FGitSourceControlModule::OnExtendContentBrowserAssetSelect void FGitSourceControlModule::CreateGitContentBrowserAssetMenu( FMenuBuilder & MenuBuilder, const TArray< FAssetData > SelectedAssets ) { - for ( const auto & BranchName : FGitSourceControlModule::Get().GetProvider().GetStatusBranchNames() ) + if (!FGitSourceControlModule::Get().GetProvider().GetStatusBranchNames().Num()) + { + return; + } + + const FString& BranchName = FGitSourceControlModule::Get().GetProvider().GetStatusBranchNames()[0]; { - MenuBuilder.AddMenuEntry( - // Directly call FInternationalization instead of using LOCTEXT as the macro requires literal strings and as such does not accept runtime constructed strings - FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText( *FString::Printf( TEXT( "Diff against %s" ), *BranchName ), TEXT( LOCTEXT_NAMESPACE ), TEXT( "GitPlugin" ) ), - FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText( *FString::Printf( TEXT( "Diff that asset against the version on %s" ), *BranchName ), TEXT( LOCTEXT_NAMESPACE ), TEXT( "GitPlugin" ) ), - FSlateIcon( FAppStyle::GetAppStyleSetName(), "SourceControl.Actions.Diff" ), - FUIAction( FExecuteAction::CreateRaw( this, &FGitSourceControlModule::DiffAssetAgainstGitOriginBranch, SelectedAssets, BranchName ) ) ); + MenuBuilder.AddMenuEntry( + // Directly call FInternationalization instead of using LOCTEXT as the macro requires literal strings and as such does not accept runtime constructed strings + FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText( *FString::Printf( TEXT( "Diff against %s" ), *BranchName ), TEXT( LOCTEXT_NAMESPACE ), TEXT( "GitPlugin" ) ), + FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText( *FString::Printf( TEXT( "Diff that asset against the version on %s" ), *BranchName ), TEXT( LOCTEXT_NAMESPACE ), TEXT( "GitPlugin" ) ), + FSlateIcon( FAppStyle::GetAppStyleSetName(), "SourceControl.Actions.Diff" ), + FUIAction( FExecuteAction::CreateRaw( this, &FGitSourceControlModule::DiffAssetAgainstGitOriginBranch, SelectedAssets, BranchName ) ) ); } }