Hi [mention removed],
Great to hear the previous workaround helped. Git integration is not fully supported since we only modified the RunGetHistory method.
I’ve explored a cleaner and more flexible solution by dynamically overriding the repository root via an exposed method in the GitSourceControlProvider. This way all Git operations work based on the root you set.
This does require more structural changes to the Git Source Control Module:
1. Revert the previous changes made to GitSourceControlUtils.cpp (in RunGetHistory).
2. In the GitSourceControl/Source/GitSourceControl folder (next to the GitSourceControl.Build.cs file) create a Public folder and move all the header files from Private to Public.
3. Inside the GitSourceControl.Build.cs file add a new public include path like this:
`public class GitSourceControl : ModuleRules
{
public GitSourceControl(ReadOnlyTargetRules Target) : base(Target)
{
PrivateDependencyModuleNames.AddRange(
new string {
“Core”,
“Slate”,
“SlateCore”,
“InputCore”,
“DesktopWidgets”,
“SourceControl”,
}
);
// Make the header files public
PublicIncludePaths.AddRange(
new string {
“GitSourceControl/Public”
});
…
}
}`4. Open GitSourceControlProvider.h and update:
- Add GITSOURCECONTROL_API next to FGitSourceControlProvider
`// Before
class FGitSourceControlProvider
//After
class GITSOURCECONTROL_API FGitSourceControlProvider`* Declare the new public method called OverrideRepositoryRoot
`// In GitSourceControlProvider.h
void OverrideRepositoryRoot(const FString& NewRoot);`5. Open GitSourceControlProvider.cpp and update:
- Add the definition for the OverrideRepository method
`// GitSourceControlProvider.cpp
// Definition for OverrideRepository
void FGitSourceControlProvider::OverrideRepositoryRoot(const FString& NewRoot)
{
PathToRepositoryRoot = NewRoot;
bOverriddenPath = true;
UE_LOG(LogSourceControl, Warning, TEXT(“PathToRepositoryRoot overridden to: %s”), NewRoot);
CheckGitAvailability();
}` Modify the CheckRepositoryStatus method:
`void FGitSourceControlProvider::CheckRepositoryStatus(const FString& InPathToGitBinary)
{
// If the path has not been overridden, find the path to the root Git directory (if any)
if (!bOverriddenPath) {
const FString PathToProjectDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
bGitRepositoryFound = GitSourceControlUtils::FindRootDirectory(PathToProjectDir, PathToRepositoryRoot);
}
else {
bGitRepositoryFound = true;
}
if(bGitRepositoryFound)
{
// Get branch name
bGitRepositoryFound = GitSourceControlUtils::GetBranchName(InPathToGitBinary, PathToRepositoryRoot, BranchName);
if(bGitRepositoryFound)
{
GitSourceControlUtils::GetRemoteUrl(InPathToGitBinary, PathToRepositoryRoot, RemoteUrl);
UE_LOG(LogSourceControl, Warning, TEXT(“Repo root(%s) RemoteUrl(%s)”), *PathToRepositoryRoot, *RemoteUrl);
}
else
{
UE_LOG(LogSourceControl, Error, TEXT(“‘%s’ is not a valid Git repository”), *PathToRepositoryRoot);
}
}
else
{
UE_LOG(LogSourceControl, Warning, TEXT(“‘%s’ is not part of a Git repository”), *FPaths::ProjectDir());
}
// Get user name & email (of the repository, else from the global Git config)
GitSourceControlUtils::GetUserConfig(InPathToGitBinary, PathToRepositoryRoot, UserName, UserEmail);
}`
Now, we have everything ready in the Git module, you just need a way to call the OverrideRepositoryRoot.
I added a console command in my custom TestPlayerController like this:
`// TestPlayerController.h
UCLASS()
class MYGITPROJECT_API ATestPlayerController : public APlayerController
{
GENERATED_BODY()
// Exposed in the UE Editor console as: SetGitRepoRoot “Your/Path”
UFUNCTION(Exec)
void SetGitRepoRoot(FString NewRoot);
};
// TestPlayerController.cpp
include “TestPlayerController.h”
include “GitSourceControlModule.h”
include “GitSourceControlProvider.h”
void ATestPlayerController::SetGitRepoRoot(FString NewRoot)
{
UE_LOG(LogTemp, Warning, TEXT(“SetGitRepoRoot() called with: %s”), *NewRoot);
FGitSourceControlModule& Module = FModuleManager::LoadModuleChecked(“GitSourceControl”);
FGitSourceControlProvider& Provider = Module.GetProvider();
Provider.OverrideRepositoryRoot(NewRoot);
}`Make sure to include the Git Source and Source Control module in your project’s .Build.cs file:
`public class MyGitProject: ModuleRules
{
public MyGitProject(ReadOnlyTargetRules Target) : base(Target)
{
…
PublicDependencyModuleNames.AddRange(new string { “Core”, “CoreUObject”, “Engine”, “InputCore”, “SourceControl”, “GitSourceControl” });
…
}
}`Once compiled (engine and project), you can launch a PIE session and run the command via the console like this:
SetGitRepoRoot E:/UDN/Launcher_5.5.4/GitPluginIssue/Plugins/TestPlugin
Where TestPlugin is the directory of my plugin/submodule. Be aware that the path must be absolute and without any quotes.
[Image Removed]You should see Git-related logs and now history, diff and other operations should work in the plugin/submodule context.
Here’s an image of calling “Diff Against Depot” on a plugin BP:
[Image Removed]To go back to the original repo root you may call the command again using the project root or restart the editor.
While the way the function is triggered could certainly be improved, I believe this approach could sufficient for your revision needs.
Please let me know if this works for you.
Best,
Francisco