From 90972ee4bb3a7ba8e4a0d033b0742bb56ccafca7 Mon Sep 17 00:00:00 2001 From: "AzureAD\\JimSimons" Date: Fri, 4 Jun 2021 14:53:36 +0100 Subject: [PATCH 1/5] Submodules working --- .../Private/GitSourceControlCommand.cpp | 31 +++++++++++++++++++ .../Private/GitSourceControlCommand.h | 5 +++ .../Private/GitSourceControlProvider.cpp | 2 ++ 3 files changed, 38 insertions(+) diff --git a/Source/GitSourceControl/Private/GitSourceControlCommand.cpp b/Source/GitSourceControl/Private/GitSourceControlCommand.cpp index 1bf25ec8..4bb6476c 100644 --- a/Source/GitSourceControl/Private/GitSourceControlCommand.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlCommand.cpp @@ -25,7 +25,38 @@ FGitSourceControlCommand::FGitSourceControlCommand(const TSharedRef& AbsoluteFilePaths) +{ + FString PluginsRoot = FPaths::ConvertRelativePathToFull(FPaths::ProjectPluginsDir()); + // note this is not going to support operations where selected files are both in the root repo and the submodule/plugin's repo + int NumPluginFiles = 0; + + for (auto& FilePath : AbsoluteFilePaths) + { + if (FilePath.Contains(PluginsRoot)) + { + NumPluginFiles++; + } + } + // if all plugins? + // modify Source control base path + if((NumPluginFiles == AbsoluteFilePaths.Num()) && (AbsoluteFilePaths.Num() > 0)) + { + FString FullPath = AbsoluteFilePaths[0]; + FString PluginPart = FullPath.Replace(*PluginsRoot, *FString("")); + PluginPart = PluginPart.Left(PluginPart.Find("/")); + + + FString CandidateRepoRoot = PluginsRoot + PluginPart; + + FString IsItUsingGitPath = CandidateRepoRoot + "/.git"; + if (FPaths::FileExists(IsItUsingGitPath)) + { + PathToRepositoryRoot = CandidateRepoRoot; + } + } +} bool FGitSourceControlCommand::DoWork() { bCommandSuccessful = Worker->Execute(*this); diff --git a/Source/GitSourceControl/Private/GitSourceControlCommand.h b/Source/GitSourceControl/Private/GitSourceControlCommand.h index 42c1a899..10f3ec2f 100644 --- a/Source/GitSourceControl/Private/GitSourceControlCommand.h +++ b/Source/GitSourceControl/Private/GitSourceControlCommand.h @@ -18,6 +18,11 @@ class FGitSourceControlCommand : public IQueuedWork FGitSourceControlCommand(const TSharedRef& InOperation, const TSharedRef& InWorker, const FSourceControlOperationComplete& InOperationCompleteDelegate = FSourceControlOperationComplete() ); + /** + * Modify the repo root if all selected files are in a plugin subfolder, and the plugin subfolder is a git repo + * This supports the case where each plugin is a sub module + */ + void UpdateRepositoryRootIfSubmodule(const TArray& AbsoluteFilePaths); /** * This is where the real thread work is done. All work that is done for * this queued object should be done from within the call to this function. diff --git a/Source/GitSourceControl/Private/GitSourceControlProvider.cpp b/Source/GitSourceControl/Private/GitSourceControlProvider.cpp index aa6c2564..042d930c 100644 --- a/Source/GitSourceControl/Private/GitSourceControlProvider.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlProvider.cpp @@ -254,6 +254,8 @@ ECommandResult::Type FGitSourceControlProvider::Execute( const TSharedRefFiles = AbsoluteFiles; + Command->UpdateRepositoryRootIfSubmodule(AbsoluteFiles); + Command->OperationCompleteDelegate = InOperationCompleteDelegate; // fire off operation From f546dbce5c99d77ac8fcb0ee95355281e3a2528c Mon Sep 17 00:00:00 2001 From: "AzureAD\\JimSimons" Date: Fri, 4 Jun 2021 16:12:49 +0100 Subject: [PATCH 2/5] Diff from plugin working --- .../Private/GitSourceControlCommand.cpp | 31 +-------------- .../Private/GitSourceControlRevision.cpp | 8 +++- .../Private/GitSourceControlRevision.h | 2 + .../Private/GitSourceControlUtils.cpp | 39 +++++++++++++++++++ .../Private/GitSourceControlUtils.h | 6 +++ 5 files changed, 55 insertions(+), 31 deletions(-) diff --git a/Source/GitSourceControl/Private/GitSourceControlCommand.cpp b/Source/GitSourceControl/Private/GitSourceControlCommand.cpp index 4bb6476c..170d64a6 100644 --- a/Source/GitSourceControl/Private/GitSourceControlCommand.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlCommand.cpp @@ -7,6 +7,7 @@ #include "Modules/ModuleManager.h" #include "GitSourceControlModule.h" +#include "GitSourceControlUtils.h" FGitSourceControlCommand::FGitSourceControlCommand(const TSharedRef& InOperation, const TSharedRef& InWorker, const FSourceControlOperationComplete& InOperationCompleteDelegate) : Operation(InOperation) @@ -27,35 +28,7 @@ FGitSourceControlCommand::FGitSourceControlCommand(const TSharedRef& AbsoluteFilePaths) { - FString PluginsRoot = FPaths::ConvertRelativePathToFull(FPaths::ProjectPluginsDir()); - // note this is not going to support operations where selected files are both in the root repo and the submodule/plugin's repo - int NumPluginFiles = 0; - - for (auto& FilePath : AbsoluteFilePaths) - { - if (FilePath.Contains(PluginsRoot)) - { - NumPluginFiles++; - } - } - // if all plugins? - // modify Source control base path - if((NumPluginFiles == AbsoluteFilePaths.Num()) && (AbsoluteFilePaths.Num() > 0)) - { - FString FullPath = AbsoluteFilePaths[0]; - - FString PluginPart = FullPath.Replace(*PluginsRoot, *FString("")); - PluginPart = PluginPart.Left(PluginPart.Find("/")); - - - FString CandidateRepoRoot = PluginsRoot + PluginPart; - - FString IsItUsingGitPath = CandidateRepoRoot + "/.git"; - if (FPaths::FileExists(IsItUsingGitPath)) - { - PathToRepositoryRoot = CandidateRepoRoot; - } - } + PathToRepositoryRoot = GitSourceControlUtils::ChangeRepositoryRootIfSubmodule(AbsoluteFilePaths, PathToRepositoryRoot); } bool FGitSourceControlCommand::DoWork() { diff --git a/Source/GitSourceControl/Private/GitSourceControlRevision.cpp b/Source/GitSourceControl/Private/GitSourceControlRevision.cpp index 0858f7f2..9c0e19cb 100644 --- a/Source/GitSourceControl/Private/GitSourceControlRevision.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlRevision.cpp @@ -17,8 +17,13 @@ bool FGitSourceControlRevision::Get( FString& InOutFilename ) const { FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked("GitSourceControl"); const FString PathToGitBinary = GitSourceControl.AccessSettings().GetBinaryPath(); - const FString PathToRepositoryRoot = GitSourceControl.GetProvider().GetPathToRepositoryRoot(); + FString PathToRepositoryRoot = GitSourceControl.GetProvider().GetPathToRepositoryRoot(); + // the repo root can be customised if in a plugin that has it's own repo + if (PathToRepoRoot.Len()) + { + PathToRepositoryRoot = PathToRepoRoot; + } // if a filename for the temp file wasn't supplied generate a unique-ish one if(InOutFilename.Len() == 0) { @@ -28,7 +33,6 @@ bool FGitSourceControlRevision::Get( FString& InOutFilename ) const const FString TempFileName = FString::Printf(TEXT("%stemp-%s-%s"), *FPaths::DiffDir(), *CommitId, *FPaths::GetCleanFilename(Filename)); InOutFilename = FPaths::ConvertRelativePathToFull(TempFileName); } - // Diff against the revision const FString Parameter = FString::Printf(TEXT("%s:%s"), *CommitId, *Filename); diff --git a/Source/GitSourceControl/Private/GitSourceControlRevision.h b/Source/GitSourceControl/Private/GitSourceControlRevision.h index d2cf7ab2..1f35a700 100644 --- a/Source/GitSourceControl/Private/GitSourceControlRevision.h +++ b/Source/GitSourceControl/Private/GitSourceControlRevision.h @@ -70,6 +70,8 @@ class FGitSourceControlRevision : public ISourceControlRevision, public TSharedF /** The size of the file at this revision */ int32 FileSize; + + FString PathToRepoRoot; }; /** History composed of the last 100 revisions of the file */ diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.cpp b/Source/GitSourceControl/Private/GitSourceControlUtils.cpp index 42014585..7f00285b 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.cpp @@ -55,7 +55,45 @@ const FString& FGitScopedTempFile::GetFilename() const namespace GitSourceControlUtils { +FString ChangeRepositoryRootIfSubmodule(const TArray& AbsoluteFilePaths, const FString& PathToRepositoryRoot) +{ + FString Ret = PathToRepositoryRoot; + FString PluginsRoot = FPaths::ConvertRelativePathToFull(FPaths::ProjectPluginsDir()); + // note this is not going to support operations where selected files are both in the root repo and the submodule/plugin's repo + int NumPluginFiles = 0; + + for (auto& FilePath : AbsoluteFilePaths) + { + if (FilePath.Contains(PluginsRoot)) + { + NumPluginFiles++; + } + } + // if all plugins? + // modify Source control base path + if ((NumPluginFiles == AbsoluteFilePaths.Num()) && (AbsoluteFilePaths.Num() > 0)) + { + FString FullPath = AbsoluteFilePaths[0]; + + FString PluginPart = FullPath.Replace(*PluginsRoot, *FString("")); + PluginPart = PluginPart.Left(PluginPart.Find("/")); + + FString CandidateRepoRoot = PluginsRoot + PluginPart; + + FString IsItUsingGitPath = CandidateRepoRoot + "/.git"; + if (FPaths::FileExists(IsItUsingGitPath)) + { + Ret = CandidateRepoRoot; + } + } + return Ret; +} +FString ChangeRepositoryRootIfSubmodule(const FString& AbsoluteFilePath, const FString& PathToRepositoryRoot) +{ + TArray AbsoluteFilePaths = { AbsoluteFilePath }; + return ChangeRepositoryRootIfSubmodule(AbsoluteFilePaths, PathToRepositoryRoot); +} // Launch the Git command line process and extract its results & errors static bool RunCommandInternalRaw(const FString& InCommand, const FString& InPathToGitBinary, const FString& InRepositoryRoot, const TArray& InParameters, const TArray& InFiles, FString& OutResults, FString& OutErrors, const int32 ExpectedReturnCode = 0) { @@ -1451,6 +1489,7 @@ bool RunGetHistory(const FString& InPathToGitBinary, const FString& InRepository Revision->FileHash = LsTree.FileHash; Revision->FileSize = LsTree.FileSize; } + Revision->PathToRepoRoot = InRepositoryRoot; } return bResults; diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.h b/Source/GitSourceControl/Private/GitSourceControlUtils.h index 971b433b..c214e64e 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.h +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.h @@ -35,6 +35,12 @@ struct FGitVersion; namespace GitSourceControlUtils { +/** +* Returns an updated the repo root if all selected files are in a plugin subfolder, and the plugin subfolder is a git repo +* This supports the case where each plugin is a sub module +*/ +FString ChangeRepositoryRootIfSubmodule(const TArray& AbsoluteFilePaths, const FString& PathToRepositoryRoot); +FString ChangeRepositoryRootIfSubmodule(const FString& AbsoluteFilePath, const FString& PathToRepositoryRoot); /** * Find the path to the Git binary, looking into a few places (standalone Git install, and other common tools embedding Git) From 57fb115c7b275be8d6836f878131f84e5bce1696 Mon Sep 17 00:00:00 2001 From: "AzureAD\\JimSimons" Date: Fri, 4 Jun 2021 16:17:26 +0100 Subject: [PATCH 3/5] Comments --- .../GitSourceControl/Private/GitSourceControlUtils.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.h b/Source/GitSourceControl/Private/GitSourceControlUtils.h index c214e64e..cd0f518e 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.h +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.h @@ -38,8 +38,19 @@ namespace GitSourceControlUtils /** * Returns an updated the repo root if all selected files are in a plugin subfolder, and the plugin subfolder is a git repo * This supports the case where each plugin is a sub module +* +* @param AbsoluteFilePaths The list of files in the SC operation +* @param PathToRepositoryRoot The original path to the repository root (used by default) */ FString ChangeRepositoryRootIfSubmodule(const TArray& AbsoluteFilePaths, const FString& PathToRepositoryRoot); + +/** +* Returns an updated the repo root if all selected file is in a plugin subfolder, and the plugin subfolder is a git repo +* This supports the case where each plugin is a sub module +* +* @param AbsoluteFilePath The files in the SC operation +* @param PathToRepositoryRoot The original path to the repository root (used by default) +*/ FString ChangeRepositoryRootIfSubmodule(const FString& AbsoluteFilePath, const FString& PathToRepositoryRoot); /** From 8ab85d49310d37de6f26515fe15305e94673e27e Mon Sep 17 00:00:00 2001 From: "AzureAD\\JimSimons" Date: Fri, 4 Jun 2021 16:25:25 +0100 Subject: [PATCH 4/5] Typos in comments --- Source/GitSourceControl/Private/GitSourceControlUtils.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.h b/Source/GitSourceControl/Private/GitSourceControlUtils.h index cd0f518e..0cf9c708 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.h +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.h @@ -36,7 +36,7 @@ struct FGitVersion; namespace GitSourceControlUtils { /** -* Returns an updated the repo root if all selected files are in a plugin subfolder, and the plugin subfolder is a git repo +* Returns an updated repo root if all selected files are in a plugin subfolder, and the plugin subfolder is a git repo * This supports the case where each plugin is a sub module * * @param AbsoluteFilePaths The list of files in the SC operation @@ -45,10 +45,10 @@ namespace GitSourceControlUtils FString ChangeRepositoryRootIfSubmodule(const TArray& AbsoluteFilePaths, const FString& PathToRepositoryRoot); /** -* Returns an updated the repo root if all selected file is in a plugin subfolder, and the plugin subfolder is a git repo +* Returns an updated repo root if all selected file is in a plugin subfolder, and the plugin subfolder is a git repo * This supports the case where each plugin is a sub module * -* @param AbsoluteFilePath The files in the SC operation +* @param AbsoluteFilePath The file in the SC operation * @param PathToRepositoryRoot The original path to the repository root (used by default) */ FString ChangeRepositoryRootIfSubmodule(const FString& AbsoluteFilePath, const FString& PathToRepositoryRoot); From 0c6646e68782b061103fc0d9396d93314793433f Mon Sep 17 00:00:00 2001 From: "AzureAD\\JimSimons" Date: Wed, 30 Jun 2021 17:10:35 +0100 Subject: [PATCH 5/5] Added .git folder to the 'is it git' test --- Source/GitSourceControl/Private/GitSourceControlUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/GitSourceControl/Private/GitSourceControlUtils.cpp b/Source/GitSourceControl/Private/GitSourceControlUtils.cpp index 7f00285b..5726d4a0 100644 --- a/Source/GitSourceControl/Private/GitSourceControlUtils.cpp +++ b/Source/GitSourceControl/Private/GitSourceControlUtils.cpp @@ -82,7 +82,7 @@ FString ChangeRepositoryRootIfSubmodule(const TArray& AbsoluteFilePaths FString CandidateRepoRoot = PluginsRoot + PluginPart; FString IsItUsingGitPath = CandidateRepoRoot + "/.git"; - if (FPaths::FileExists(IsItUsingGitPath)) + if (FPaths::FileExists(IsItUsingGitPath) || FPaths::DirectoryExists(IsItUsingGitPath)) { Ret = CandidateRepoRoot; }