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 #75

Merged
merged 1 commit into from
Apr 12, 2023
Merged
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
8 changes: 7 additions & 1 deletion Source/GitSourceControl/Private/GitSourceControlCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
// Copyright (c) 2014-2023 Sebastien Rombauts (sebastien.rombauts@gmail.com)
//
// Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
// or copy at http://opensource.org/licenses/MIT)
Expand All @@ -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 @@ -27,6 +28,11 @@ FGitSourceControlCommand::FGitSourceControlCommand(const TSharedRef<class ISourc
PathToGitRoot = Provider.GetPathToGitRoot();
}

void FGitSourceControlCommand::UpdateRepositoryRootIfSubmodule(const TArray<FString>& AbsoluteFilePaths)
{
PathToRepositoryRoot = GitSourceControlUtils::ChangeRepositoryRootIfSubmodule(AbsoluteFilePaths, PathToRepositoryRoot);
}

bool FGitSourceControlCommand::DoWork()
{
bCommandSuccessful = Worker->Execute(*this);
Expand Down
8 changes: 7 additions & 1 deletion Source/GitSourceControl/Private/GitSourceControlCommand.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
// Copyright (c) 2014-2023 Sebastien Rombauts (sebastien.rombauts@gmail.com)
//
// Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
// or copy at http://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -36,6 +36,12 @@ 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
3 changes: 2 additions & 1 deletion Source/GitSourceControl/Private/GitSourceControlProvider.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
// Copyright (c) 2014-2023 Sebastien Rombauts (sebastien.rombauts@gmail.com)
//
// Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
// or copy at http://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -422,6 +422,7 @@ ECommandResult::Type FGitSourceControlProvider::Execute( const FSourceControlOpe

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

// fire off operation
Expand Down
9 changes: 7 additions & 2 deletions Source/GitSourceControl/Private/GitSourceControlRevision.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
// Copyright (c) 2014-2023 Sebastien Rombauts (sebastien.rombauts@gmail.com)
//
// Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
// or copy at http://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -28,7 +28,12 @@ bool FGitSourceControlRevision::Get( FString& InOutFilename ) const
const FGitSourceControlModule& GitSourceControl = FGitSourceControlModule::Get();
const FGitSourceControlProvider& Provider = GitSourceControl.GetProvider();
const FString PathToGitBinary = Provider.GetGitBinaryPath();
const FString PathToRepositoryRoot = Provider.GetPathToRepositoryRoot();
FString PathToRepositoryRoot = Provider.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 Down
5 changes: 4 additions & 1 deletion Source/GitSourceControl/Private/GitSourceControlRevision.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
// Copyright (c) 2014-2023 Sebastien Rombauts (sebastien.rombauts@gmail.com)
//
// Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
// or copy at http://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -71,6 +71,9 @@ class FGitSourceControlRevision : public ISourceControlRevision

/** The size of the file at this revision */
int32 FileSize;

/** Dynamic repository root **/
FString PathToRepoRoot;
};

/** History composed of the last 100 revisions of the file */
Expand Down
42 changes: 42 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,47 @@ TMap<FString, FString> FGitLockedFilesCache::LockedFiles = TMap<FString, FString

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
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 @@ -1830,6 +1871,7 @@ bool RunGetHistory(const FString& InPathToGitBinary, const FString& InRepository
Revision->FileHash = LsTree.FileHash;
Revision->FileSize = LsTree.FileSize;
}
Revision->PathToRepoRoot = InRepositoryRoot;
}

return bResults;
Expand Down
Loading