Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submodule support #161

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Source/GitSourceControl/Private/GitSourceControlCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "Modules/ModuleManager.h"
#include "GitSourceControlModule.h"
#include "GitSourceControlUtils.h"

FGitSourceControlCommand::FGitSourceControlCommand(const TSharedRef<class ISourceControlOperation, ESPMode::ThreadSafe>& InOperation, const TSharedRef<class IGitSourceControlWorker, ESPMode::ThreadSafe>& InWorker, const FSourceControlOperationComplete& InOperationCompleteDelegate)
: Operation(InOperation)
Expand All @@ -25,7 +26,10 @@ FGitSourceControlCommand::FGitSourceControlCommand(const TSharedRef<class ISourc
bUsingGitLfsLocking = GitSourceControl.AccessSettings().IsUsingGitLfsLocking();
PathToRepositoryRoot = GitSourceControl.GetProvider().GetPathToRepositoryRoot();
}

void FGitSourceControlCommand::UpdateRepositoryRootIfSubmodule(const TArray<FString>& AbsoluteFilePaths)
{
PathToRepositoryRoot = GitSourceControlUtils::ChangeRepositoryRootIfSubmodule(AbsoluteFilePaths, PathToRepositoryRoot);
}
bool FGitSourceControlCommand::DoWork()
{
bCommandSuccessful = Worker->Execute(*this);
Expand Down
5 changes: 5 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class FGitSourceControlCommand : public IQueuedWork

FGitSourceControlCommand(const TSharedRef<class ISourceControlOperation, ESPMode::ThreadSafe>& InOperation, const TSharedRef<class IGitSourceControlWorker, ESPMode::ThreadSafe>& 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<FString>& 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.
Expand Down
2 changes: 2 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ ECommandResult::Type FGitSourceControlProvider::Execute( const TSharedRef<ISourc

FGitSourceControlCommand* Command = new FGitSourceControlCommand(InOperation, Worker.ToSharedRef());
Command->Files = AbsoluteFiles;
Command->UpdateRepositoryRootIfSubmodule(AbsoluteFiles);

Command->OperationCompleteDelegate = InOperationCompleteDelegate;

// fire off operation
Expand Down
8 changes: 6 additions & 2 deletions Source/GitSourceControl/Private/GitSourceControlRevision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ bool FGitSourceControlRevision::Get( FString& InOutFilename ) const
{
FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("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)
{
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlRevision.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
39 changes: 39 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,45 @@ const FString& FGitScopedTempFile::GetFilename() const

namespace GitSourceControlUtils
{
FString ChangeRepositoryRootIfSubmodule(const TArray<FString>& 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) || FPaths::DirectoryExists(IsItUsingGitPath))
{
Ret = CandidateRepoRoot;
}
}
return Ret;
}
FString ChangeRepositoryRootIfSubmodule(const FString& AbsoluteFilePath, const FString& PathToRepositoryRoot)
{
TArray<FString> 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<FString>& InParameters, const TArray<FString>& InFiles, FString& OutResults, FString& OutErrors, const int32 ExpectedReturnCode = 0)
{
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ struct FGitVersion;

namespace GitSourceControlUtils
{
/**
* 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
* @param PathToRepositoryRoot The original path to the repository root (used by default)
*/
FString ChangeRepositoryRootIfSubmodule(const TArray<FString>& AbsoluteFilePaths, const FString& PathToRepositoryRoot);

/**
* 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 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);

/**
* Find the path to the Git binary, looking into a few places (standalone Git install, and other common tools embedding Git)
Expand Down